MCPcopy
hub / github.com/grpc/grpc-go / TestConcurrentUsage

Method TestConcurrentUsage

encoding/proto/proto_test.go:63–92  ·  view source on GitHub ↗

Try to catch possible race conditions around use of pools

(t *testing.T)

Source from the content-addressed store, hash-verified

61
62// Try to catch possible race conditions around use of pools
63func (s) TestConcurrentUsage(t *testing.T) {
64 const (
65 numGoRoutines = 100
66 numMarshUnmarsh = 1000
67 )
68
69 // small, arbitrary byte slices
70 protoBodies := [][]byte{
71 []byte("one"),
72 []byte("two"),
73 []byte("three"),
74 []byte("four"),
75 []byte("five"),
76 }
77
78 var wg sync.WaitGroup
79 codec := &codecV2{}
80
81 for i := 0; i < numGoRoutines; i++ {
82 wg.Add(1)
83 go func() {
84 defer wg.Done()
85 for k := 0; k < numMarshUnmarsh; k++ {
86 marshalAndUnmarshal(t, codec, protoBodies[k%len(protoBodies)])
87 }
88 }()
89 }
90
91 wg.Wait()
92}
93
94// TestStaggeredMarshalAndUnmarshalUsingSamePool tries to catch potential errors in which slices get
95// stomped on during reuse of a proto.Buffer.

Callers

nothing calls this directly

Calls 4

marshalAndUnmarshalFunction · 0.85
WaitMethod · 0.80
AddMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected