Skip to content

Commit

Permalink
Fix race condition in kafka tests
Browse files Browse the repository at this point in the history
also add a hack/until to run the services needed by the integration tests locally

Signed-off-by: Doug Davis <dug@microsoft.com>
  • Loading branch information
duglin committed Oct 21, 2023
1 parent 566d1be commit 0a006bb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
38 changes: 38 additions & 0 deletions hack/run-integration-services.sh
@@ -0,0 +1,38 @@
#!/bin/bash

# Run the services needed by the integration test in our local docker install

if [[ "$1" == "stop" ]]; then
docker rm -f kafka nats amqp mqtt
exit 0
fi

# Kafka
docker run --name kafka -dti -e ADV_HOST=localhost -p 9091:9091 -p 9092:9092 \
lensesio/fast-data-dev

# NATS
docker run --name nats -dti -p 4222:4222 nats-streaming:0.22.1

# AMQP
docker run --name amqp -dti -e QDROUTERD_CONFIG_OPTIONS='
router {
mode: standalone
id: ZTg2NDQ0N2Q1YjU1OGE1N2NkNzY4NDFk
workerThreads: 4
}
log {
module: DEFAULT
enable: trace+
timestamp: true
}
listener {
role: normal
host: 0.0.0.0
port: amqp
saslMechanisms: ANONYMOUS
}' -p 5672:5672 scholzj/qpid-dispatch

# MQTT
docker run --name mqtt -dti -p 1883:1883 eclipse-mosquitto:1.6

5 changes: 5 additions & 0 deletions test/integration/kafka_sarama_binding/kafka_test.go
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"strings"
"testing"
"time"

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

// Not perfect but we need to give OpenInbound() as chance to start
// as it's a race condition. I couldn't find something on 'p' to wait for
time.Sleep(5 * time.Second)

return func() {
require.NoError(t, p.Close(context.TODO()))
require.NoError(t, client.Close())
Expand Down

0 comments on commit 0a006bb

Please sign in to comment.