@@ -1069,6 +1069,55 @@ func TestNegativeCasesObjectsStorage(t *testing.T) {
10691069func 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
0 commit comments