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 <dug@microsoft.com>
This commit is contained in:
Doug Davis 2023-10-20 16:47:04 +00:00
parent 566d1be636
commit 0a006bba61
2 changed files with 43 additions and 0 deletions

View File

@ -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

View File

@ -10,6 +10,7 @@ import (
"os"
"strings"
"testing"
"time"
"github.com/IBM/sarama"
"github.com/google/uuid"
@ -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())