MCPcopy
hub / github.com/segmentio/kafka-go / TestConsumerGroup

Function TestConsumerGroup

consumergroup_test.go:244–344  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

242}
243
244func TestConsumerGroup(t *testing.T) {
245 tests := []struct {
246 scenario string
247 function func(*testing.T, context.Context, *ConsumerGroup)
248 }{
249 {
250 scenario: "Next returns generations",
251 function: func(t *testing.T, ctx context.Context, cg *ConsumerGroup) {
252 gen1, err := cg.Next(ctx)
253 if gen1 == nil {
254 t.Fatalf("expected generation 1 not to be nil")
255 }
256 if err != nil {
257 t.Fatalf("expected no error, but got %+v", err)
258 }
259 // returning from this function should cause the generation to
260 // exit.
261 gen1.Start(func(context.Context) {})
262
263 // if this fails due to context timeout, it would indicate that
264 // the
265 gen2, err := cg.Next(ctx)
266 if gen2 == nil {
267 t.Fatalf("expected generation 2 not to be nil")
268 }
269 if err != nil {
270 t.Fatalf("expected no error, but got %+v", err)
271 }
272
273 if gen1.ID == gen2.ID {
274 t.Errorf("generation ID should have changed, but it stayed as %d", gen1.ID)
275 }
276 if gen1.GroupID != gen2.GroupID {
277 t.Errorf("mismatched group ID between generations: %s and %s", gen1.GroupID, gen2.GroupID)
278 }
279 if gen1.MemberID != gen2.MemberID {
280 t.Errorf("mismatched member ID between generations: %s and %s", gen1.MemberID, gen2.MemberID)
281 }
282 },
283 },
284
285 {
286 scenario: "Next returns ctx.Err() on canceled context",
287 function: func(t *testing.T, _ context.Context, cg *ConsumerGroup) {
288 ctx, cancel := context.WithCancel(context.Background())
289 cancel()
290
291 gen, err := cg.Next(ctx)
292 if gen != nil {
293 t.Errorf("expected generation to be nil")
294 }
295 if !errors.Is(err, context.Canceled) {
296 t.Errorf("expected context.Canceled, but got %+v", err)
297 }
298 },
299 },
300
301 {

Callers

nothing calls this directly

Calls 9

CloseMethod · 0.95
createTopicFunction · 0.85
deleteTopicFunction · 0.85
NewConsumerGroupFunction · 0.85
makeGroupIDFunction · 0.85
makeTopicFunction · 0.70
NextMethod · 0.65
StartMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected