(t *testing.T)
| 49 | } |
| 50 | |
| 51 | func 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 | |
| 92 | func TestRoundRobinQueues(t *testing.T) { |
| 93 | var config Config |
nothing calls this directly
no test coverage detected