mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
Brings seaweed-block main (v1.1.1 plus the docs and a test fix after it) into seaweed-block/ as one commit. Only files under seaweed-block/ change, and the subtree equals seaweed-block main exactly. The module's full history stays in the seaweed-block repository. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
4.2 KiB
Go
94 lines
4.2 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
"testing/synctest"
|
|
"time"
|
|
)
|
|
|
|
// M5 PlainStop -> Quiesce, INV-CUT-PLAIN-DETACH-001: encode the existing
|
|
// idle seal request; preserve JSON stdout for existing operator tooling.
|
|
func TestOpsChunkPlainDetachSendsTheExistingRequest(t *testing.T) {
|
|
const reply = `{"apiVersion":1,"volumeID":"vol","headGen":11}`
|
|
srv, got := chunkServer(t, http.StatusOK, reply)
|
|
code, out, errOut := runChunk("detach", "--plain", "--volume", "vol", "--status-addr", srv.URL, "--timeout", "2s")
|
|
if code != 0 || out != reply || !strings.Contains(errOut, "sealed HEAD generation: 11\n") {
|
|
t.Fatalf("exit=%d stdout=%q stderr=%q", code, out, errOut)
|
|
}
|
|
if len(*got) != 1 || (*got)[0].path != "/chunk/detach" || (*got)[0].body["plain"] != true || (*got)[0].body["volumeID"] != "vol" || (*got)[0].body["timeoutMs"] != float64(2000) {
|
|
t.Fatalf("plain request=%+v", *got)
|
|
}
|
|
for _, key := range []string{"frozen", "freezeStartedAtNs", "allowOverBudget"} {
|
|
if _, ok := (*got)[0].body[key]; ok {
|
|
t.Fatalf("plain request contains %s", key)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestOpsChunkPlainDetachRefusesInvalidMixBeforeHTTP(t *testing.T) {
|
|
srv, got := chunkServer(t, http.StatusOK, `{}`)
|
|
for _, extra := range [][]string{
|
|
{"--frozen", "--freeze-started-at-ns", "1"}, {"--freeze-started-at-ns", "1"}, {"--allow-over-budget"},
|
|
{"--timeout", "0s"}, {"--timeout", "-1s"}, {"unexpected"},
|
|
} {
|
|
args := append([]string{"detach", "--plain", "--volume", "vol", "--status-addr", srv.URL}, extra...)
|
|
if code, _, _ := runChunk(args...); code != 2 || len(*got) != 0 {
|
|
t.Fatalf("%v: exit=%d requests=%d", extra, code, len(*got))
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestOpsChunkPlainDetachPreservesTypedFailure(t *testing.T) {
|
|
for _, reason := range []string{"busy", "fenced", "outcome_unknown"} {
|
|
t.Run(reason, func(t *testing.T) {
|
|
reply := `{"apiVersion":1,"code":"` + reason + `","message":"seal refused","retryable":true}`
|
|
srv, got := chunkServer(t, http.StatusConflict, reply)
|
|
code, out, errOut := runChunk("detach", "--plain", "--volume", "vol", "--status-addr", srv.URL)
|
|
if code != 1 || out != reply || len(*got) != 1 || strings.Contains(errOut, "sealed HEAD generation:") {
|
|
t.Fatalf("exit=%d stdout=%q stderr=%q requests=%d", code, out, errOut, len(*got))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// An observed plain detach whose handle the holder ends outcome_unknown is
|
|
// reported unknown (exit 3) at once: one admission, one read, no re-POST.
|
|
func TestOpsChunkPlainDetachHandleEndedUnknownIsReportedAtOnce(t *testing.T) {
|
|
synctest.Test(t, func(t *testing.T) {
|
|
start, posts, polls := time.Now(), 0, 0
|
|
installCutPollTransport(t, func(r *http.Request) (*http.Response, error) {
|
|
if r.Method == http.MethodPost {
|
|
posts++
|
|
return cutPollReply(202, `{"apiVersion":1,"code":"in_progress","cutID":"d1","sequence":1}`), nil
|
|
}
|
|
polls++
|
|
return cutPollReply(503, `{"apiVersion":1,"code":"outcome_unknown","cutID":"d1","message":"publish answer lost","retryable":true}`), nil
|
|
})
|
|
code, out, _ := runChunk("detach", "--plain", "--volume", "v1", "--status-addr", "http://holder", "--timeout", "1m")
|
|
if code != 3 || posts != 1 || polls != 1 || !strings.Contains(out, `"code":"outcome_unknown"`) || time.Since(start) >= time.Minute {
|
|
t.Fatalf("code=%d posts=%d polls=%d elapsed=%s out=%s", code, posts, polls, time.Since(start), out)
|
|
}
|
|
})
|
|
}
|
|
|
|
// A first answer that already carries the detach's id with a terminal
|
|
// outcome_unknown (the admitted worker ended unknown within the window) is
|
|
// unknown (exit 3), never a definite refusal, with one POST.
|
|
func TestOpsChunkPlainDetachFirstAnswerUnknownWithItsIDIsUnknown(t *testing.T) {
|
|
synctest.Test(t, func(t *testing.T) {
|
|
posts := 0
|
|
installCutPollTransport(t, func(r *http.Request) (*http.Response, error) {
|
|
if r.Method == http.MethodPost {
|
|
posts++
|
|
}
|
|
return cutPollReply(503, `{"apiVersion":1,"code":"outcome_unknown","cutID":"d1","message":"publish answer lost","retryable":true}`), nil
|
|
})
|
|
code, out, _ := runChunk("detach", "--plain", "--volume", "v1", "--status-addr", "http://holder", "--timeout", "1m")
|
|
if code != 3 || posts != 1 || !strings.Contains(out, `"code":"outcome_unknown"`) {
|
|
t.Fatalf("code=%d posts=%d out=%s, want unknown after one POST", code, posts, out)
|
|
}
|
|
})
|
|
}
|