| 214 | } |
| 215 | |
| 216 | func 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 | |
| 260 | func TestHandleStore_ZeroValues(t *testing.T) { |
| 261 | hs := newHandleStore() |