Skip to content

Commit

Permalink
test(storage): retry metadata check in SoftDelete test (#11528)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennaEpp authored Jan 29, 2025
1 parent 360cfc4 commit c2f9f6b
Showing 1 changed file with 27 additions and 19 deletions.
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

0 comments on commit c2f9f6b

Please sign in to comment.