Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a006bb

Browse files
author
Doug Davis
committed
Fix race condition in kafka tests
also add a hack/until to run the services needed by the integration tests locally Signed-off-by: Doug Davis <[email protected]>
1 parent 566d1be commit 0a006bb

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

hack/run-integration-services.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# Run the services needed by the integration test in our local docker install
4+
5+
if [[ "$1" == "stop" ]]; then
6+
docker rm -f kafka nats amqp mqtt
7+
exit 0
8+
fi
9+
10+
# Kafka
11+
docker run --name kafka -dti -e ADV_HOST=localhost -p 9091:9091 -p 9092:9092 \
12+
lensesio/fast-data-dev
13+
14+
# NATS
15+
docker run --name nats -dti -p 4222:4222 nats-streaming:0.22.1
16+
17+
# AMQP
18+
docker run --name amqp -dti -e QDROUTERD_CONFIG_OPTIONS='
19+
router {
20+
mode: standalone
21+
id: ZTg2NDQ0N2Q1YjU1OGE1N2NkNzY4NDFk
22+
workerThreads: 4
23+
}
24+
log {
25+
module: DEFAULT
26+
enable: trace+
27+
timestamp: true
28+
}
29+
listener {
30+
role: normal
31+
host: 0.0.0.0
32+
port: amqp
33+
saslMechanisms: ANONYMOUS
34+
}' -p 5672:5672 scholzj/qpid-dispatch
35+
36+
# MQTT
37+
docker run --name mqtt -dti -p 1883:1883 eclipse-mosquitto:1.6
38+

test/integration/kafka_sarama_binding/kafka_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"strings"
1212
"testing"
13+
"time"
1314

1415
"github.com/IBM/sarama"
1516
"github.com/google/uuid"
@@ -101,6 +102,10 @@ func testSenderReceiver(t testing.TB) (func(), bindings.Sender, bindings.Receive
101102
require.NoError(t, p.OpenInbound(context.TODO()))
102103
}()
103104

105+
// Not perfect but we need to give OpenInbound() as chance to start
106+
// as it's a race condition. I couldn't find something on 'p' to wait for
107+
time.Sleep(5 * time.Second)
108+
104109
return func() {
105110
require.NoError(t, p.Close(context.TODO()))
106111
require.NoError(t, client.Close())

0 commit comments

Comments
 (0)