MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestQueueConcurrency

Function TestQueueConcurrency

pkg/scheduler/queue/user_queues_test.go:461–492  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

459}
460
461func 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
494func generateTenant(r *rand.Rand) string {
495 return fmt.Sprint("tenant-", r.Int()%5)

Callers

nothing calls this directly

Calls 10

newUserQueuesFunction · 0.85
addQuerierConnectionMethod · 0.80
DoneMethod · 0.80
getOrAddQueueMethod · 0.80
deleteQueueMethod · 0.80
enqueueRequestMethod · 0.65
dequeueRequestMethod · 0.65
AddMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected