diff --git a/pkg/engine/image_verify_test.go b/pkg/engine/image_verify_test.go index a529b01bb5..1d949b39a5 100644 --- a/pkg/engine/image_verify_test.go +++ b/pkg/engine/image_verify_test.go @@ -1118,7 +1118,7 @@ func Test_ImageVerifyCacheExpiredCosign(t *testing.T) { opts := []imageverifycache.Option{ imageverifycache.WithCacheEnableFlag(true), imageverifycache.WithMaxSize(1000), - imageverifycache.WithTTLDuration(5 * time.Second), + imageverifycache.WithTTLDuration(2 * time.Second), } imageVerifyCache, err := imageverifycache.New(opts...) assert.NilError(t, err) @@ -1137,7 +1137,7 @@ func Test_ImageVerifyCacheExpiredCosign(t *testing.T) { er, ivm = testImageVerifyCache(imageVerifyCache, context.TODO(), registryclient.NewOrDie(), nil, policyContext, cfg) secondOperationTime := time.Since(start) errorAssertionUtil(t, image, ivm, er) - assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry is expired, so image verification should not be from cache.") + assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry is expired, so image verification should not be from cache.", firstOperationTime, secondOperationTime) } func Test_changePolicyCacheVerificationCosign(t *testing.T) { @@ -1162,7 +1162,7 @@ func Test_changePolicyCacheVerificationCosign(t *testing.T) { er, ivm = testImageVerifyCache(imageVerifyCache, context.TODO(), registryclient.NewOrDie(), nil, policyContext, cfg) secondOperationTime := time.Since(start) errorAssertionUtil(t, image, ivm, er) - assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry not found, so image verification should not be from cache.") + assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry not found, so image verification should not be from cache.", firstOperationTime, secondOperationTime) } var verifyImageNotaryPolicy = `{ @@ -1289,7 +1289,6 @@ var verifyImageNotaryResource = `{ }` func Test_ImageVerifyCacheNotary(t *testing.T) { - opts := []imageverifycache.Option{ imageverifycache.WithCacheEnableFlag(true), imageverifycache.WithMaxSize(1000), @@ -1313,11 +1312,10 @@ func Test_ImageVerifyCacheNotary(t *testing.T) { } func Test_ImageVerifyCacheExpiredNotary(t *testing.T) { - opts := []imageverifycache.Option{ imageverifycache.WithCacheEnableFlag(true), imageverifycache.WithMaxSize(1000), - imageverifycache.WithTTLDuration(5 * time.Second), + imageverifycache.WithTTLDuration(2 * time.Second), } imageVerifyCache, err := imageverifycache.New(opts...) assert.NilError(t, err) @@ -1325,19 +1323,18 @@ func Test_ImageVerifyCacheExpiredNotary(t *testing.T) { policyContext := buildContext(t, verifyImageNotaryPolicy, verifyImageNotaryResource, "") - assert.NilError(t, err) start := time.Now() er, ivm := testImageVerifyCache(imageVerifyCache, context.TODO(), registryclient.NewOrDie(), nil, policyContext, cfg) firstOperationTime := time.Since(start) errorAssertionUtil(t, image, ivm, er) + time.Sleep(5 * time.Second) start = time.Now() er, ivm = testImageVerifyCache(imageVerifyCache, context.TODO(), registryclient.NewOrDie(), nil, policyContext, cfg) secondOperationTime := time.Since(start) errorAssertionUtil(t, image, ivm, er) - assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry is expired, so image verification should not be from cache.") - + assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry is expired, so image verification should not be from cache.", firstOperationTime, secondOperationTime) } func Test_changePolicyCacheVerificationNotary(t *testing.T) { @@ -1361,6 +1358,5 @@ func Test_changePolicyCacheVerificationNotary(t *testing.T) { er, ivm = testImageVerifyCache(imageVerifyCache, context.TODO(), registryclient.NewOrDie(), nil, policyContext, cfg) secondOperationTime := time.Since(start) errorAssertionUtil(t, image, ivm, er) - assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry not found, so image verification should not be from cache.") - + assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry not found, so image verification should not be from cache.", firstOperationTime, secondOperationTime) }