Skip to content

Commit 5fa60ba

Browse files
itizirrahul2393
andauthored
test(spanner): fix race when accessing trace spans (#10186)
* test(spanner): fix race when accessing trace spans * fix go vet * fix build * return span data itself * fix go vet * fix vet * revert changes * revert other module changes, they will be done after cloud.google.com/go release --------- Co-authored-by: rahul2393 <irahul@google.com> Co-authored-by: rahul yadav <rahulyadavsep92@gmail.com>
1 parent b19dd34 commit 5fa60ba

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

internal/testutil/trace.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
// TestExporter is a test utility exporter. It should be created with NewtestExporter.
2828
type TestExporter struct {
2929
mu sync.Mutex
30-
Spans []*trace.SpanData
30+
spans []*trace.SpanData
3131

3232
Stats chan *view.Data
3333
Views []*view.View
@@ -56,7 +56,16 @@ func NewTestExporter(views ...*view.View) *TestExporter {
5656
func (te *TestExporter) ExportSpan(s *trace.SpanData) {
5757
te.mu.Lock()
5858
defer te.mu.Unlock()
59-
te.Spans = append(te.Spans, s)
59+
te.spans = append(te.spans, s)
60+
}
61+
62+
// Spans returns the exported spans.
63+
func (te *TestExporter) Spans() []*trace.SpanData {
64+
te.mu.Lock()
65+
defer te.mu.Unlock()
66+
spans := make([]*trace.SpanData, len(te.spans))
67+
copy(spans, te.spans)
68+
return spans
6069
}
6170

6271
// ExportView exports a view.

internal/trace/trace_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestStartSpan_OpenCensus(t *testing.T) {
6363
if IsOpenTelemetryTracingEnabled() {
6464
t.Errorf("got true, want false")
6565
}
66-
spans := te.Spans
66+
spans := te.Spans()
6767
if len(spans) != 1 {
6868
t.Fatalf("got %d, want 1", len(spans))
6969
}

0 commit comments

Comments
 (0)