TestConcurrentEncoding verifies thread-safety of buffer pooling
(t *testing.T)
| 111 | |
| 112 | // TestConcurrentEncoding verifies thread-safety of buffer pooling |
| 113 | func TestConcurrentEncoding(t *testing.T) { |
| 114 | type payload struct { |
| 115 | ID int `json:"id"` |
| 116 | Value string `json:"value"` |
| 117 | } |
| 118 | |
| 119 | var wg sync.WaitGroup |
| 120 | concurrency := 50 |
| 121 | |
| 122 | for i := 0; i < concurrency; i++ { |
| 123 | wg.Add(1) |
| 124 | go func(id int) { |
| 125 | defer wg.Done() |
| 126 | |
| 127 | p := payload{ |
| 128 | ID: id, |
| 129 | Value: "test value", |
| 130 | } |
| 131 | |
| 132 | result, err := EncodeMsgPack(p) |
| 133 | if err != nil { |
| 134 | t.Errorf("EncodeMsgPack() failed for ID %d: %v", id, err) |
| 135 | return |
| 136 | } |
| 137 | |
| 138 | if len(result) == 0 { |
| 139 | t.Errorf("EncodeMsgPack() returned empty result for ID %d", id) |
| 140 | } |
| 141 | }(i) |
| 142 | } |
| 143 | |
| 144 | wg.Wait() |
| 145 | } |
| 146 | |
| 147 | // BenchmarkEncodeMsgPack benchmarks encoding performance |
| 148 | func BenchmarkEncodeMsgPack(b *testing.B) { |
nothing calls this directly
no test coverage detected