| 308 | } |
| 309 | |
| 310 | func TestPoolConcurrentAcquireRelease(t *testing.T) { |
| 311 | p, err := newPool(4) |
| 312 | if err != nil { |
| 313 | t.Fatalf("newPool failed: %v", err) |
| 314 | } |
| 315 | defer p.close() |
| 316 | |
| 317 | var wg sync.WaitGroup |
| 318 | var acquired atomic.Int32 |
| 319 | |
| 320 | for i := 0; i < 20; i++ { |
| 321 | wg.Add(1) |
| 322 | go func() { |
| 323 | defer wg.Done() |
| 324 | w := p.acquire(100 * time.Millisecond) |
| 325 | if w == nil { |
| 326 | return |
| 327 | } |
| 328 | acquired.Add(1) |
| 329 | time.Sleep(5 * time.Millisecond) // simulate work |
| 330 | p.release(w, false) |
| 331 | }() |
| 332 | } |
| 333 | |
| 334 | wg.Wait() |
| 335 | if acquired.Load() == 0 { |
| 336 | t.Error("no workers were ever acquired") |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | func TestQueryWorkingSetCurrentProcess(t *testing.T) { |
| 341 | // allocate a page so we have a known committed address to query |