8000 API tests: fix flaky TestEndpoints · rnadupal/prometheus@25f200b · GitHub
[go: up one dir, main page]

Skip to content

Commit 25f200b

Browse files
committed
API tests: fix flaky TestEndpoints
When a limit is specified, the API may return arbitrary rows, so don't check specific response values. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
1 parent e6b7bbc commit 25f200b

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

web/api/v1/api_test.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
10541054
params map[string]string
10551055
query url.Values
10561056
response interface{}
1057-
responseLen int
1057+
responseLen int // If nonzero, check only the length; `response` is ignored.
10581058
responseMetadataTotal int
10591059
responseAsJSON string
10601060
errType errorType
@@ -1388,17 +1388,16 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
13881388
labels.FromStrings("__name__", "test_metric2", "foo", "boo"),
13891389
},
13901390
},
1391-
// Missing match[] query params in series requests.
1391+
// Series request with limit.
13921392
{
13931393
endpoint: api.series,
13941394
query: url.Values{
13951395
"match[]": []string{"test_metric1"},
13961396
"limit": []string{"1"},
13971397
},
1398-
response: []labels.Labels{
1399-
labels.FromStrings("__name__", "test_metric1", "foo", "bar"),
1400-
},
1398+
responseLen: 1, // API does not specify which particular value will come back.
14011399
},
1400+
// Missing match[] query params in series requests.
14021401
{
14031402
endpoint: api.series,
14041403
errType: errorBadData,
@@ -2670,18 +2669,16 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
26702669
"boo",
26712670
},
26722671
},
2672+
// Label values with limit.
26732673
{
26742674
endpoint: api.labelValues,
26752675
params: map[string]string{
2676-
"name": "foo",
2676+
"name": "__name__",
26772677
},
26782678
query: url.Values{
2679-
"match[]": []string{"test_metric4"},
2680-
"limit": []string{"1"},
2681-
},
2682-
response: []string{
2683-
"bar",
2679+
"limit": []string{"2"},
26842680
},
2681+
responseLen: 2, // API does not specify which particular values will come back.
26852682
},
26862683
// Label names.
26872684
{
@@ -2822,13 +2819,13 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
28222819
},
28232820
response: []string{"__name__", "foo"},
28242821
},
2822+
// Label names with limit.
28252823
{
28262824
endpoint: api.labelNames,
28272825
query: url.Values{
2828-
"match[]": []string{"test_metric2"},
2829-
"limit": []string{"1"},
2826+
"limit": []string{"2"},
28302827
},
2831-
response: []string{"__name__"},
2828+
responseLen: 2, // API does not specify which particular values will come back.
28322829
},
28332830
}...)
28342831
}

0 commit comments

Comments
 (0)
0