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

Function TestDequeuesExpiredRequests

pkg/frontend/v1/queue_test.go:51–90  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

49}
50
51func TestDequeuesExpiredRequests(t *testing.T) {
52 var config Config
53 flagext.DefaultValues(&config)
54 userID := "1"
55
56 f, err := setupFrontend(t, 10, config)
57 require.NoError(t, err)
58
59 ctx := user.InjectOrgID(context.Background(), userID)
60 expired, cancel := context.WithCancel(ctx)
61 cancel()
62
63 good := 0
64 for i := range 10 {
65 var err error
66 if i%5 == 0 {
67 good++
68 err = f.queueRequest(ctx, testReq(ctx, fmt.Sprintf("good-%d", i), userID))
69 } else {
70 err = f.queueRequest(ctx, testReq(expired, fmt.Sprintf("expired-%d", i), userID))
71 }
72
73 require.Nil(t, err)
74 }
75
76 // Calling Process will only return when client disconnects or context is finished.
77 // We use context timeout to stop Process call.
78 ctx2, cancel2 := context.WithTimeout(context.Background(), 1*time.Second)
79 defer cancel2()
80
81 m := &processServerMock{ctx: ctx2, querierID: "querier"}
82 err = f.Process(m)
83 require.EqualError(t, err, context.DeadlineExceeded.Error())
84
85 // Verify that only non-expired requests were forwarded to querier.
86 for _, r := range m.requests {
87 require.True(t, strings.HasPrefix(r.Url, "good-"), r.Url)
88 }
89 require.Len(t, m.requests, good)
90}
91
92func TestRoundRobinQueues(t *testing.T) {
93 var config Config

Callers

nothing calls this directly

Calls 7

DefaultValuesFunction · 0.92
testReqFunction · 0.85
queueRequestMethod · 0.80
setupFrontendFunction · 0.70
ProcessMethod · 0.65
ErrorMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected