test: a typed moved/deleted refusal gives 78 with its reason; none stays 75

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-23 22:43:55 -08:00
1 parent e56fe3b9b8
commit f77a75c58e
1 file changed
+67
@@ -10,6 +10,8 @@ import (
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
"github.com/seaweedfs/seaweed-block/core/storage"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"net"
"sync/atomic"
"testing"
@@ -21,12 +23,16 @@ type exitAssignmentStream struct {
control.UnimplementedObservationServiceServer
control.UnimplementedWorkspaceServiceServer
revoke bool
refuse error // when set, every renewal is refused with it
ackError error
acks atomic.Int32
facts chan *control.AssignmentFact
}
func (s *exitAssignmentStream) RenewWorkspaceLease(_ context.Context, id *control.WorkspaceIdentity) (*control.WorkspaceLeaseFact, error) {
if s.refuse != nil {
return nil, s.refuse
}
return &control.WorkspaceLeaseFact{VolumeId: id.VolumeId, ReplicaId: id.ReplicaId, Epoch: id.Epoch, ValidForNs: int64(30 * time.Second), Revoking: s.revoke}, nil
}
func (s *exitAssignmentStream) AckWorkspaceRevoked(_ context.Context, a *control.WorkspaceRevocationAck) (*control.WorkspaceEmpty, error) {
@@ -490,3 +496,64 @@ func TestWorkspaceDisplacedClaimUsesAssignedEpoch(t *testing.T) {
})
}
}
// A typed MOVED or DELETED renewal refusal, seen by the real host's guard,
// turns the startup outcome into 78 with that reason; a refusal without the
// detail stays 75 assignment_timeout.
func TestChunkStartupExitFinalGives78(t *testing.T) {
refusal := func(kind control.WorkspaceLeaseRefusal_Kind) error {
st, err := status.New(codes.FailedPrecondition, "workspace lease: server identity does not match the current holder").
WithDetails(&control.WorkspaceLeaseRefusal{Kind: kind})
if err != nil {
t.Fatal(err)
}
return st.Err()
}
for _, tc := range []struct {
name string
refuse error
code int
reason string
}{
{"moved", refusal(control.WorkspaceLeaseRefusal_MOVED), exitWorkspaceSuperseded, "moved"},
{"deleted", refusal(control.WorkspaceLeaseRefusal_DELETED), exitWorkspaceSuperseded, "deleted"},
{"no detail", status.Error(codes.FailedPrecondition, "workspace lease: server identity does not match the current holder"), exitWorkspaceRetry, "assignment_timeout"},
} {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
h, assign := exitAuthorityHost(t, func(s *exitAssignmentStream) { s.refuse = tc.refuse })
assign("r", 1)
leaseCtx, stopLease := context.WithCancel(ctx)
done := make(chan error, 1)
go func() {
done <- h.RunWorkspaceLease(leaseCtx, func(context.Context, *control.WorkspaceIdentity) (uint64, error) { return 1, nil })
}()
t.Cleanup(func() { stopLease(); <-done })
if tc.reason == "assignment_timeout" {
time.Sleep(2 * time.Second) // a renewal or two, refused without a detail
if _, final := h.MasterWaitState(); final != "" {
t.Fatalf("a refusal without a detail was taken as final %q", final)
}
}
for tc.reason != "assignment_timeout" {
if _, final := h.MasterWaitState(); final != "" {
break
}
select {
case <-ctx.Done():
t.Fatal("the guard's refusal never reached the host")
case <-time.After(20 * time.Millisecond):
}
}
e := newProcessExit(ctx)
if !chooseChunkStartupExit(e, flags{workspaceLease: true, durableImpl: "walstore-chunk", volumeID: "v"}, h, &exitStartupOutcome{expired: true}) {
t.Fatal("the startup outcome selected no exit")
}
out := <-e.decision
if out.code != tc.code || out.reason != tc.reason {
t.Fatalf("exit %+v; want %d %s", out, tc.code, tc.reason)
}
})
}
}