Skip to content

Commit

Permalink
atomic operation on shared var
Browse files Browse the repository at this point in the history
Signed-off-by: chahatsagarmain <[email protected]>
  • Loading branch information
chahatsagarmain committed Jan 18, 2025
1 parent bcc716a commit e1d95b2
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions cmd/collector/app/span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,13 +848,11 @@ func TestOTLPReceiverWithV2Storage(t *testing.T) {
span := sSpans.Spans().AppendEmpty()
span.SetName("test-trace")

var receivedTraces ptrace.Traces
var mu sync.Mutex
receivedTraces := atomic.Pointer[ptrace.Traces]{}
mockWriter.On("WriteTraces", mock.Anything, mock.Anything).
Run(func(args mock.Arguments) {
mu.Lock()
receivedTraces = args.Get(1).(ptrace.Traces)
mu.Unlock()
storeTrace := args.Get(1).(ptrace.Traces)
receivedTraces.Store(&storeTrace)
}).Return(nil)

spanProcessor, err := NewSpanProcessor(
Expand Down Expand Up @@ -908,12 +906,10 @@ func TestOTLPReceiverWithV2Storage(t *testing.T) {

time.Sleep(100 * time.Millisecond)

mu.Lock()
receivedSpan := receivedTraces.ResourceSpans().At(0).
receivedSpan := receivedTraces.Load().ResourceSpans().At(0).
ScopeSpans().At(0).
Spans().At(0)
require.Equal(t, span.Name(), receivedSpan.Name())
mu.Unlock()

mockWriter.AssertExpectations(t)
}

0 comments on commit e1d95b2

Please sign in to comment.