@@ -503,64 +503,89 @@ func TestWatchBatchUnsynced(t *testing.T) {
503
503
tcs := []struct {
504
504
name string
505
505
revisions int
506
- watchBatchMaxRevs int
506
+ eventSize int
507
+ watchBatchMaxSize int
507
508
eventsPerRevision int
508
509
expectRevisionBatches [][]int64
509
510
}{
510
511
{
511
- name : "3 revisions, 4 revs per batch, 1 events per revision" ,
512
- revisions : 12 ,
513
- watchBatchMaxRevs : 4 ,
512
+ name : "Fits into a single batch" ,
513
+ revisions : 10 ,
514
+ eventSize : 100 ,
515
+ watchBatchMaxSize : 1000 ,
514
516
eventsPerRevision : 1 ,
515
517
expectRevisionBatches : [][]int64 {
516
- {2 , 3 , 4 , 5 },
517
- {6 , 7 , 8 , 9 },
518
- {10 , 11 , 12 , 13 },
518
+ {2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 },
519
519
},
520
520
},
521
521
{
522
- name : "3 revisions, 4 revs per batch, 3 events per revision" ,
523
- revisions : 12 ,
524
- watchBatchMaxRevs : 4 ,
522
+ name : "Spills to second batch" ,
523
+ revisions : 15 ,
524
+ eventSize : 100 ,
525
+ watchBatchMaxSize : 1000 ,
526
+ eventsPerRevision : 1 ,
527
+ expectRevisionBatches : [][]int64 {
528
+ {2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 },
529
+ {12 , 13 , 14 , 15 , 16 },
530
+ },
531
+ },
532
+ {
533
+ name : "Spills to second batch, but maintains revision pairs" ,
534
+ revisions : 8 ,
535
+ eventSize : 100 ,
536
+ watchBatchMaxSize : 1000 ,
537
+ eventsPerRevision : 2 ,
538
+ expectRevisionBatches : [][]int64 {
539
+ {2 , 2 , 3 , 3 , 4 , 4 , 5 , 5 , 6 , 6 },
540
+ {7 , 7 , 8 , 8 , 9 , 9 },
541
+ },
542
+ },
543
+ {
544
+ name : "Spills to second batch, but maintains revision triples" ,
545
+ revisions : 6 ,
546
+ eventSize : 100 ,
547
+ watchBatchMaxSize : 1000 ,
525
548
eventsPerRevision : 3 ,
526
549
expectRevisionBatches : [][]int64 {
527
550
{2 , 2 , 2 , 3 , 3 , 3 , 4 , 4 , 4 , 5 , 5 , 5 },
528
- {6 , 6 , 6 , 7 , 7 , 7 , 8 , 8 , 8 , 9 , 9 , 9 },
529
- {10 , 10 , 10 , 11 , 11 , 11 , 12 , 12 , 12 , 13 , 13 , 13 },
551
+ {6 , 6 , 6 , 7 , 7 , 7 },
530
552
},
531
553
},
532
554
}
533
555
for _ , tc := range tcs {
534
556
t .Run (tc .name , func (t * testing.T ) {
535
557
b , _ := betesting .NewDefaultTmpBackend (t )
536
558
s := New (zaptest .NewLogger (t ), b , & lease.FakeLessor {}, StoreConfig {})
537
- oldMaxRevs := watchBatchMaxRevs
559
+ oldMaxRevs := watchBatchMaxSize
538
560
defer func () {
539
- watchBatchMaxRevs = oldMaxRevs
561
+ watchBatchMaxSize = oldMaxRevs
540
562
cleanup (s , b )
541
563
}()
542
- watchBatchMaxRevs = tc .watchBatchMaxRevs
564
+ watchBatchMaxSize = tc .watchBatchMaxSize
543
565
544
- v := []byte ("foo" )
566
+ k := []byte ("k" )
567
+ eventProtoOverhead := 13
568
+ v := make ([]byte , tc .eventSize - eventProtoOverhead )
545
569
for i := 0 ; i < tc .revisions ; i ++ {
546
570
txn := s .Write (traceutil .TODO ())
547
571
for j := 0 ; j < tc .eventsPerRevision ; j ++ {
548
- txn .Put (v , v , lease .NoLease )
572
+ txn .Put (k , v , lease .NoLease )
549
573
}
550
574
txn .End ()
551
575
}
552
576
553
577
w := s .NewWatchStream ()
554
578
defer w .Close ()
555
579
556
- w .Watch (0 , v , nil , 1 )
580
+ w .Watch (0 , k , nil , 1 )
557
581
var revisionBatches [][]int64
558
582
eventCount := 0
559
583
for eventCount < tc .revisions * tc .eventsPerRevision {
560
584
var revisions []int64
561
585
for _ , e := range (<- w .Chan ()).Events {
562
586
revisions = append (revisions , e .Kv .ModRevision )
563
587
eventCount ++
588
+ assert .Equal (t , tc .eventSize , e .Size ())
564
589
}
565
590
revisionBatches = append (revisionBatches , revisions )
566
591
}
0 commit comments