Skip to content

Commit c2f9f6b

Browse files
authored
test(storage): retry metadata check in SoftDelete test (#11528)
1 parent 360cfc4 commit c2f9f6b

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

storage/integration_test.go

+27-19
Original file line numberDiff line numberDiff line change
@@ -4846,6 +4846,24 @@ func TestIntegration_SoftDelete(t *testing.T) {
48464846
t.Fatalf("effective time of soft delete policy should not be in the past, got: %v, test start: %v", got.EffectiveTime, testStart.UTC())
48474847
}
48484848

4849+
// Update the soft delete policy of the bucket.
4850+
policy.RetentionDuration = time.Hour * 24 * 9
4851+
// Retry to account for metadata propagation delay.
4852+
if err := retry(ctx, func() error {
4853+
attrs, err = b.Update(ctx, BucketAttrsToUpdate{SoftDeletePolicy: policy})
4854+
if err != nil {
4855+
return fmt.Errorf("b.Update: %v", err)
4856+
}
4857+
return nil
4858+
}, func() error {
4859+
if got, expect := attrs.SoftDeletePolicy.RetentionDuration, policy.RetentionDuration; got != expect {
4860+
return fmt.Errorf("mismatching retention duration; got: %+v, expected: %+v", got, expect)
4861+
}
4862+
return nil
4863+
}); err != nil {
4864+
t.Error(err)
4865+
}
4866+
48494867
// Create a second bucket with an empty soft delete policy to verify
48504868
// that this leads to no retention.
48514869
b2 := client.Bucket(prefix + uidSpace.New())
@@ -4862,23 +4880,7 @@ func TestIntegration_SoftDelete(t *testing.T) {
48624880
t.Fatalf("mismatching retention duration; got: %+v, expected: %+v", got, expect)
48634881
}
48644882

4865-
// Update the soft delete policy of the original bucket.
4866-
policy.RetentionDuration = time.Hour * 24 * 9
4867-
4868-
retry(ctx, func() error {
4869-
attrs, err = b.Update(ctx, BucketAttrsToUpdate{SoftDeletePolicy: policy})
4870-
if err != nil {
4871-
return fmt.Errorf("b.Update: %v", err)
4872-
}
4873-
return nil
4874-
}, func() error {
4875-
if got, expect := attrs.SoftDeletePolicy.RetentionDuration, policy.RetentionDuration; got != expect {
4876-
return fmt.Errorf("mismatching retention duration; got: %+v, expected: %+v", got, expect)
4877-
}
4878-
return nil
4879-
})
4880-
4881-
// Create 2 objects and delete one of them.
4883+
// Create 2 objects in the original bucket and delete one of them.
48824884
deletedObject := b.Object("soft-delete" + uidSpaceObjects.New())
48834885
liveObject := b.Object("not-soft-delete" + uidSpaceObjects.New())
48844886

@@ -4937,8 +4939,14 @@ func TestIntegration_SoftDelete(t *testing.T) {
49374939
if oAttrs.SoftDeleteTime.Before(testStart) {
49384940
t.Fatalf("SoftDeleteTime of soft deleted object should not be in the past, got: %v, test start: %v", oAttrs.SoftDeleteTime, testStart.UTC())
49394941
}
4940-
if got, expected := oAttrs.HardDeleteTime, oAttrs.SoftDeleteTime.Add(policy.RetentionDuration); !expected.Equal(got) {
4941-
t.Fatalf("HardDeleteTime of soft deleted object should be equal to SoftDeleteTime+RetentionDuration, got: %v, expected: %v", got, expected)
4942+
4943+
if err := retry(ctx, func() error {
4944+
if got, expected := oAttrs.HardDeleteTime, oAttrs.SoftDeleteTime.Add(policy.RetentionDuration); !expected.Equal(got) {
4945+
return fmt.Errorf("HardDeleteTime of soft deleted object should be equal to SoftDeleteTime+RetentionDuration, got: %v, expected: %v", got, expected)
4946+
}
4947+
return nil
4948+
}, func() error { return nil }); err != nil {
4949+
t.Fatal(err)
49424950
}
49434951

49444952
// Restore a soft deleted object.

0 commit comments

Comments
 (0)