From 3d79293218836be28c5628e913b22b7f1484d35d Mon Sep 17 00:00:00 2001 From: Lemon-miaow Date: Fri, 25 Sep 2026 10:48:51 +0800 Subject: [PATCH] =?UTF-8?q?test(imagepush):=20=E5=BC=80=E5=8F=AA=E8=AF=BB?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E9=81=87=20409=20=E6=97=B6=E5=83=8F=20GC=20J?= =?UTF-8?q?ob=20=E4=B8=80=E6=A0=B7=E9=87=8D=E8=AF=95=EF=BC=8C=E6=B6=88?= =?UTF-8?q?=E9=99=A4=20-race=20=E4=B8=8B=E7=9A=84=E5=81=B6=E5=8F=91?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/imagepush/push_test.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/internal/imagepush/push_test.go b/internal/imagepush/push_test.go index 0cd1a96..5a9e486 100644 --- a/internal/imagepush/push_test.go +++ b/internal/imagepush/push_test.go @@ -207,19 +207,31 @@ func TestPushWaitsOutTheGCWindow(t *testing.T) { maint := httptest.NewServer(g.MaintHandler()) t.Cleanup(maint.Close) host := strings.TrimPrefix(gate.URL, "http://") + // The gate counts a write as finished only after its handler returns, which + // is just after the client already has the response, so a window opened + // right behind the last push can see it in flight for a moment and answer + // 409. The registry GC Job retries until it gets 200 (platform/workloads.go); so + // does this helper. setReadOnly := func(on bool) { t.Helper() path := "/readwrite" if on { path = "/readonly?lease=600" } - resp, err := http.Post(maint.URL+path, "text/plain", nil) - if err != nil { - t.Fatal(err) - } - resp.Body.Close() - if resp.StatusCode != http.StatusOK { - t.Fatalf("POST %s = %d", path, resp.StatusCode) + deadline := time.Now().Add(5 * time.Second) + for { + resp, err := http.Post(maint.URL+path, "text/plain", nil) + if err != nil { + t.Fatal(err) + } + resp.Body.Close() + if resp.StatusCode == http.StatusOK { + return + } + if !on || resp.StatusCode != http.StatusConflict || time.Now().After(deadline) { + t.Fatalf("POST %s = %d", path, resp.StatusCode) + } + time.Sleep(10 * time.Millisecond) } }