Skip to content

Commit cadad71

Browse files
committed
Fixes some flaky tests in the build as well as the case when tests start before kafka is ready.
1 parent a8e5eab commit cadad71

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ jobs:
5454
key: kafka-go-mod-{{ checksum "go.sum" }}-1
5555
paths:
5656
- /go/pkg/mod
57+
- run:
58+
name: Wait for kafka
59+
command: COUNTER=0; nc -Z localhost 9092; until [ $? -eq 0 ] || [ "$COUNTER" -ge 60 ]; do let COUNTER=$COUNTER+1; sleep 1; echo "waiting $COUNTER"; nc -Z localhost 9092; done
5760
- run:
5861
name: Test kafka-go
5962
command: go test -race -cover ./...

reader_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func createTopic(t *testing.T, topic string, partitions int) {
309309
ReplicationFactor: 1,
310310
},
311311
},
312-
Timeout: milliseconds(time.Second),
312+
Timeout: milliseconds(5 * time.Second),
313313
})
314314
if err != nil {
315315
if !errors.Is(err, TopicAlreadyExists) {
@@ -1559,17 +1559,22 @@ func TestConsumerGroupWithGroupTopicsSingle(t *testing.T) {
15591559
}
15601560
}
15611561

1562-
func TestConsumerGroupWithGroupTopicsMultple(t *testing.T) {
1562+
func TestConsumerGroupWithGroupTopicsMultiple(t *testing.T) {
15631563
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
15641564
defer cancel()
15651565

15661566
client, shutdown := newLocalClient()
15671567
defer shutdown()
1568-
1568+
t1 := makeTopic()
1569+
createTopic(t, t1, 1)
1570+
defer deleteTopic(t, t1)
1571+
t2 := makeTopic()
1572+
createTopic(t, t2, 1)
1573+
defer deleteTopic(t, t2)
15691574
conf := ReaderConfig{
15701575
Brokers: []string{"localhost:9092"},
15711576
GroupID: makeGroupID(),
1572-
GroupTopics: []string{makeTopic(), makeTopic()},
1577+
GroupTopics: []string{t1, t2},
15731578
MaxWait: time.Second,
15741579
PartitionWatchInterval: 100 * time.Millisecond,
15751580
WatchPartitionChanges: true,

0 commit comments

Comments
 (0)