@@ -669,6 +669,67 @@ test('client.sent', function (t) {
669
669
} )
670
670
} )
671
671
672
+ test ( 'should not open new request until it\'s needed after flush' , function ( t ) {
673
+ let client
674
+ let requests = 0
675
+ let expectRequest = false
676
+ const server = APMServer ( function ( req , res ) {
677
+ t . equal ( expectRequest , true , 'should only send new request when expected' )
678
+ expectRequest = false
679
+
680
+ req . resume ( )
681
+ req . on ( 'end' , function ( ) {
682
+ res . end ( )
683
+
684
+ if ( ++ requests === 2 ) {
685
+ server . close ( )
686
+ t . end ( )
687
+ } else {
688
+ setTimeout ( sendData , 250 )
689
+ }
690
+ } )
691
+ } ) . client ( function ( _client ) {
692
+ client = _client
693
+ sendData ( )
694
+ } )
695
+
696
+ function sendData ( ) {
697
+ expectRequest = true
698
+ client . sendError ( { foo : 42 } )
699
+ client . flush ( )
700
+ }
701
+ } )
702
+
703
+ test ( 'should not open new request until it\'s needed after timeout' , function ( t ) {
704
+ let client
705
+ let requests = 0
706
+ let expectRequest = false
707
+ const server = APMServer ( function ( req , res ) {
708
+ t . equal ( expectRequest , true , 'should only send new request when expected' )
709
+ expectRequest = false
710
+
711
+ req . resume ( )
712
+ req . on ( 'end' , function ( ) {
713
+ res . end ( )
714
+
715
+ if ( ++ requests === 2 ) {
716
+ server . close ( )
717
+ t . end ( )
718
+ } else {
719
+ setTimeout ( sendData , 250 )
720
+ }
721
+ } )
722
+ } ) . client ( { time : 1 } , function ( _client ) {
723
+ client = _client
724
+ sendData ( )
725
+ } )
726
+
727
+ function sendData ( ) {
728
+ expectRequest = true
729
+ client . sendError ( { foo : 42 } )
730
+ }
731
+ } )
732
+
672
733
/**
673
734
* Side effects
674
735
*/
0 commit comments