@@ -97,7 +97,7 @@ def _create_start_and_end_span(name, span_processor):
97
97
98
98
99
99
class TestBatchExportSpanProcessor (unittest .TestCase ):
100
- def test_batch_span_processor (self ):
100
+ def test_shutdown (self ):
101
101
spans_names_list = []
102
102
103
103
my_exporter = MySpanExporter (destination = spans_names_list )
@@ -109,9 +109,35 @@ def test_batch_span_processor(self):
109
109
_create_start_and_end_span (name , span_processor )
110
110
111
111
span_processor .shutdown ()
112
+ self .assertTrue (my_exporter .is_shutdown )
113
+
114
+ # check that spans are exported without an explicitly call to
115
+ # force_flush()
112
116
self .assertListEqual (span_names , spans_names_list )
113
117
114
- self .assertTrue (my_exporter .is_shutdown )
118
+ def test_flush (self ):
119
+ spans_names_list = []
120
+
121
+ my_exporter = MySpanExporter (destination = spans_names_list )
122
+ span_processor = export .BatchExportSpanProcessor (my_exporter )
123
+
124
+ span_names0 = ["xxx" , "bar" , "foo" ]
125
+ span_names1 = ["yyy" , "baz" , "fox" ]
126
+
127
+ for name in span_names0 :
128
+ _create_start_and_end_span (name , span_processor )
129
+
130
+ span_processor .force_flush ()
131
+ self .assertListEqual (span_names0 , spans_names_list )
132
+
133
+ # create some more spans to check that span processor still works
134
+ for name in span_names1 :
135
+ _create_start_and_end_span (name , span_processor )
136
+
137
+ span_processor .force_flush ()
138
+ self .assertListEqual (span_names0 + span_names1 , spans_names_list )
139
+
140
+ span_processor .shutdown ()
115
141
116
142
def test_batch_span_processor_lossless (self ):
117
143
"""Test that no spans are lost when sending max_queue_size spans"""
@@ -127,8 +153,9 @@ def test_batch_span_processor_lossless(self):
127
153
for _ in range (512 ):
128
154
_create_start_and_end_span ("foo" , span_processor )
129
155
130
- span_processor .shutdown ()
156
+ span_processor .force_flush ()
131
157
self .assertEqual (len (spans_names_list ), 512 )
158
+ span_processor .shutdown ()
132
159
133
160
def test_batch_span_processor_many_spans (self ):
134
161
"""Test that no spans are lost when sending many spans"""
@@ -150,8 +177,9 @@ def test_batch_span_processor_many_spans(self):
150
177
151
178
time .sleep (0.05 ) # give some time for the exporter to upload spans
152
179
153
- span_processor .shutdown ()
180
+ span_processor .force_flush ()
154
181
self .assertEqual (len (spans_names_list ), 1024 )
182
+ span_processor .shutdown ()
155
183
156
184
def test_batch_span_processor_scheduled_delay (self ):
157
185
"""Test that spans are exported each schedule_delay_millis"""
0 commit comments