@@ -55,12 +55,6 @@ func (t *testBatchExporter) getBatchCount() int {
55
55
return t .batchCount
56
56
}
57
57
58
- func (t * testBatchExporter ) get (idx int ) * export.SpanData {
59
- t .mu .Lock ()
60
- defer t .mu .Unlock ()
61
- return t .spans [idx ]
62
- }
63
-
64
58
var _ export.SpanBatcher = (* testBatchExporter )(nil )
65
59
66
60
func TestNewBatchSpanProcessorWithNilExporter (t * testing.T ) {
@@ -77,6 +71,7 @@ type testOption struct {
77
71
wantBatchCount int
78
72
genNumSpans int
79
73
waitTime time.Duration
74
+ parallel bool
80
75
}
81
76
82
77
func TestNewBatchSpanProcessorWithOptions (t * testing.T ) {
@@ -136,18 +131,30 @@ func TestNewBatchSpanProcessorWithOptions(t *testing.T) {
136
131
genNumSpans : 205 ,
137
132
waitTime : waitTime ,
138
133
},
134
+ {
135
+ name : "parallel span generation" ,
136
+ o : []sdktrace.BatchSpanProcessorOption {
137
+ sdktrace .WithScheduleDelayMillis (schDelay ),
138
+ sdktrace .WithMaxQueueSize (200 ),
139
+ },
140
+ wantNumSpans : 200 ,
141
+ wantBatchCount : 1 ,
142
+ genNumSpans : 205 ,
143
+ waitTime : waitTime ,
144
+ parallel : true ,
145
+ },
139
146
}
140
147
for _ , option := range options {
141
148
te := testBatchExporter {}
142
149
tp := basicProvider (t )
143
150
ssp := createAndRegisterBatchSP (t , option , & te )
144
151
if ssp == nil {
145
- t .Errorf ("%s: Error creating new instance of BatchSpanProcessor\n " , option .name )
152
+ t .Fatalf ("%s: Error creating new instance of BatchSpanProcessor\n " , option .name )
146
153
}
147
154
tp .RegisterSpanProcessor (ssp )
148
155
tr := tp .Tracer ("BatchSpanProcessorWithOptions" )
149
156
150
- generateSpan (t , tr , option )
157
+ generateSpan (t , option . parallel , tr , option )
151
158
152
159
time .Sleep (option .waitTime )
153
160
@@ -162,14 +169,6 @@ func TestNewBatchSpanProcessorWithOptions(t *testing.T) {
162
169
t .Errorf ("Batches %v\n " , te .sizes )
163
170
}
164
171
165
- // Check first Span is reported. Most recent one is dropped.
166
- sc := getSpanContext ()
167
- wantTraceID := sc .TraceID
168
- binary .BigEndian .PutUint64 (wantTraceID [0 :8 ], uint64 (1 ))
169
- gotTraceID := te .get (0 ).SpanContext .TraceID
170
- if wantTraceID != gotTraceID {
171
- t .Errorf ("%s: first exported span: got %+v, want %+v\n " , option .name , gotTraceID , wantTraceID )
172
- }
173
172
tp .UnregisterSpanProcessor (ssp )
174
173
}
175
174
}
@@ -182,15 +181,26 @@ func createAndRegisterBatchSP(t *testing.T, option testOption, te *testBatchExpo
182
181
return ssp
183
182
}
184
183
185
- func generateSpan (t * testing.T , tr apitrace.Tracer , option testOption ) {
184
+ func generateSpan (t * testing.T , parallel bool , tr apitrace.Tracer , option testOption ) {
186
185
sc := getSpanContext ()
187
186
187
+ wg := & sync.WaitGroup {}
188
188
for i := 0 ; i < option .genNumSpans ; i ++ {
189
189
binary .BigEndian .PutUint64 (sc .TraceID [0 :8 ], uint64 (i + 1 ))
190
- ctx := apitrace .ContextWithRemoteSpanContext (context .Background (), sc )
191
- _ , span := tr .Start (ctx , option .name )
192
- span .End ()
190
+ wg .Add (1 )
191
+ f := func (sc core.SpanContext ) {
192
+ ctx := apitrace .ContextWithRemoteSpanContext (context .Background (), sc )
193
+ _ , span := tr .Start (ctx , option .name )
194
+ span .End ()
195
+ wg .Done ()
196
+ }
197
+ if parallel {
198
+ go f (sc )
199
+ } else {
200
+ f (sc )
201
+ }
193
202
}
203
+ wg .Wait ()
194
204
}
195
205
196
206
func getSpanContext () core.SpanContext {
0 commit comments