eko / gocache

☔️ A complete Go cache library that brings you multiple ways of managing your caches
https://vincent.composieux.fr/article/i-wrote-gocache-a-complete-and-extensible-go-cache-library/
MIT License
2.42k stars 192 forks source link

Cannot write reliable tests for cache invalidation #176

Open sgtsquiggs opened 1 year ago

sgtsquiggs commented 1 year ago

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.