Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(storage): retry metadata check in SoftDelete test #11528

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions storage/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4846,6 +4846,24 @@ func TestIntegration_SoftDelete(t *testing.T) {
t.Fatalf("effective time of soft delete policy should not be in the past, got: %v, test start: %v", got.EffectiveTime, testStart.UTC())
}

// Update the soft delete policy of the bucket.
policy.RetentionDuration = time.Hour * 24 * 9
// Retry to account for metadata propagation delay.
if err := retry(ctx, func() error {
attrs, err = b.Update(ctx, BucketAttrsToUpdate{SoftDeletePolicy: policy})
if err != nil {
return fmt.Errorf("b.Update: %v", err)
}
return nil
}, func() error {
if got, expect := attrs.SoftDeletePolicy.RetentionDuration, policy.RetentionDuration; got != expect {
return fmt.Errorf("mismatching retention duration; got: %+v, expected: %+v", got, expect)
}
return nil
}); err != nil {
t.Error(err)
}

// Create a second bucket with an empty soft delete policy to verify
// that this leads to no retention.
b2 := client.Bucket(prefix + uidSpace.New())
Expand All @@ -4862,23 +4880,7 @@ func TestIntegration_SoftDelete(t *testing.T) {
t.Fatalf("mismatching retention duration; got: %+v, expected: %+v", got, expect)
}

// Update the soft delete policy of the original bucket.
policy.RetentionDuration = time.Hour * 24 * 9

retry(ctx, func() error {
attrs, err = b.Update(ctx, BucketAttrsToUpdate{SoftDeletePolicy: policy})
if err != nil {
return fmt.Errorf("b.Update: %v", err)
}
return nil
}, func() error {
if got, expect := attrs.SoftDeletePolicy.RetentionDuration, policy.RetentionDuration; got != expect {
return fmt.Errorf("mismatching retention duration; got: %+v, expected: %+v", got, expect)
}
return nil
})

// Create 2 objects and delete one of them.
// Create 2 objects in the original bucket and delete one of them.
deletedObject := b.Object("soft-delete" + uidSpaceObjects.New())
liveObject := b.Object("not-soft-delete" + uidSpaceObjects.New())

Expand Down Expand Up @@ -4937,8 +4939,14 @@ func TestIntegration_SoftDelete(t *testing.T) {
if oAttrs.SoftDeleteTime.Before(testStart) {
t.Fatalf("SoftDeleteTime of soft deleted object should not be in the past, got: %v, test start: %v", oAttrs.SoftDeleteTime, testStart.UTC())
}
if got, expected := oAttrs.HardDeleteTime, oAttrs.SoftDeleteTime.Add(policy.RetentionDuration); !expected.Equal(got) {
t.Fatalf("HardDeleteTime of soft deleted object should be equal to SoftDeleteTime+RetentionDuration, got: %v, expected: %v", got, expected)

if err := retry(ctx, func() error {
if got, expected := oAttrs.HardDeleteTime, oAttrs.SoftDeleteTime.Add(policy.RetentionDuration); !expected.Equal(got) {
return fmt.Errorf("HardDeleteTime of soft deleted object should be equal to SoftDeleteTime+RetentionDuration, got: %v, expected: %v", got, expected)
}
return nil
}, func() error { return nil }); err != nil {
t.Fatal(err)
}

// Restore a soft deleted object.
Expand Down
Loading