@@ -6,6 +6,7 @@ package processorhelper
6
6
import (
7
7
"context"
8
8
"errors"
9
+ "sync"
9
10
"testing"
10
11
11
12
"github.com/stretchr/testify/assert"
@@ -70,6 +71,38 @@ func newTestTProcessor(retError error) ProcessTracesFunc {
70
71
}
71
72
}
72
73
74
+ func TestTracesConcurrency (t * testing.T ) {
75
+ tracesFunc := func (_ context.Context , td ptrace.Traces ) (ptrace.Traces , error ) {
76
+ return td , nil
77
+ }
78
+
79
+ incomingTraces := ptrace .NewTraces ()
80
+ incomingSpans := incomingTraces .ResourceSpans ().AppendEmpty ().ScopeSpans ().AppendEmpty ().Spans ()
81
+
82
+ // Add 4 records to the incoming
83
+ incomingSpans .AppendEmpty ()
84
+ incomingSpans .AppendEmpty ()
85
+ incomingSpans .AppendEmpty ()
86
+ incomingSpans .AppendEmpty ()
87
+
88
+ mp , err := NewTraces (context .Background (), processortest .NewNopSettings (), & testLogsCfg , consumertest .NewNop (), tracesFunc )
89
+ require .NoError (t , err )
90
+ assert .NoError (t , mp .Start (context .Background (), componenttest .NewNopHost ()))
91
+
92
+ var wg sync.WaitGroup
93
+ for i := 0 ; i < 10 ; i ++ {
94
+ wg .Add (1 )
95
+ go func () {
96
+ defer wg .Done ()
97
+ for j := 0 ; j < 10000 ; j ++ {
98
+ assert .NoError (t , mp .ConsumeTraces (context .Background (), incomingTraces ))
99
+ }
100
+ }()
101
+ }
102
+ wg .Wait ()
103
+ assert .NoError (t , mp .Shutdown (context .Background ()))
104
+ }
105
+
73
106
func TestTraces_RecordInOut (t * testing.T ) {
74
107
// Regardless of how many spans are ingested, emit just one
75
108
mockAggregate := func (_ context.Context , _ ptrace.Traces ) (ptrace.Traces , error ) {
0 commit comments