From db9d8703ef0446fd515818ddac97b523043a674b Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Sat, 4 Jul 2026 00:40:00 +0100 Subject: [PATCH] Fix flaky TestPublic_FindCommentsCtrl_ConsistentCount The test decided the expected HTTP status with strings.Contains(tc.params, "=bad"), but comment IDs are random UUIDs. When one started with "bad" (e.g. offset_id=bad49e60-...), the param string contained "=bad" and the case was wrongly expected to return 400 while the handler correctly returned 200, failing the run about 0.2% of the time. Identify bad-request cases by their error response body instead, which is deterministic per case and independent of the generated IDs. --- backend/app/rest/api/rest_public_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/app/rest/api/rest_public_test.go b/backend/app/rest/api/rest_public_test.go index 979d1c58..a583a8e9 100644 --- a/backend/app/rest/api/rest_public_test.go +++ b/backend/app/rest/api/rest_public_test.go @@ -771,8 +771,12 @@ func TestPublic_FindCommentsCtrl_ConsistentCount(t *testing.T) { t.Run(tc.params, func(t *testing.T) { url := fmt.Sprintf(ts.URL+"/api/v1/find?site=remark42&%s", tc.params) body, code := get(t, url) + // bad-request cases are identified by their error response body rather than + // a "=bad" substring of the params: comment IDs are random UUIDs and one + // starting with "bad" (e.g. offset_id=bad49e60-...) would otherwise be + // misread as a bad request, making this test flaky. expectedStatus := http.StatusOK - if strings.Contains(tc.params, "=bad") { + if strings.Contains(tc.expectedBody, `"error":`) { expectedStatus = http.StatusBadRequest } assert.Equal(t, expectedStatus, code)