Skip to content

Commit fc22a9d

Browse files
committed
test(storage): harden remote dedupe convergence checks
Signed-off-by: Ramkumar Chinchani <rchincha.dev@gmail.com>
1 parent e2360b7 commit fc22a9d

2 files changed

Lines changed: 84 additions & 11 deletions

File tree

pkg/storage/s3/s3_test.go

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,55 @@ func TestNegativeCasesObjectsStorage(t *testing.T) {
10691069
func TestS3Dedupe(t *testing.T) {
10701070
tskip.SkipS3(t)
10711071
tskip.SkipDynamo(t)
1072+
1073+
waitForBlobStatExists := func(storeDrv driver.StorageDriver, rootDir string, repo string,
1074+
digest godigest.Digest,
1075+
) error {
1076+
var statErr error
1077+
1078+
for range 300 {
1079+
_, statErr = storeDrv.Stat(context.Background(), path.Join(rootDir, repo, "blobs", "sha256", digest.Encoded()))
1080+
if statErr == nil {
1081+
return nil
1082+
}
1083+
1084+
time.Sleep(100 * time.Millisecond)
1085+
}
1086+
1087+
return fmt.Errorf("timed out waiting for stat on blob %s/%s: %w", repo, digest.Encoded(), statErr)
1088+
}
1089+
1090+
waitForBlobStatSize := func(storeDrv driver.StorageDriver, rootDir string, repo string,
1091+
digest godigest.Digest, expectedSize int64,
1092+
) error {
1093+
var (
1094+
statErr error
1095+
observedSize int64 = -1
1096+
)
1097+
1098+
for range 300 {
1099+
fi, err := storeDrv.Stat(context.Background(), path.Join(rootDir, repo, "blobs", "sha256", digest.Encoded()))
1100+
if err == nil {
1101+
observedSize = fi.Size()
1102+
if observedSize == expectedSize {
1103+
return nil
1104+
}
1105+
} else {
1106+
statErr = err
1107+
}
1108+
1109+
time.Sleep(100 * time.Millisecond)
1110+
}
1111+
1112+
if statErr != nil {
1113+
return fmt.Errorf("timed out waiting for size %d on blob %s/%s: %w",
1114+
expectedSize, repo, digest.Encoded(), statErr)
1115+
}
1116+
1117+
return fmt.Errorf("timed out waiting for size %d on blob %s/%s, observed %d",
1118+
expectedSize, repo, digest.Encoded(), observedSize)
1119+
}
1120+
10721121
Convey("Dedupe", t, func(c C) {
10731122
uuid, err := guuid.NewV4()
10741123
if err != nil {
@@ -1478,16 +1527,19 @@ func TestS3Dedupe(t *testing.T) {
14781527

14791528
// rebuild with dedupe false, should have all blobs with content
14801529
imgStore.RunDedupeBlobs(time.Duration(0), taskScheduler)
1481-
// wait until rebuild finishes
14821530

1483-
time.Sleep(10 * time.Second)
1531+
err = waitForBlobStatExists(storeDriver, testDir, "dedupe1", blobDigest1)
1532+
So(err, ShouldBeNil)
14841533

14851534
taskScheduler.Shutdown()
14861535

14871536
fi1, err := storeDriver.Stat(context.Background(), path.Join(testDir, "dedupe1", "blobs", "sha256",
14881537
blobDigest1.Encoded()))
14891538
So(err, ShouldBeNil)
14901539

1540+
err = waitForBlobStatSize(storeDriver, testDir, "dedupe2", blobDigest2, fi1.Size())
1541+
So(err, ShouldBeNil)
1542+
14911543
blobContent1, err := imgStore.GetBlobContent("dedupe1", blobDigest1)
14921544
So(err, ShouldBeNil)
14931545
So(len(blobContent1), ShouldBeGreaterThan, 0)
@@ -1510,9 +1562,9 @@ func TestS3Dedupe(t *testing.T) {
15101562

15111563
// rebuild with dedupe false, should have all blobs with content
15121564
imgStore.RunDedupeBlobs(time.Duration(0), taskScheduler)
1513-
// wait until rebuild finishes
15141565

1515-
time.Sleep(10 * time.Second)
1566+
err = waitForBlobStatSize(storeDriver, testDir, "dedupe2", blobDigest2, 0)
1567+
So(err, ShouldBeNil)
15161568

15171569
taskScheduler.Shutdown()
15181570

@@ -1761,9 +1813,9 @@ func TestS3Dedupe(t *testing.T) {
17611813

17621814
// rebuild with dedupe false, should have all blobs with content
17631815
imgStore.RunDedupeBlobs(time.Duration(0), taskScheduler)
1764-
// wait until rebuild finishes
17651816

1766-
time.Sleep(10 * time.Second)
1817+
err = waitForBlobStatExists(storeDriver, testDir, "dedupe1", blobDigest1)
1818+
So(err, ShouldBeNil)
17671819

17681820
taskScheduler.Shutdown()
17691821

@@ -1841,9 +1893,9 @@ func TestS3Dedupe(t *testing.T) {
18411893

18421894
// rebuild with dedupe false, should have all blobs with content
18431895
imgStore.RunDedupeBlobs(time.Duration(0), taskScheduler)
1844-
// wait until rebuild finishes
18451896

1846-
time.Sleep(10 * time.Second)
1897+
err = waitForBlobStatSize(storeDriver, testDir, "dedupe2", blobDigest2, 0)
1898+
So(err, ShouldBeNil)
18471899

18481900
taskScheduler.Shutdown()
18491901

pkg/storage/storage_test.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,18 +2518,39 @@ func TestReuploadCorruptedBlob(t *testing.T) {
25182518
ok bool
25192519
size int64
25202520
checkErr error
2521+
statOK bool
2522+
statSize int64
2523+
statErr error
25212524
)
25222525

2523-
for range 100 {
2526+
for range 300 {
25242527
ok, size, checkErr = imgStore.CheckBlob(context.Background(), repoName, digest)
2525-
if checkErr == nil && ok && size == int64(expectedSize) {
2528+
statOK, statSize, _, statErr = imgStore.StatBlob(repoName, digest)
2529+
2530+
if checkErr == nil && statErr == nil && ok && statOK &&
2531+
size == int64(expectedSize) && statSize == int64(expectedSize) {
25262532
return ok, size, nil
25272533
}
25282534

25292535
time.Sleep(100 * time.Millisecond)
25302536
}
25312537

2532-
return ok, size, checkErr
2538+
if checkErr != nil {
2539+
return ok, size, checkErr
2540+
}
2541+
2542+
if statErr != nil {
2543+
return statOK, statSize, statErr
2544+
}
2545+
2546+
if statOK {
2547+
return statOK, statSize,
2548+
fmt.Errorf("timed out waiting for blob %s size convergence: check=%d stat=%d expected=%d",
2549+
digest.String(), size, statSize, expectedSize)
2550+
}
2551+
2552+
return ok, size,
2553+
fmt.Errorf("timed out waiting for blob %s to be present with expected size %d", digest.String(), expectedSize)
25332554
}
25342555

25352556
Convey("Test reupload repair corrupted image", t, func() {

0 commit comments

Comments
 (0)