Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions playground/e2e/stress-tasks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Page } from "@playwright/test"
import { expect, test } from "@playwright/test"
import { watchNetworkProcess } from "./support/browser-crash"
import { awaitClientHandover } from "./support/hydrated"
import {
card,
Expand Down Expand Up @@ -29,6 +30,9 @@ import {
* for the wrong reason. The reload storm counts errors only from the document
* it settles on: WebKit reports the module imports a reload aborts in the
* document it tore down as page errors, and those are the reload, not the app.
* Its count checks name a crash of WebKit's network process when there was one
* (`support/browser-crash.ts`): that empties the test context's storage and
* reads "0 pending" exactly like lost writes.
*/

const MUTATIONS = "/src/data/collections/todos/mutations.ts"
Expand Down Expand Up @@ -127,20 +131,27 @@ test.describe("The tasks app under load", () => {
await openApp(page)
await createMany(page, "Kept", 50)
await expect(taskCounts(page)).toHaveText(/50 pending/)
const network = watchNetworkProcess(page)

//five reloads back to back, each tearing down a document still booting
for (let reload = 0; reload < 5; reload += 1) {
await page.reload()
}
await awaitClientHandover(page)
await expect(taskCounts(page)).toHaveText(/50 pending/)
await expect(
taskCounts(page),
network.explain("the storm lost tasks"),
).toHaveText(/50 pending/)
expect(await storedRows(page)).toHaveLength(50)

//and the document that follows the storm boots clean, start to finish
const errors = collectErrors(page)
await page.reload()
await awaitClientHandover(page)
await expect(taskCounts(page)).toHaveText(/50 pending/)
await expect(
taskCounts(page),
network.explain("the reload after the storm lost tasks"),
).toHaveText(/50 pending/)
expect(await storedRows(page)).toHaveLength(50)
expect(errors).toEqual([])
})
Expand Down
60 changes: 60 additions & 0 deletions playground/e2e/support/browser-crash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type { Page } from "@playwright/test"

/*
* A crash of WebKit's network process, told apart from the app losing data.
*
* Playwright's WebKit contexts are ephemeral: IndexedDB, localStorage and the
* cookie jar live in the memory of the network process, not on disk. When that
* process dies the browser starts a new one with empty storage, so the next
* document reads an empty store and the tasks app shows "0 pending" — the
* symptom of lost writes, though every write had committed.
*
* The Linux WebKit build does crash that way under a reload storm on a loaded
* machine: each reload cancels a hundred dev-server module requests, a child
* process logs a GLib refcount assertion and then glibc's "corrupted
* double-linked list", and the browser's stderr says "WebKit encountered an
* internal error. This is a WebKit bug." Safari's network stack is not GLib,
* and Safari keeps IndexedDB on disk; this is the test browser, not something
* the app can guard against.
*
* The page sees the crash in two ways: each load in flight fails with "WebKit
* encountered an internal error", and an open WebSocket (the dev server's HMR
* socket) reports "Network process crashed". Either one is enough.
*/

const CRASH_SIGNS = [
/WebKit encountered an internal error/,
/Network process crashed/,
]

export type NetworkProcessWatch = {
/** The first sign of a crash seen so far, or null. */
crash: () => string | null
/** An assertion message: `what`, plus the crash when there was one. */
explain: (what: string) => string
}

/** Watch `page` for the signs that WebKit's network process crashed. */
export function watchNetworkProcess(page: Page): NetworkProcessWatch {
let first: string | null = null
const note = (text: string) => {
if (first === null && CRASH_SIGNS.some((sign) => sign.test(text))) {
first = text
}
}
page.on("requestfailed", (request) =>
note(`${request.failure()?.errorText ?? ""} (${request.url()})`),
)
page.on("console", (message) => {
if (message.type() === "error") note(message.text())
})
return {
crash: () => first,
explain: (what) =>
first === null
? what
: `${what} — but WebKit's network process crashed during the test ` +
`(${first}), which empties an ephemeral context's storage: read this ` +
"as a browser crash, not as the app losing writes",
}
}
Loading