MCPcopy Create free account
hub / github.com/frain-dev/convoy / TestConcurrentEncoding

Function TestConcurrentEncoding

pkg/msgpack/msgpack_test.go:113–145  ·  view source on GitHub ↗

TestConcurrentEncoding verifies thread-safety of buffer pooling

(t *testing.T)

Source from the content-addressed store, hash-verified

111
112// TestConcurrentEncoding verifies thread-safety of buffer pooling
113func 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
148func BenchmarkEncodeMsgPack(b *testing.B) {

Callers

nothing calls this directly

Calls 3

EncodeMsgPackFunction · 0.85
ErrorfMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected