mirror of
https://github.com/hashicorp/vault.git
synced 2026-05-05 12:26:34 +02:00
Wait for expiration manager to be out of restore mode while testing. (#12779)
This commit is contained in:
parent
7640d6a840
commit
c0abf719cc
@ -32,6 +32,17 @@ var testImagePull sync.Once
|
||||
// mockExpiration returns a mock expiration manager
|
||||
func mockExpiration(t testing.TB) *ExpirationManager {
|
||||
c, _, _ := TestCoreUnsealed(t)
|
||||
|
||||
// Wait until the expiration manager is out of restore mode.
|
||||
// This was added to prevent sporadic failures of TestExpiration_unrecoverableErrorMakesIrrevocable.
|
||||
timeout := time.Now().Add(time.Second * 10)
|
||||
for c.expiration.inRestoreMode() {
|
||||
if time.Now().After(timeout) {
|
||||
t.Fatal("ExpirationManager is still in restore mode after 10 seconds")
|
||||
}
|
||||
time.Sleep(50*time.Millisecond)
|
||||
}
|
||||
|
||||
return c.expiration
|
||||
}
|
||||
|
||||
@ -3077,20 +3088,22 @@ func TestExpiration_unrecoverableErrorMakesIrrevocable(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc.job.OnFailure(tc.err)
|
||||
t.Run(tc.err.Error(), func(t *testing.T) {
|
||||
tc.job.OnFailure(tc.err)
|
||||
|
||||
le, err := exp.loadEntry(ctx, tc.job.leaseID)
|
||||
if err != nil {
|
||||
t.Fatalf("could not load leaseID %q: %v", tc.job.leaseID, err)
|
||||
}
|
||||
if le == nil {
|
||||
t.Fatalf("nil lease for leaseID: %q", tc.job.leaseID)
|
||||
}
|
||||
le, err := exp.loadEntry(ctx, tc.job.leaseID)
|
||||
if err != nil {
|
||||
t.Fatalf("could not load leaseID %q: %v", tc.job.leaseID, err)
|
||||
}
|
||||
if le == nil {
|
||||
t.Fatalf("nil lease for leaseID: %q", tc.job.leaseID)
|
||||
}
|
||||
|
||||
isIrrevocable := le.isIrrevocable()
|
||||
if isIrrevocable != tc.shouldBeIrrevocable {
|
||||
t.Errorf("expected irrevocable: %t, got irrevocable: %t", tc.shouldBeIrrevocable, isIrrevocable)
|
||||
}
|
||||
isIrrevocable := le.isIrrevocable()
|
||||
if isIrrevocable != tc.shouldBeIrrevocable {
|
||||
t.Errorf("expected irrevocable: %t, got irrevocable: %t", tc.shouldBeIrrevocable, isIrrevocable)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user