test(19.3-06): wait for the queued site-cache purge before asserting (WR-01)
- every read of the purge receiver first drains the app's purger through cooler.SiteCachePurger.Wait, since cooler now queues purges after commit
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -206,10 +207,16 @@ func TestSiteCachePurgeRequest(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("outside a transaction the after-commit purge runs at once", func(t *testing.T) {
|
||||
t.Run("outside a transaction the after-commit purge is queued at once", func(t *testing.T) {
|
||||
captureLogs(t)
|
||||
srv, hits := purgeReceiver(t, func(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write([]byte(`{"purged":2}`)) })
|
||||
PurgeSiteCacheAfterCommit(context.Background(), nil, newTestPurger(t, srv), "category", "now")
|
||||
p := newTestPurger(t, srv)
|
||||
PurgeSiteCacheAfterCommit(context.Background(), nil, p, "category", "now")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if err := p.Wait(ctx); err != nil {
|
||||
t.Fatalf("Wait: %v", err)
|
||||
}
|
||||
if got := hits(); len(got) != 1 || got[0].body["kind"] != "category" || got[0].body["slug"] != "now" {
|
||||
t.Fatalf("requests = %#v, want one", got)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user