@@ -1451,36 +1451,87 @@ func TestCommitLoopImmediateFlushOnGenerationEnd(t *testing.T) {
1451
1451
}
1452
1452
1453
1453
func TestCommitOffsetsWithRetry (t * testing.T ) {
1454
- offsets := offsetStash {"topic" : {0 : {0 , 1 }}}
1454
+ offsets := func () offsetStash {
1455
+ return offsetStash {"topic" : {0 : {0 , 1 }}}
1456
+ }
1455
1457
1456
1458
tests := map [string ]struct {
1457
- Fails int
1458
- Invocations int
1459
- HasError bool
1459
+ Fails int
1460
+ Invocations int
1461
+ HasError bool
1462
+ Error error
1463
+ Offsets offsetStash
1464
+ Config ReaderConfig
1465
+ ExpectedOffsets offsetStash
1460
1466
}{
1461
1467
"happy path" : {
1462
- Invocations : 1 ,
1468
+ Invocations : 1 ,
1469
+ Error : io .EOF ,
1470
+ Offsets : offsets (),
1471
+ ExpectedOffsets : offsets (),
1463
1472
},
1464
1473
"1 retry" : {
1465
- Fails : 1 ,
1466
- Invocations : 2 ,
1474
+ Fails : 1 ,
1475
+ Invocations : 2 ,
1476
+ Error : io .EOF ,
1477
+ Offsets : offsets (),
1478
+ ExpectedOffsets : offsets (),
1467
1479
},
1468
1480
"out of retries" : {
1469
- Fails : defaultCommitRetries + 1 ,
1470
- Invocations : defaultCommitRetries ,
1471
- HasError : true ,
1481
+ Fails : defaultCommitRetries + 1 ,
1482
+ Invocations : defaultCommitRetries ,
1483
+ HasError : true ,
1484
+ Error : io .EOF ,
1485
+ Offsets : offsets (),
1486
+ ExpectedOffsets : offsets (),
1487
+ },
1488
+ "illegal generation error only 1 generation" : {
1489
+ Fails : 1 ,
1490
+ Invocations : 1 ,
1491
+ Error : IllegalGeneration ,
1492
+ Offsets : offsetStash {"topic" : {0 : {0 , 1 }, 1 : {0 , 1 }}},
1493
+ ExpectedOffsets : offsetStash {},
1494
+ Config : ReaderConfig {ErrorOnWrongGenerationCommit : false },
1495
+ },
1496
+ "illegal generation error only 2 generations" : {
1497
+ Fails : 1 ,
1498
+ Invocations : 1 ,
1499
+ Error : IllegalGeneration ,
1500
+ Offsets : offsetStash {"topic" : {0 : {0 , 1 }, 1 : {0 , 2 }}},
1501
+ ExpectedOffsets : offsetStash {"topic" : {1 : {0 , 2 }}},
1502
+ Config : ReaderConfig {ErrorOnWrongGenerationCommit : false },
1503
+ },
1504
+ "illegal generation error only 1 generation - error propagation" : {
1505
+ Fails : 1 ,
1506
+ Invocations : 1 ,
1507
+ Error : IllegalGeneration ,
1508
+ Offsets : offsetStash {"topic" : {0 : {0 , 1 }, 1 : {0 , 1 }}},
1509
+ ExpectedOffsets : offsetStash {},
1510
+ Config : ReaderConfig {ErrorOnWrongGenerationCommit : true },
1511
+ HasError : true ,
1512
+ },
1513
+ "illegal generation error only 2 generations - error propagation" : {
1514
+ Fails : 1 ,
1515
+ Invocations : 1 ,
1516
+ Error : IllegalGeneration ,
1517
+ Offsets : offsetStash {"topic" : {0 : {0 , 1 }, 1 : {0 , 2 }}},
1518
+ ExpectedOffsets : offsetStash {"topic" : {1 : {0 , 2 }}},
1519
+ Config : ReaderConfig {ErrorOnWrongGenerationCommit : true },
1520
+ HasError : true ,
1472
1521
},
1473
1522
}
1474
1523
1475
1524
for label , test := range tests {
1476
1525
t .Run (label , func (t * testing.T ) {
1526
+ requests := make ([]offsetCommitRequestV2 , 0 )
1477
1527
count := 0
1478
1528
gen := & Generation {
1479
1529
conn : mockCoordinator {
1480
- offsetCommitFunc : func (offsetCommitRequestV2 ) (offsetCommitResponseV2 , error ) {
1530
+ offsetCommitFunc : func (r offsetCommitRequestV2 ) (offsetCommitResponseV2 , error ) {
1531
+ requests = append (requests , r )
1481
1532
count ++
1482
1533
if count <= test .Fails {
1483
- return offsetCommitResponseV2 {}, io . EOF
1534
+ return offsetCommitResponseV2 {}, test . Error
1484
1535
}
1485
1536
return offsetCommitResponseV2 {}, nil
1486
1537
},
@@ -1491,13 +1542,17 @@ func TestCommitOffsetsWithRetry(t *testing.T) {
1491
1542
Assignments : map [string ][]PartitionAssignment {"topic" : {{0 , 1 }}},
1492
1543
}
1493
1544
1494
- r := & Reader {stctx : context .Background ()}
1495
- err := r .commitOffsetsWithRetry (gen , offsets , defaultCommitRetries )
1545
+ r := & Reader {stctx : context .Background (), config : test . Config }
1546
+ err := r .commitOffsetsWithRetry (gen , test . Offsets , defaultCommitRetries )
1496
1547
switch {
1497
1548
case test .HasError && err == nil :
1498
1549
t .Error ("bad err: expected not nil; got nil" )
1499
1550
case ! test .HasError && err != nil :
1500
1551
t .Errorf ("bad err: expected nil; got %v" , err )
1552
+ default :
1553
+ if ! reflect .DeepEqual (test .ExpectedOffsets , test .Offsets ) {
1554
+ t .Errorf ("bad expected offsets: expected %+v; got %v" , test .ExpectedOffsets , test .Offsets )
1555
+ }
1501
1556
}
1502
1557
})
1503
1558
}
0 commit comments