MCPcopy Create free account
hub / github.com/buke/quickjs-go / TestHandleStore_Concurrency

Function TestHandleStore_Concurrency

handle_test.go:216–258  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

214}
215
216func TestHandleStore_Concurrency(t *testing.T) {
217 hs := newHandleStore()
218 const numGoroutines = 10
219 const numOpsPerGoroutine = 100
220
221 var wg sync.WaitGroup
222 var successCount int64
223
224 // Test concurrent operations
225 for i := 0; i < numGoroutines; i++ {
226 wg.Add(1)
227 go func(goroutineID int) {
228 defer wg.Done()
229
230 // Each goroutine does store/load/delete operations
231 for j := 0; j < numOpsPerGoroutine; j++ {
232 value := goroutineID*1000 + j
233
234 // Store
235 id := hs.Store(value)
236
237 // Load and verify
238 loadedValue, ok := hs.Load(id)
239 if ok && loadedValue == value {
240 atomic.AddInt64(&successCount, 1)
241 }
242
243 // Delete
244 hs.Delete(id)
245 }
246 }(i)
247 }
248
249 wg.Wait()
250
251 // Verify all operations succeeded
252 expectedSuccesses := int64(numGoroutines * numOpsPerGoroutine)
253 assert.Equal(t, expectedSuccesses, successCount)
254
255 // Final cleanup
256 hs.Clear()
257 assert.Equal(t, 0, hs.Count())
258}
259
260func TestHandleStore_ZeroValues(t *testing.T) {
261 hs := newHandleStore()

Callers

nothing calls this directly

Calls 7

newHandleStoreFunction · 0.85
StoreMethod · 0.80
LoadMethod · 0.80
EqualMethod · 0.80
ClearMethod · 0.80
CountMethod · 0.80
DeleteMethod · 0.45

Tested by

no test coverage detected