mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
58 lines
2.1 KiB
Go
58 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"github.com/seaweedfs/seaweed-block/core/rpc/control"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestRestartedRecordedRevocationExitsFinalOnce(t *testing.T) {
|
|
if os.Getenv("SWB_RECORDED_REVOKE_CHILD") == "1" {
|
|
refusal, e := status.New(codes.FailedPrecondition, "volume was moved or revoked; inspect workspace state and complete the intended move; leave this unit stopped").WithDetails(&control.WorkspaceLeaseRefusal{Kind: control.WorkspaceLeaseRefusal_FINAL})
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
h, send := exitAuthorityHost(t, func(s *exitAssignmentStream) { s.refuse = refusal.Err() })
|
|
send("r", 1)
|
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
|
defer cancel()
|
|
startWorkspaceLease(ctx, h) // the restarted holder receives FINAL on renewal
|
|
for {
|
|
if _, final := h.MasterWaitState(); final != "" {
|
|
break
|
|
}
|
|
select {
|
|
case <-ctx.Done():
|
|
t.Fatal("typed final renewal never ended the startup wait")
|
|
case <-time.After(time.Millisecond):
|
|
}
|
|
}
|
|
code := superviseProcess(ctx, func(e *processExit) int {
|
|
if !chooseChunkStartupExit(e, flags{workspaceLease: true, durableImpl: "walstore-chunk", volumeID: "v"}, h, &exitStartupOutcome{expired: true}) {
|
|
t.Fatal("no final decision")
|
|
}
|
|
e.choose(workspaceExit{code: 75, reason: "later retry must lose"})
|
|
return 0
|
|
})
|
|
os.Exit(code)
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
cmd := exec.CommandContext(ctx, os.Args[0], "-test.run=^TestRestartedRecordedRevocationExitsFinalOnce$", "-test.count=1")
|
|
cmd.Env = append(os.Environ(), "SWB_RECORDED_REVOKE_CHILD=1")
|
|
out, e := cmd.CombinedOutput()
|
|
exit, ok := e.(*exec.ExitError)
|
|
if !ok || exit.ExitCode() != 79 || strings.Count(string(out), "exiting status=79 reason=revoked") != 1 {
|
|
t.Fatalf("restarted revoked holder: %v output=%s; want one final exit 79", e, out)
|
|
}
|
|
if strings.Contains(string(out), "exiting status=75") {
|
|
t.Fatalf("restart loop outcome: %s", out)
|
|
}
|
|
}
|