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