oficina / docs Public

Docs: the closing test sees the beacon, not the old page's own save

The paste gzipped to under 20KB, so a beacon repeating it fitted the
quota, and the old page outlived the hold and sent the text itself: with
the beacon fix reverted the test still passed (Claude Fable on #94, round
2). The paste is now 46KB of random letters, about 28KB gzipped, the test
requires a save answered while the large one is still held, and each
finished page is closed so its held link does not queue the beacon behind
the host's connection limit. Reverted, it fails in Chromium and WebKit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 2c518dd9caac0d3dfda3e4a307805d5d01218959 parent cc3589e
2 files changed, +40 −9
  • fixtures/engines/saving.mjs +5 −0
  • internal/docs/saving_browser_test.go +35 −9
diff --git a/fixtures/engines/saving.mjs b/fixtures/engines/saving.mjs
index d63598f..9b0e1ff 100644
--- a/fixtures/engines/saving.mjs
+++ b/fixtures/engines/saving.mjs
@@ -44,6 +44,10 @@ for (const [engineName, engine] of Object.entries({ chromium, webkit }).filter((
// loading: the test's server holds it until the browser goes away.
await pause(3000)
console.log('SAVING RESULT ' + JSON.stringify({ engine: engineName, states }))
+ // Each page done with is closed, and its held link and stream with it:
+ // left open they take the host's connections (six, on HTTP/1.1), and a
+ // later page's unload beacon queues behind them.
+ await page.close()
// The same with other edits (config.held: [{ name, docs, typing }]):
// a large paste of prose, which goes keepalive once gzipped, and one
@@ -62,6 +66,7 @@ for (const [engineName, engine] of Object.entries({ chromium, webkit }).filter((
await page.evaluate(`(${config.script})(${JSON.stringify(held.typing)})`)
await pause(3000)
console.log('SAVING RESULT ' + JSON.stringify({ engine: engineName + '-' + held.name, states: heldStates }))
+ await page.close()
}
// Closing with a large save on the wire: the server holds it, the page
diff --git a/internal/docs/saving_browser_test.go b/internal/docs/saving_browser_test.go
index 33ea630..c893f72 100644
--- a/internal/docs/saving_browser_test.go
+++ b/internal/docs/saving_browser_test.go
@@ -90,14 +90,18 @@ const closingScript = `({ big, queued }) => {
}, 700)
}`
-// closingTyping is what closingScript types: a paste just under a
-// keepalive save's 32KiB, and a couple of KB after it. Random letters, so
-// that compressing the paste does not shrink it out of the case.
+// closingTyping is what closingScript types: a paste of 46KB of random
+// letters, which gzips to about 28KB, so it goes as a keepalive save just
+// under 32KiB, and a couple of KB after it. A beacon repeating that save
+// (46KB raw, beside the 28KB on the wire) is over the shared 64KiB; one of
+// the queue alone is not. At 32.6KB the paste gzipped to under 20KB and
+// the repeat fitted, so the test could not fail (Claude Fable on #94,
+// round 2).
func closingTyping() map[string]string {
rng := rand.New(rand.NewPCG(1, 2))
var big, queued strings.Builder
big.WriteString("Bigpaste ")
- for big.Len() < 32600 {
+ for big.Len() < 46000 {
big.WriteByte(byte('a' + rng.IntN(26)))
}
queued.WriteString("Queuedbehind ")
@@ -206,6 +210,17 @@ func TestSavingContinuesWhileALinkIsLoading(t *testing.T) {
if !strings.Contains(string(out), `SAVING CLOSED {"engine":"`+e+`"}`) {
t.Fatal("the harness never closed the page")
}
+ // The beacon, while the large save is still held: the
+ // queued text arrives by itself. Without it the old page,
+ // which outlives the hold, sends the text once the large
+ // save is answered, so the words alone prove nothing
+ // (Claude Fable on #94, round 2).
+ s.mu.Lock()
+ beaconed := s.duringLarge[closing[e]]
+ s.mu.Unlock()
+ if beaconed == 0 {
+ t.Error("nothing reached the server while the large save was held: the unload beacon was refused")
+ }
s.contains(t, closing[e], "Bigpaste Queuedbehind")
})
}
@@ -291,6 +306,10 @@ type savingServer struct {
// heldLarge are the documents whose first save of more than 16KiB the
// server answers three seconds late: true until it has.
heldLarge map[string]bool
+ // holdingLarge is, per document, whether that save is being held now;
+ // duringLarge counts the saves answered 2xx meanwhile.
+ holdingLarge map[string]bool
+ duringLarge map[string]int
}
// holdLarge makes the server answer sqid's first large save three seconds
@@ -311,7 +330,7 @@ func (s *savingServer) slow(sqid string) {
func newSavingServer(t *testing.T) *savingServer {
t.Helper()
server := httptest.NewUnstartedServer(nil)
- s := &savingServer{origin: "http://" + server.Listener.Addr().String(), held: map[string]int{}, slowed: map[string]bool{}, heldLarge: map[string]bool{}}
+ s := &savingServer{origin: "http://" + server.Listener.Addr().String(), held: map[string]int{}, slowed: map[string]bool{}, heldLarge: map[string]bool{}, holdingLarge: map[string]bool{}, duringLarge: map[string]int{}}
app, err := docs.NewForTestWith(t, docs.Config{Origin: s.origin})
if err != nil {
t.Fatal(err)
@@ -337,6 +356,7 @@ func newSavingServer(t *testing.T) *savingServer {
slow, large := s.slowed[sqid], s.heldLarge[sqid] && r.ContentLength > 16*1024
if large {
s.heldLarge[sqid] = false
+ s.holdingLarge[sqid] = true
}
s.mu.Unlock()
if slow {
@@ -344,15 +364,21 @@ func newSavingServer(t *testing.T) *savingServer {
}
if large {
time.Sleep(3 * time.Second)
+ s.mu.Lock()
+ s.holdingLarge[sqid] = false
+ s.mu.Unlock()
}
during := s.holding.Load() > 0
rec := &statusRecorder{ResponseWriter: w, code: http.StatusOK}
served.ServeHTTP(rec, r)
- if during && rec.code/100 == 2 {
- s.mu.Lock()
- s.held[strings.Split(r.URL.Path, "/")[2]]++
- s.mu.Unlock()
+ s.mu.Lock()
+ if rec.code/100 == 2 && during {
+ s.held[sqid]++
}
+ if rec.code/100 == 2 && !large && s.holdingLarge[sqid] {
+ s.duringLarge[sqid]++
+ }
+ s.mu.Unlock()
return
}
served.ServeHTTP(w, r)