forked from segmentio/kafka-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
consumergroup_test.go
679 lines (625 loc) · 19.9 KB
/
consumergroup_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
package skafka
import (
"context"
"errors"
"reflect"
"strings"
"sync"
"testing"
"time"
)
var _ coordinator = mockCoordinator{}
type mockCoordinator struct {
closeFunc func() error
findCoordinatorFunc func(findCoordinatorRequestV0) (findCoordinatorResponseV0, error)
joinGroupFunc func(joinGroupRequestV1) (joinGroupResponseV1, error)
syncGroupFunc func(syncGroupRequestV0) (syncGroupResponseV0, error)
leaveGroupFunc func(leaveGroupRequestV0) (leaveGroupResponseV0, error)
heartbeatFunc func(heartbeatRequestV0) (heartbeatResponseV0, error)
offsetFetchFunc func(offsetFetchRequestV1) (offsetFetchResponseV1, error)
offsetCommitFunc func(offsetCommitRequestV2) (offsetCommitResponseV2, error)
readPartitionsFunc func(...string) ([]Partition, error)
}
func (c mockCoordinator) Close() error {
if c.closeFunc != nil {
return c.closeFunc()
}
return nil
}
func (c mockCoordinator) findCoordinator(req findCoordinatorRequestV0) (findCoordinatorResponseV0, error) {
if c.findCoordinatorFunc == nil {
return findCoordinatorResponseV0{}, errors.New("no findCoordinator behavior specified")
}
return c.findCoordinatorFunc(req)
}
func (c mockCoordinator) joinGroup(req joinGroupRequestV1) (joinGroupResponseV1, error) {
if c.joinGroupFunc == nil {
return joinGroupResponseV1{}, errors.New("no joinGroup behavior specified")
}
return c.joinGroupFunc(req)
}
func (c mockCoordinator) syncGroup(req syncGroupRequestV0) (syncGroupResponseV0, error) {
if c.syncGroupFunc == nil {
return syncGroupResponseV0{}, errors.New("no syncGroup behavior specified")
}
return c.syncGroupFunc(req)
}
func (c mockCoordinator) leaveGroup(req leaveGroupRequestV0) (leaveGroupResponseV0, error) {
if c.leaveGroupFunc == nil {
return leaveGroupResponseV0{}, errors.New("no leaveGroup behavior specified")
}
return c.leaveGroupFunc(req)
}
func (c mockCoordinator) heartbeat(req heartbeatRequestV0) (heartbeatResponseV0, error) {
if c.heartbeatFunc == nil {
return heartbeatResponseV0{}, errors.New("no heartbeat behavior specified")
}
return c.heartbeatFunc(req)
}
func (c mockCoordinator) offsetFetch(req offsetFetchRequestV1) (offsetFetchResponseV1, error) {
if c.offsetFetchFunc == nil {
return offsetFetchResponseV1{}, errors.New("no offsetFetch behavior specified")
}
return c.offsetFetchFunc(req)
}
func (c mockCoordinator) offsetCommit(req offsetCommitRequestV2) (offsetCommitResponseV2, error) {
if c.offsetCommitFunc == nil {
return offsetCommitResponseV2{}, errors.New("no offsetCommit behavior specified")
}
return c.offsetCommitFunc(req)
}
func (c mockCoordinator) readPartitions(topics ...string) ([]Partition, error) {
if c.readPartitionsFunc == nil {
return nil, errors.New("no Readpartitions behavior specified")
}
return c.readPartitionsFunc(topics...)
}
func TestValidateConsumerGroupConfig(t *testing.T) {
tests := []struct {
config ConsumerGroupConfig
errorOccured bool
}{
{config: ConsumerGroupConfig{}, errorOccured: true},
{config: ConsumerGroupConfig{Brokers: []string{"broker1"}, HeartbeatInterval: 2}, errorOccured: true},
{config: ConsumerGroupConfig{Brokers: []string{"broker1"}, Topics: []string{"t1"}}, errorOccured: true},
{config: ConsumerGroupConfig{Brokers: []string{"broker1"}, Topics: []string{"t1"}, ID: "group1", HeartbeatInterval: -1}, errorOccured: true},
{config: ConsumerGroupConfig{Brokers: []string{"broker1"}, Topics: []string{"t1"}, ID: "group1", SessionTimeout: -1}, errorOccured: true},
{config: ConsumerGroupConfig{Brokers: []string{"broker1"}, Topics: []string{"t1"}, ID: "group1", HeartbeatInterval: 2, SessionTimeout: -1}, errorOccured: true},
{config: ConsumerGroupConfig{Brokers: []string{"broker1"}, Topics: []string{"t1"}, ID: "group1", HeartbeatInterval: 2, SessionTimeout: 2, RebalanceTimeout: -2}, errorOccured: true},
{config: ConsumerGroupConfig{Brokers: []string{"broker1"}, Topics: []string{"t1"}, ID: "group1", HeartbeatInterval: 2, SessionTimeout: 2, RebalanceTimeout: 2, RetentionTime: -1}, errorOccured: true},
{config: ConsumerGroupConfig{Brokers: []string{"broker1"}, Topics: []string{"t1"}, ID: "group1", HeartbeatInterval: 2, SessionTimeout: 2, RebalanceTimeout: 2, RetentionTime: 1, StartOffset: 123}, errorOccured: true},
{config: ConsumerGroupConfig{Brokers: []string{"broker1"}, Topics: []string{"t1"}, ID: "group1", HeartbeatInterval: 2, SessionTimeout: 2, RebalanceTimeout: 2, RetentionTime: 1, PartitionWatchInterval: -1}, errorOccured: true},
{config: ConsumerGroupConfig{Brokers: []string{"broker1"}, Topics: []string{"t1"}, ID: "group1", HeartbeatInterval: 2, SessionTimeout: 2, RebalanceTimeout: 2, RetentionTime: 1, PartitionWatchInterval: 1, JoinGroupBackoff: -1}, errorOccured: true},
{config: ConsumerGroupConfig{Brokers: []string{"broker1"}, Topics: []string{"t1"}, ID: "group1", HeartbeatInterval: 2, SessionTimeout: 2, RebalanceTimeout: 2, RetentionTime: 1, PartitionWatchInterval: 1, JoinGroupBackoff: 1}, errorOccured: false},
}
for _, test := range tests {
err := test.config.Validate()
if test.errorOccured && err == nil {
t.Error("expected an error", test.config)
}
if !test.errorOccured && err != nil {
t.Error("expected no error, got", err, test.config)
}
}
}
func TestReaderAssignTopicPartitions(t *testing.T) {
conn := &mockCoordinator{
readPartitionsFunc: func(...string) ([]Partition, error) {
return []Partition{
{
Topic: "topic-1",
ID: 0,
},
{
Topic: "topic-1",
ID: 1,
},
{
Topic: "topic-1",
ID: 2,
},
{
Topic: "topic-2",
ID: 0,
},
}, nil
},
}
newJoinGroupResponseV1 := func(topicsByMemberID map[string][]string) joinGroupResponseV1 {
resp := joinGroupResponseV1{
GroupProtocol: RoundRobinGroupBalancer{}.ProtocolName(),
}
for memberID, topics := range topicsByMemberID {
resp.Members = append(resp.Members, joinGroupResponseMemberV1{
MemberID: memberID,
MemberMetadata: groupMetadata{
Topics: topics,
}.bytes(),
})
}
return resp
}
testCases := map[string]struct {
Members joinGroupResponseV1
Assignments GroupMemberAssignments
}{
"nil": {
Members: newJoinGroupResponseV1(nil),
Assignments: GroupMemberAssignments{},
},
"one member, one topic": {
Members: newJoinGroupResponseV1(map[string][]string{
"member-1": {"topic-1"},
}),
Assignments: GroupMemberAssignments{
"member-1": map[string][]int{
"topic-1": {0, 1, 2},
},
},
},
"one member, two topics": {
Members: newJoinGroupResponseV1(map[string][]string{
"member-1": {"topic-1", "topic-2"},
}),
Assignments: GroupMemberAssignments{
"member-1": map[string][]int{
"topic-1": {0, 1, 2},
"topic-2": {0},
},
},
},
"two members, one topic": {
Members: newJoinGroupResponseV1(map[string][]string{
"member-1": {"topic-1"},
"member-2": {"topic-1"},
}),
Assignments: GroupMemberAssignments{
"member-1": map[string][]int{
"topic-1": {0, 2},
},
"member-2": map[string][]int{
"topic-1": {1},
},
},
},
"two members, two unshared topics": {
Members: newJoinGroupResponseV1(map[string][]string{
"member-1": {"topic-1"},
"member-2": {"topic-2"},
}),
Assignments: GroupMemberAssignments{
"member-1": map[string][]int{
"topic-1": {0, 1, 2},
},
"member-2": map[string][]int{
"topic-2": {0},
},
},
},
}
for label, tc := range testCases {
t.Run(label, func(t *testing.T) {
cg := ConsumerGroup{}
cg.config.GroupBalancers = []GroupBalancer{
RangeGroupBalancer{},
RoundRobinGroupBalancer{},
}
assignments, err := cg.assignTopicPartitions(conn, tc.Members)
if err != nil {
t.Fatalf("bad err: %v", err)
}
if !reflect.DeepEqual(tc.Assignments, assignments) {
t.Errorf("expected %v; got %v", tc.Assignments, assignments)
}
})
}
}
func TestConsumerGroup(t *testing.T) {
tests := []struct {
scenario string
function func(*testing.T, context.Context, *ConsumerGroup)
}{
{
scenario: "Next returns generations",
function: func(t *testing.T, ctx context.Context, cg *ConsumerGroup) {
gen1, err := cg.Next(ctx)
if gen1 == nil {
t.Fatalf("expected generation 1 not to be nil")
}
if err != nil {
t.Fatalf("expected no error, but got %+v", err)
}
// returning from this function should cause the generation to
// exit.
gen1.Start(func(context.Context) {})
// if this fails due to context timeout, it would indicate that
// the
gen2, err := cg.Next(ctx)
if gen2 == nil {
t.Fatalf("expected generation 2 not to be nil")
}
if err != nil {
t.Fatalf("expected no error, but got %+v", err)
}
if gen1.ID == gen2.ID {
t.Errorf("generation ID should have changed, but it stayed as %d", gen1.ID)
}
if gen1.GroupID != gen2.GroupID {
t.Errorf("mismatched group ID between generations: %s and %s", gen1.GroupID, gen2.GroupID)
}
if gen1.MemberID != gen2.MemberID {
t.Errorf("mismatched member ID between generations: %s and %s", gen1.MemberID, gen2.MemberID)
}
},
},
{
scenario: "Next returns ctx.Err() on canceled context",
function: func(t *testing.T, _ context.Context, cg *ConsumerGroup) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
gen, err := cg.Next(ctx)
if gen != nil {
t.Errorf("expected generation to be nil")
}
if !errors.Is(err, context.Canceled) {
t.Errorf("expected context.Canceled, but got %+v", err)
}
},
},
{
scenario: "Next returns ErrGroupClosed on closed group",
function: func(t *testing.T, ctx context.Context, cg *ConsumerGroup) {
if err := cg.Close(); err != nil {
t.Fatal(err)
}
gen, err := cg.Next(ctx)
if gen != nil {
t.Errorf("expected generation to be nil")
}
if !errors.Is(err, ErrGroupClosed) {
t.Errorf("expected ErrGroupClosed, but got %+v", err)
}
},
},
}
topic := makeTopic()
createTopic(t, topic, 1)
defer deleteTopic(t, topic)
for _, test := range tests {
t.Run(test.scenario, func(t *testing.T) {
group, err := NewConsumerGroup(ConsumerGroupConfig{
ID: makeGroupID(),
Topics: []string{topic},
Brokers: []string{"localhost:9092"},
HeartbeatInterval: 2 * time.Second,
RebalanceTimeout: 2 * time.Second,
RetentionTime: time.Hour,
Logger: &testKafkaLogger{T: t},
})
if err != nil {
t.Fatal(err)
}
defer group.Close()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
test.function(t, ctx, group)
})
}
}
func TestConsumerGroupErrors(t *testing.T) {
var left []string
var lock sync.Mutex
mc := mockCoordinator{
leaveGroupFunc: func(req leaveGroupRequestV0) (leaveGroupResponseV0, error) {
lock.Lock()
left = append(left, req.MemberID)
lock.Unlock()
return leaveGroupResponseV0{}, nil
},
}
assertLeftGroup := func(t *testing.T, memberID string) {
lock.Lock()
if !reflect.DeepEqual(left, []string{memberID}) {
t.Errorf("expected abc to have left group once, members left: %v", left)
}
left = left[0:0]
lock.Unlock()
}
// NOTE : the mocked behavior is accumulated across the tests, so they are
// NOT run in parallel. this simplifies test setup so that each test
// can specify only the error behavior required and leverage setup
// from previous steps.
tests := []struct {
scenario string
prepare func(*mockCoordinator)
function func(*testing.T, context.Context, *ConsumerGroup)
}{
{
scenario: "fails to find coordinator (general error)",
prepare: func(mc *mockCoordinator) {
mc.findCoordinatorFunc = func(findCoordinatorRequestV0) (findCoordinatorResponseV0, error) {
return findCoordinatorResponseV0{}, errors.New("dial error")
}
},
function: func(t *testing.T, ctx context.Context, group *ConsumerGroup) {
gen, err := group.Next(ctx)
if err == nil {
t.Errorf("expected an error")
} else if err.Error() != "dial error" {
t.Errorf("got wrong error: %+v", err)
}
if gen != nil {
t.Error("expected a nil consumer group generation")
}
},
},
{
scenario: "fails to find coordinator (error code in response)",
prepare: func(mc *mockCoordinator) {
mc.findCoordinatorFunc = func(findCoordinatorRequestV0) (findCoordinatorResponseV0, error) {
return findCoordinatorResponseV0{
ErrorCode: int16(NotCoordinatorForGroup),
}, nil
}
},
function: func(t *testing.T, ctx context.Context, group *ConsumerGroup) {
gen, err := group.Next(ctx)
if err == nil {
t.Errorf("expected an error")
} else if !errors.Is(err, NotCoordinatorForGroup) {
t.Errorf("got wrong error: %+v", err)
}
if gen != nil {
t.Error("expected a nil consumer group generation")
}
},
},
{
scenario: "fails to join group (general error)",
prepare: func(mc *mockCoordinator) {
mc.findCoordinatorFunc = func(findCoordinatorRequestV0) (findCoordinatorResponseV0, error) {
return findCoordinatorResponseV0{
Coordinator: findCoordinatorResponseCoordinatorV0{
NodeID: 1,
Host: "foo.bar.com",
Port: 12345,
},
}, nil
}
mc.joinGroupFunc = func(joinGroupRequestV1) (joinGroupResponseV1, error) {
return joinGroupResponseV1{}, errors.New("join group failed")
}
// NOTE : no stub for leaving the group b/c the member never joined.
},
function: func(t *testing.T, ctx context.Context, group *ConsumerGroup) {
gen, err := group.Next(ctx)
if err == nil {
t.Errorf("expected an error")
} else if err.Error() != "join group failed" {
t.Errorf("got wrong error: %+v", err)
}
if gen != nil {
t.Error("expected a nil consumer group generation")
}
},
},
{
scenario: "fails to join group (error code)",
prepare: func(mc *mockCoordinator) {
mc.findCoordinatorFunc = func(findCoordinatorRequestV0) (findCoordinatorResponseV0, error) {
return findCoordinatorResponseV0{
Coordinator: findCoordinatorResponseCoordinatorV0{
NodeID: 1,
Host: "foo.bar.com",
Port: 12345,
},
}, nil
}
mc.joinGroupFunc = func(joinGroupRequestV1) (joinGroupResponseV1, error) {
return joinGroupResponseV1{
ErrorCode: int16(InvalidTopic),
}, nil
}
// NOTE : no stub for leaving the group b/c the member never joined.
},
function: func(t *testing.T, ctx context.Context, group *ConsumerGroup) {
gen, err := group.Next(ctx)
if err == nil {
t.Errorf("expected an error")
} else if !errors.Is(err, InvalidTopic) {
t.Errorf("got wrong error: %+v", err)
}
if gen != nil {
t.Error("expected a nil consumer group generation")
}
},
},
{
scenario: "fails to join group (leader, unsupported protocol)",
prepare: func(mc *mockCoordinator) {
mc.joinGroupFunc = func(joinGroupRequestV1) (joinGroupResponseV1, error) {
return joinGroupResponseV1{
GenerationID: 12345,
GroupProtocol: "foo",
LeaderID: "abc",
MemberID: "abc",
}, nil
}
},
function: func(t *testing.T, ctx context.Context, group *ConsumerGroup) {
gen, err := group.Next(ctx)
if err == nil {
t.Errorf("expected an error")
} else if !strings.HasPrefix(err.Error(), "unable to find selected balancer") {
t.Errorf("got wrong error: %+v", err)
}
if gen != nil {
t.Error("expected a nil consumer group generation")
}
assertLeftGroup(t, "abc")
},
},
{
scenario: "fails to sync group (general error)",
prepare: func(mc *mockCoordinator) {
mc.joinGroupFunc = func(joinGroupRequestV1) (joinGroupResponseV1, error) {
return joinGroupResponseV1{
GenerationID: 12345,
GroupProtocol: "range",
LeaderID: "abc",
MemberID: "abc",
}, nil
}
mc.readPartitionsFunc = func(...string) ([]Partition, error) {
return []Partition{}, nil
}
mc.syncGroupFunc = func(syncGroupRequestV0) (syncGroupResponseV0, error) {
return syncGroupResponseV0{}, errors.New("sync group failed")
}
},
function: func(t *testing.T, ctx context.Context, group *ConsumerGroup) {
gen, err := group.Next(ctx)
if err == nil {
t.Errorf("expected an error")
} else if err.Error() != "sync group failed" {
t.Errorf("got wrong error: %+v", err)
}
if gen != nil {
t.Error("expected a nil consumer group generation")
}
assertLeftGroup(t, "abc")
},
},
{
scenario: "fails to sync group (error code)",
prepare: func(mc *mockCoordinator) {
mc.syncGroupFunc = func(syncGroupRequestV0) (syncGroupResponseV0, error) {
return syncGroupResponseV0{
ErrorCode: int16(InvalidTopic),
}, nil
}
},
function: func(t *testing.T, ctx context.Context, group *ConsumerGroup) {
gen, err := group.Next(ctx)
if err == nil {
t.Errorf("expected an error")
} else if !errors.Is(err, InvalidTopic) {
t.Errorf("got wrong error: %+v", err)
}
if gen != nil {
t.Error("expected a nil consumer group generation")
}
assertLeftGroup(t, "abc")
},
},
}
for _, tt := range tests {
t.Run(tt.scenario, func(t *testing.T) {
tt.prepare(&mc)
group, err := NewConsumerGroup(ConsumerGroupConfig{
ID: makeGroupID(),
Topics: []string{"test"},
Brokers: []string{"no-such-broker"}, // should not attempt to actually dial anything
HeartbeatInterval: 2 * time.Second,
RebalanceTimeout: time.Second,
JoinGroupBackoff: time.Second,
RetentionTime: time.Hour,
connect: func(*Dialer, ...string) (coordinator, error) {
return mc, nil
},
Logger: &testKafkaLogger{T: t},
})
if err != nil {
t.Fatal(err)
}
// these tests should all execute fairly quickly since they're
// mocking the coordinator.
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
tt.function(t, ctx, group)
if err := group.Close(); err != nil {
t.Errorf("error on close: %+v", err)
}
})
}
}
// todo : test for multi-topic?
func TestGenerationExitsOnPartitionChange(t *testing.T) {
var count int
partitions := [][]Partition{
{
Partition{
Topic: "topic-1",
ID: 0,
},
},
{
Partition{
Topic: "topic-1",
ID: 0,
},
{
Topic: "topic-1",
ID: 1,
},
},
}
conn := mockCoordinator{
readPartitionsFunc: func(...string) ([]Partition, error) {
p := partitions[count]
// cap the count at len(partitions) -1 so ReadPartitions doesn't even go out of bounds
// and long running tests don't fail
if count < len(partitions) {
count++
}
return p, nil
},
}
// Sadly this test is time based, so at the end will be seeing if the runGroup run to completion within the
// allotted time. The allotted time is 4x the PartitionWatchInterval.
now := time.Now()
watchTime := 500 * time.Millisecond
gen := Generation{
conn: conn,
done: make(chan struct{}),
joined: make(chan struct{}),
log: func(func(Logger)) {},
logError: func(func(Logger)) {},
}
done := make(chan struct{})
go func() {
gen.partitionWatcher(watchTime, "topic-1")
close(done)
}()
select {
case <-time.After(5 * time.Second):
t.Fatal("timed out waiting for partition watcher to exit")
case <-done:
if time.Since(now).Seconds() > watchTime.Seconds()*4 {
t.Error("partitionWatcher didn't see update")
}
}
}
func TestGenerationStartsFunctionAfterClosed(t *testing.T) {
gen := Generation{
conn: &mockCoordinator{},
done: make(chan struct{}),
joined: make(chan struct{}),
log: func(func(Logger)) {},
logError: func(func(Logger)) {},
}
gen.close()
ch := make(chan error)
gen.Start(func(ctx context.Context) {
<-ctx.Done()
ch <- ctx.Err()
})
select {
case <-time.After(time.Second):
t.Fatal("timed out waiting for func to run")
case err := <-ch:
if !errors.Is(err, ErrGenerationEnded) {
t.Fatalf("expected %v but got %v", ErrGenerationEnded, err)
}
}
}