@@ -535,6 +535,74 @@ func TestBatchSenderWithTimeout(t *testing.T) {
535
535
assert .EqualValues (t , 12 , sink .itemsCount .Load ())
536
536
}
537
537
538
+ func TestBatchSenderTimerResetNoConflict (t * testing.T ) {
539
+ bCfg := exporterbatcher .NewDefaultConfig ()
540
+ bCfg .MinSizeItems = 8
541
+ bCfg .FlushTimeout = 50 * time .Millisecond
542
+ be , err := newBaseExporter (defaultSettings , defaultDataType , newNoopObsrepSender ,
543
+ WithBatcher (bCfg , WithRequestBatchFuncs (fakeBatchMergeFunc , fakeBatchMergeSplitFunc )))
544
+ require .NoError (t , err )
545
+ require .NoError (t , be .Start (context .Background (), componenttest .NewNopHost ()))
546
+
547
+ sink := newFakeRequestSink ()
548
+
549
+ // Send 2 concurrent requests that should be merged in one batch in the same interval as the flush timer
550
+ go func () {
551
+ require .NoError (t , be .send (context .Background (), & fakeRequest {items : 4 , sink : sink }))
552
+ }()
553
+ time .Sleep (50 * time .Millisecond )
554
+ go func () {
555
+ require .NoError (t , be .send (context .Background (), & fakeRequest {items : 4 , sink : sink }))
556
+ }()
557
+
558
+ // The batch should be sent either with the flush interval or by reaching the minimum items size with no conflict
559
+ assert .EventuallyWithT (t , func (c * assert.CollectT ) {
560
+ assert .LessOrEqual (c , uint64 (1 ), sink .requestsCount .Load ())
561
+ assert .EqualValues (c , 8 , sink .itemsCount .Load ())
562
+ }, 200 * time .Millisecond , 10 * time .Millisecond )
563
+
564
+ require .NoError (t , be .Shutdown (context .Background ()))
565
+ }
566
+
567
+ func TestBatchSenderTimerFlush (t * testing.T ) {
568
+ bCfg := exporterbatcher .NewDefaultConfig ()
569
+ bCfg .MinSizeItems = 8
570
+ bCfg .FlushTimeout = 100 * time .Millisecond
571
+ be , err := newBaseExporter (defaultSettings , defaultDataType , newNoopObsrepSender ,
572
+ WithBatcher (bCfg , WithRequestBatchFuncs (fakeBatchMergeFunc , fakeBatchMergeSplitFunc )))
573
+ require .NoError (t , err )
574
+ require .NoError (t , be .Start (context .Background (), componenttest .NewNopHost ()))
575
+
576
+ sink := newFakeRequestSink ()
577
+
578
+ time .Sleep (50 * time .Millisecond )
579
+
580
+ // Send 2 concurrent requests that should be merged in one batch and sent immediately
581
+ go func () {
582
+ require .NoError (t , be .send (context .Background (), & fakeRequest {items : 4 , sink : sink }))
583
+ }()
584
+ go func () {
585
+ require .NoError (t , be .send (context .Background (), & fakeRequest {items : 4 , sink : sink }))
586
+ }()
587
+
588
+ assert .EventuallyWithT (t , func (c * assert.CollectT ) {
589
+ assert .LessOrEqual (c , uint64 (1 ), sink .requestsCount .Load ())
590
+ assert .EqualValues (c , 8 , sink .itemsCount .Load ())
591
+ }, 30 * time .Millisecond , 5 * time .Millisecond )
592
+
593
+ // Send another request that should be sent after the flush timeout which supposed to happen after remaining 50ms
594
+ go func () {
595
+ require .NoError (t , be .send (context .Background (), & fakeRequest {items : 4 , sink : sink }))
596
+ }()
597
+
598
+ assert .EventuallyWithT (t , func (c * assert.CollectT ) {
599
+ assert .LessOrEqual (c , uint64 (1 ), sink .requestsCount .Load ())
600
+ assert .EqualValues (c , 8 , sink .itemsCount .Load ())
601
+ }, 60 * time .Millisecond , 5 * time .Millisecond )
602
+
603
+ require .NoError (t , be .Shutdown (context .Background ()))
604
+ }
605
+
538
606
func queueBatchExporter (t * testing.T , batchOption Option ) * baseExporter {
539
607
be , err := newBaseExporter (defaultSettings , defaultDataType , newNoopObsrepSender , batchOption ,
540
608
WithRequestQueue (exporterqueue .NewDefaultConfig (), exporterqueue .NewMemoryQueueFactory [Request ]()))
0 commit comments