Skip to content

Commit c70ae71

Browse files
petedannemannLeonHartley
authored andcommitted
chore: fix flaky TestRebalanceTooManyConsumers (segmentio#1380)
1 parent b48cdca commit c70ae71

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

reader_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,9 @@ func TestCommitOffsetsWithRetry(t *testing.T) {
13741374
// than partitions in a group.
13751375
// https://github.com/segmentio/kafka-go/issues/200
13761376
func TestRebalanceTooManyConsumers(t *testing.T) {
1377-
ctx := context.Background()
1377+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
1378+
defer cancel()
1379+
13781380
conf := ReaderConfig{
13791381
Brokers: []string{"localhost:9092"},
13801382
GroupID: makeGroupID(),
@@ -1384,8 +1386,15 @@ func TestRebalanceTooManyConsumers(t *testing.T) {
13841386

13851387
// Create the first reader and wait for it to become the leader.
13861388
r1 := NewReader(conf)
1389+
1390+
// Give the reader some time to setup before reading a message
1391+
time.Sleep(1 * time.Second)
13871392
prepareReader(t, ctx, r1, makeTestSequence(1)...)
1388-
r1.ReadMessage(ctx)
1393+
1394+
_, err := r1.ReadMessage(ctx)
1395+
if err != nil {
1396+
t.Fatalf("failed to read message: %v", err)
1397+
}
13891398
// Clear the stats from the first rebalance.
13901399
r1.Stats()
13911400

0 commit comments

Comments
 (0)