gocache
gocache copied to clipboard
Cannot write reliable tests for cache invalidation
I am testing a cache that I've written on top of eko/gocache. I need to wait for an invalidation to occur before I can move on to my next step. Currently I am waiting for the invalidation via:
// wait for cache invalidation
assert.Eventually(t, func() bool {
_, err = s.localStore.Get(ctx, key)
return err != nil
}, 10*time.Second, 10*time.Millisecond, "timed out waiting for local store")
this loops for 10 seconds, checking every 10 milliseconds to see if the value has been ejected.
Usually this passes, but sometimes it does not pass. I cannot figure out why this sometimes fails.
I am using Invalidate
and not Delete
, so it is invalidating via the tag.
Local store in this case is Ristretto.