test(imagepush): 开只读窗口遇 409 时像 GC Job 一样重试,消除 -race 下的偶发失败

This commit is contained in:
Lemon-miaow committed 2026-09-25 10:48:51 +08:00
1 parent 2f99874d5e
commit 3d79293218
1 file changed
+13 -1
+13 -1
View File
@@ -207,20 +207,32 @@ 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"
}
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 {
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)
}
}
ref := host + "/user-uploads/sub-gc:latest"