@@ -50,6 +50,33 @@ func TestExporterTraceDataCallbackSingleSpan(t *testing.T) {
5050 assert .NoError (t , exporter .onTraceData (context .Background (), traces ))
5151
5252 mockTransportChannel .AssertNumberOfCalls (t , "Send" , 1 )
53+ mockTransportChannel .AssertNumberOfCalls (t , "Flush" , 1 )
54+ }
55+
56+ func TestExporterTraceDataCallbackCallFlushOnce (t * testing.T ) {
57+ mockTransportChannel := getMockTransportChannel ()
58+ exporter := getExporter (defaultConfig , mockTransportChannel )
59+
60+ resource := getResource ()
61+ scope := getScope ()
62+ span := getDefaultHTTPServerSpan ()
63+
64+ traces := ptrace .NewTraces ()
65+ rs := traces .ResourceSpans ().AppendEmpty ()
66+ r := rs .Resource ()
67+ resource .CopyTo (r )
68+ ilss := rs .ScopeSpans ().AppendEmpty ()
69+ scope .CopyTo (ilss .Scope ())
70+
71+ span .CopyTo (ilss .Spans ().AppendEmpty ())
72+ span .CopyTo (ilss .Spans ().AppendEmpty ())
73+ ilss .CopyTo (rs .ScopeSpans ().AppendEmpty ())
74+ rs .CopyTo (traces .ResourceSpans ().AppendEmpty ())
75+
76+ assert .NoError (t , exporter .onTraceData (context .Background (), traces ))
77+
78+ mockTransportChannel .AssertNumberOfCalls (t , "Send" , 8 )
79+ mockTransportChannel .AssertNumberOfCalls (t , "Flush" , 1 )
5380}
5481
5582// Tests the export onTraceData callback with a single Span with SpanEvents
@@ -82,6 +109,7 @@ func TestExporterTraceDataCallbackSingleSpanWithSpanEvents(t *testing.T) {
82109 assert .NoError (t , exporter .onTraceData (context .Background (), traces ))
83110
84111 mockTransportChannel .AssertNumberOfCalls (t , "Send" , 3 )
112+ mockTransportChannel .AssertNumberOfCalls (t , "Flush" , 1 )
85113}
86114
87115// Tests the export onTraceData callback with a single Span that fails to produce an envelope
@@ -111,6 +139,7 @@ func TestExporterTraceDataCallbackSingleSpanNoEnvelope(t *testing.T) {
111139 assert .True (t , consumererror .IsPermanent (err ), "error should be permanent" )
112140
113141 mockTransportChannel .AssertNumberOfCalls (t , "Send" , 0 )
142+ mockTransportChannel .AssertNumberOfCalls (t , "Flush" , 0 )
114143}
115144
116145func getMockTransportChannel () * mockTransportChannel {
0 commit comments