mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-05 15:37:19 +00:00
feat: update ivcache Set() to use Wait() (#8286)
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> Co-authored-by: shuting <shuting@nirmata.com>
This commit is contained in:
parent
c6e7ec2172
commit
274e93199b
2 changed files with 3 additions and 2 deletions
|
@ -1063,7 +1063,7 @@ func Test_ImageVerifyCacheCosign(t *testing.T) {
|
||||||
er, ivm = testImageVerifyCache(imageVerifyCache, context.TODO(), registryclient.NewOrDie(), nil, policyContext, cfg)
|
er, ivm = testImageVerifyCache(imageVerifyCache, context.TODO(), registryclient.NewOrDie(), nil, policyContext, cfg)
|
||||||
secondOperationTime := time.Since(start)
|
secondOperationTime := time.Since(start)
|
||||||
errorAssertionUtil(t, image, ivm, er)
|
errorAssertionUtil(t, image, ivm, er)
|
||||||
assert.Check(t, secondOperationTime < firstOperationTime/2, "cache entry is valid, so image verification should be from cache.", firstOperationTime, secondOperationTime)
|
assert.Check(t, secondOperationTime < firstOperationTime/10, "cache entry is valid, so image verification should be from cache.", firstOperationTime, secondOperationTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_ImageVerifyCacheExpiredCosign(t *testing.T) {
|
func Test_ImageVerifyCacheExpiredCosign(t *testing.T) {
|
||||||
|
@ -1266,7 +1266,7 @@ func Test_ImageVerifyCacheNotary(t *testing.T) {
|
||||||
er, ivm = testImageVerifyCache(imageVerifyCache, context.TODO(), registryclient.NewOrDie(), nil, policyContext, cfg)
|
er, ivm = testImageVerifyCache(imageVerifyCache, context.TODO(), registryclient.NewOrDie(), nil, policyContext, cfg)
|
||||||
secondOperationTime := time.Since(start)
|
secondOperationTime := time.Since(start)
|
||||||
errorAssertionUtil(t, image, ivm, er)
|
errorAssertionUtil(t, image, ivm, er)
|
||||||
assert.Check(t, secondOperationTime < firstOperationTime, "cache entry is valid, so image verification should be from cache.", firstOperationTime, secondOperationTime)
|
assert.Check(t, secondOperationTime < firstOperationTime/10, "cache entry is valid, so image verification should be from cache.", firstOperationTime, secondOperationTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_ImageVerifyCacheExpiredNotary(t *testing.T) {
|
func Test_ImageVerifyCacheExpiredNotary(t *testing.T) {
|
||||||
|
|
|
@ -98,6 +98,7 @@ func (c *cache) Set(ctx context.Context, policy kyvernov1.PolicyInterface, ruleN
|
||||||
key := generateKey(policy, ruleName, imageRef)
|
key := generateKey(policy, ruleName, imageRef)
|
||||||
|
|
||||||
stored := c.cache.SetWithTTL(key, nil, 1, c.ttl)
|
stored := c.cache.SetWithTTL(key, nil, 1, c.ttl)
|
||||||
|
c.cache.Wait()
|
||||||
if stored {
|
if stored {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue