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:
Jakub Zych
2026-10-15 22:39:18 +02:00
parent a99e9a167e
commit 4f633f0b04
2 changed files with 43 additions and 3 deletions

View File

@@ -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)
}