(t *testing.T)
| 459 | } |
| 460 | |
| 461 | func TestQueueConcurrency(t *testing.T) { |
| 462 | const numGoRoutines = 30 |
| 463 | limits := MockLimits{ |
| 464 | MaxOutstanding: 50, |
| 465 | } |
| 466 | q := newUserQueues(0, limits, nil) |
| 467 | q.addQuerierConnection("q-1") |
| 468 | q.addQuerierConnection("q-2") |
| 469 | q.addQuerierConnection("q-3") |
| 470 | q.addQuerierConnection("q-4") |
| 471 | q.addQuerierConnection("q-5") |
| 472 | |
| 473 | var wg sync.WaitGroup |
| 474 | wg.Add(numGoRoutines) |
| 475 | |
| 476 | for i := range numGoRoutines { |
| 477 | go func(cnt int) { |
| 478 | defer wg.Done() |
| 479 | queue := q.getOrAddQueue("userID", 2) |
| 480 | if cnt%2 == 0 { |
| 481 | queue.enqueueRequest(MockRequest{}) |
| 482 | q.getNextQueueForQuerier(0, "q-1") |
| 483 | } else if cnt%5 == 0 { |
| 484 | queue.dequeueRequest(0, false) |
| 485 | } else if cnt%7 == 0 { |
| 486 | q.deleteQueue("userID") |
| 487 | } |
| 488 | }(i) |
| 489 | } |
| 490 | |
| 491 | wg.Wait() |
| 492 | } |
| 493 | |
| 494 | func generateTenant(r *rand.Rand) string { |
| 495 | return fmt.Sprint("tenant-", r.Int()%5) |
nothing calls this directly
no test coverage detected