Skip to content

Commit 0321279

Browse files
authored
add test for stats_handler (#2)
1 parent 1c4d2ec commit 0321279

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package otelgrpc
2+
3+
import (
4+
"context"
5+
"sync"
6+
"testing"
7+
8+
"google.golang.org/grpc/stats"
9+
)
10+
11+
func TestHandleRPC(t *testing.T) {
12+
const iteration = 100
13+
wg := &sync.WaitGroup{}
14+
ctx := context.Background()
15+
h := NewClientHandler()
16+
ctx = h.TagRPC(ctx, &stats.RPCTagInfo{
17+
FullMethodName: "test/method",
18+
})
19+
for i := 0; i < iteration; i++ {
20+
wg.Add(1)
21+
go func() {
22+
defer wg.Done()
23+
h.HandleRPC(ctx, &stats.Begin{})
24+
wg.Add(3)
25+
go func() {
26+
defer wg.Done()
27+
h.HandleRPC(ctx, &stats.InPayload{})
28+
}()
29+
go func() {
30+
defer wg.Done()
31+
h.HandleRPC(ctx, &stats.OutPayload{})
32+
}()
33+
go func() {
34+
defer wg.Done()
35+
h.HandleRPC(ctx, &stats.End{})
36+
}()
37+
}()
38+
}
39+
wg.Wait()
40+
}

0 commit comments

Comments
 (0)