Try to catch possible race conditions around use of pools
(t *testing.T)
| 61 | |
| 62 | // Try to catch possible race conditions around use of pools |
| 63 | func (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. |
nothing calls this directly
no test coverage detected