mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
test(workspace): expose divergent lease validity decisions
This commit is contained in:
1 parent
18b773a346
commit
be1337aeaa
2 files changed
+70
No files matched your search
@@ -0,0 +1,43 @@
|
||||
package authority
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestWorkspaceAckUsesGrantedHalfSkewBoundary(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
elapsed time.Duration
|
||||
allowed bool
|
||||
}{
|
||||
{"before", 28*time.Second - time.Nanosecond, true},
|
||||
{"at", 28 * time.Second, false},
|
||||
{"after", 29 * time.Second, false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
disk, _ := newTempStore(t)
|
||||
now := time.Unix(1000, 0)
|
||||
p := NewPublisher(nil, WithStore(disk), WithWorkspaceLeaseConfig(30*time.Second, func() time.Time { return now }), WithWorkspaceMaxClockSkew(4*time.Second))
|
||||
if err := p.apply(AssignmentAsk{VolumeID: "v", ReplicaID: "r", DataAddr: "d", CtrlAddr: "c", Intent: IntentBind}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx := context.Background()
|
||||
if _, err := p.RenewWorkspaceLease(ctx, "v", "r", 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.BeginWorkspaceRevocation(ctx, "v", "r", 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now = now.Add(tc.elapsed)
|
||||
err := p.AckWorkspaceRevocation(ctx, "v", WorkspaceRevokeAck{ReplicaID: "r", Epoch: 1, HeadGen: 7})
|
||||
if (err == nil) != tc.allowed {
|
||||
t.Fatalf("ACK allowed=%t, want %t: %v", err == nil, tc.allowed, err)
|
||||
}
|
||||
if (p.WorkspaceState("v").Ack != nil) != tc.allowed {
|
||||
t.Fatal("ACK persistence differs from admission")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -145,3 +145,30 @@ func TestWorkspaceClockSkewConfigReachesLeaseReply(t *testing.T) {
|
||||
t.Fatal("configuration not applied to host validity", lease, reply)
|
||||
}
|
||||
}
|
||||
|
||||
// The lease reply uses the publisher clock even when it differs from this
|
||||
// process's wall clock; configured skew also covers legacy leases with no bound.
|
||||
func TestWorkspaceLeaseFactUsesPublisherClockAndSkew(t *testing.T) {
|
||||
now := time.Unix(1000, 0)
|
||||
p := authority.NewPublisher(nil, authority.WithWorkspaceLeaseConfig(12*time.Second, func() time.Time { return now }), authority.WithWorkspaceMaxClockSkew(4*time.Second))
|
||||
_ = p
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
expiry time.Duration
|
||||
skew int64
|
||||
want time.Duration
|
||||
}{
|
||||
{"legacy-configured-bound", 10 * time.Second, 0, 8 * time.Second},
|
||||
{"persisted-larger-bound", 10 * time.Second, int64(6 * time.Second), 7 * time.Second},
|
||||
{"configured-ttl-cap", 40 * time.Second, 0, 12 * time.Second},
|
||||
{"expired", time.Second, 0, 0},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
l := authority.WorkspaceLease{ReplicaID: "r", Epoch: 1, ExpiresAtNS: now.Add(tc.expiry).UnixNano(), MaxClockSkewNS: tc.skew}
|
||||
fact := leaseFact("v", l)
|
||||
if fact.ValidForNs != int64(tc.want) {
|
||||
t.Fatalf("validity=%s, want %s", time.Duration(fact.ValidForNs), tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user