Test max query length limit works with new validateQueryTimeRange function.
(t *testing.T)
| 1258 | |
| 1259 | // Test max query length limit works with new validateQueryTimeRange function. |
| 1260 | func TestValidateMaxQueryLength(t *testing.T) { |
| 1261 | t.Parallel() |
| 1262 | ctx := context.Background() |
| 1263 | now := time.Now() |
| 1264 | for _, tc := range []struct { |
| 1265 | name string |
| 1266 | start time.Time |
| 1267 | end time.Time |
| 1268 | expectedStartMs int64 |
| 1269 | expectedEndMs int64 |
| 1270 | maxQueryLength time.Duration |
| 1271 | exceedQueryLength bool |
| 1272 | }{ |
| 1273 | { |
| 1274 | name: "normal params, not hit max query length", |
| 1275 | start: now.Add(-time.Hour), |
| 1276 | end: now, |
| 1277 | expectedStartMs: util.TimeToMillis(now.Add(-time.Hour)), |
| 1278 | expectedEndMs: util.TimeToMillis(now), |
| 1279 | maxQueryLength: 24 * time.Hour, |
| 1280 | exceedQueryLength: false, |
| 1281 | }, |
| 1282 | { |
| 1283 | name: "normal params, hit max query length", |
| 1284 | start: now.Add(-100 * time.Hour), |
| 1285 | end: now, |
| 1286 | expectedStartMs: util.TimeToMillis(now.Add(-100 * time.Hour)), |
| 1287 | expectedEndMs: util.TimeToMillis(now), |
| 1288 | maxQueryLength: 24 * time.Hour, |
| 1289 | exceedQueryLength: true, |
| 1290 | }, |
| 1291 | { |
| 1292 | name: "negative start", |
| 1293 | start: time.Unix(-1000, 0), |
| 1294 | end: now, |
| 1295 | expectedStartMs: 0, |
| 1296 | expectedEndMs: util.TimeToMillis(now), |
| 1297 | maxQueryLength: 24 * time.Hour, |
| 1298 | exceedQueryLength: true, |
| 1299 | }, |
| 1300 | } { |
| 1301 | t.Run(tc.name, func(t *testing.T) { |
| 1302 | //parallel testing causes data race |
| 1303 | limits := DefaultLimitsConfig() |
| 1304 | overrides := validation.NewOverrides(limits, nil) |
| 1305 | startMs, endMs, err := validateQueryTimeRange(ctx, "test", util.TimeToMillis(tc.start), util.TimeToMillis(tc.end), overrides, 0) |
| 1306 | require.NoError(t, err) |
| 1307 | startTime := model.Time(startMs) |
| 1308 | endTime := model.Time(endMs) |
| 1309 | if tc.maxQueryLength > 0 { |
| 1310 | require.Equal(t, tc.exceedQueryLength, endTime.Sub(startTime) > tc.maxQueryLength) |
| 1311 | } |
| 1312 | }) |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | // mockDistibutorFor duplicates the chunks in the mockChunkStore into the mockDistributor |
| 1317 | // so we can test everything is dedupe correctly. |
nothing calls this directly
no test coverage detected