diff --git a/.github/workflows/switch-repeat.yml b/.github/workflows/switch-repeat.yml new file mode 100644 index 0000000000..665a500ac6 --- /dev/null +++ b/.github/workflows/switch-repeat.yml @@ -0,0 +1,67 @@ +name: Switch repeat (diagnostic, not for main) + +# Diagnostic only, never merged: conversation-switch.test.tsx under the load of the app (real +# browser, WebKit) job, and after the files it ran behind locally, printing what its server saw +# whenever its reopen test fails. Three shards, as the CI queue allows. +on: + pull_request: + +permissions: + contents: read + +jobs: + repeat: + if: github.head_ref == 'diag/switch-chromium' + strategy: + fail-fast: false + matrix: + shard: [1, 2, 3] + runs-on: openbot-ubuntu-16core + timeout-minutes: 45 + env: + PLAYWRIGHT_IMAGE: mcr.microsoft.com/playwright:v1.62.1-noble@sha256:dcc5531e97840b9b5e794f2814476b21571c5124a3fca2267d73041f56e7580e + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 + with: + bun-version: 1.4.3 + - run: bun install --frozen-lockfile + - run: bun run generate:app-config + - name: Copies of the file + run: | + for r in 1 2 3 4 5; do + cp app/tests/conversation-switch.test.tsx "app/tests/conversation-switch-r$r.test.tsx" + done + - name: Under load, with CI's WebKit-job list, eight at once + run: | + set +e + LIST=$(grep -o 'app/tests/chunk-recovery.test.tsx.*artifact-sign-in-refusal-browser.test.tsx' .github/workflows/ci.yml | head -1) + docker run --rm --ipc=host \ + --volume "$GITHUB_WORKSPACE:$GITHUB_WORKSPACE" --workdir "$GITHUB_WORKSPACE" \ + --volume "$(command -v bun):/usr/local/bin/bun:ro" \ + --env OPENBOT_APP_BROWSER=1 --env OPENBOT_APP_ENGINES=chromium,webkit \ + "$PLAYWRIGHT_IMAGE" \ + bun test --parallel=8 --timeout=5000 $LIST app/tests/conversation-switch-r*.test.tsx \ + > load.log 2>&1 + echo "passes: $(grep -cE '\(pass\) switching conversations' load.log), fails:" + grep -E '\(fail\) switching conversations' load.log || echo "none" + sed -n '/SWITCHDIAG/,/SWITCHDIAG END/p' load.log + grep -B3 -A25 'error: expect' load.log | grep -A28 'conversation-switch' | grep -vE '^\s+at ' | head -80 + - name: After the files it ran behind, four times, one process each + run: | + set +e + for r in 1 2 3 4; do + docker run --rm --ipc=host \ + --volume "$GITHUB_WORKSPACE:$GITHUB_WORKSPACE" --workdir "$GITHUB_WORKSPACE" \ + --volume "$(command -v bun):/usr/local/bin/bun:ro" \ + --env OPENBOT_APP_BROWSER=1 --env OPENBOT_APP_ENGINES=chromium,webkit \ + "$PLAYWRIGHT_IMAGE" \ + bun test app/tests/conversation-reopen-end.test.tsx app/tests/conversation-switch.test.tsx app/tests/transcript-follow.test.tsx \ + > seq-$r.log 2>&1 + echo "sequence $r: $(grep -cE '\(pass\) switching conversations' seq-$r.log) switch passes" + grep -E '\(fail\)' seq-$r.log || true + sed -n '/SWITCHDIAG/,/SWITCHDIAG END/p' seq-$r.log + grep -B3 -A25 'error: expect' seq-$r.log | grep -vE '^\s+at ' | head -60 + done diff --git a/app/tests/conversation-switch.test.tsx b/app/tests/conversation-switch.test.tsx index 51044631e5..b54d3dc807 100644 --- a/app/tests/conversation-switch.test.tsx +++ b/app/tests/conversation-switch.test.tsx @@ -193,6 +193,12 @@ let gateway: Gateway; const sleep = (milliseconds: number) => new Promise((resolve) => setTimeout(resolve, milliseconds)); +/** DIAGNOSTIC: what the server saw, with the time since the test began. */ +let timeline: string[] = []; +let began = Date.now(); +const mark = (what: string) => + timeline.push(`${Date.now() - began}ms ${what}`); + /** * What the gateway sends a browser that has joined the design thread. * @@ -208,6 +214,7 @@ async function design( ) { gateway.joins += 1; const join = gateway.joins; + mark(`join ${join} (finished=${gateway.finished} written=${gateway.written})`); if (gateway.finished) { for (const one of [ event(STARTED, { type: "RUN_STARTED" }), @@ -591,6 +598,10 @@ beforeAll(async () => { port: 0, fetch(request, bun) { const url = new URL(request.url); + if (request.headers.get("upgrade") === "websocket") { + mark(`socket upgrade ${url.pathname}`); + } else if (url.pathname.includes("/threads/")) + mark(`read ${url.pathname}`); if (request.headers.get("upgrade") === "websocket") return bun.upgrade(request, { data: { open: true } }) ? undefined @@ -603,13 +614,15 @@ beforeAll(async () => { return reply(url); }, websocket: { - close(socket) { + close(socket, code) { socket.data.open = false; + mark(`socket closed ${code}`); }, message(socket, message) { const [joinRef, ref, topic, name] = JSON.parse( String(message), ) as Frame; + if (name !== "heartbeat") mark(`${name} ${topic}`); socket.send( JSON.stringify([ joinRef, @@ -745,8 +758,15 @@ describe.skipIf(!asked)("switching conversations while a Bot answers", () => { finished: false, resume: () => {}, }; + timeline = []; + began = Date.now(); const page = await open(engine, theme, window); const name = `${engine}-${theme}-${window.width}`; + let passed = false; + page.on("console", (message) => { + if (message.type() === "error" || message.type() === "warning") + mark(`page ${message.type()}: ${message.text().slice(0, 160)}`); + }); try { // The Bot is writing; the person reads the start of it. await page @@ -765,6 +785,7 @@ describe.skipIf(!asked)("switching conversations while a Bot answers", () => { while (!gateway.finished && Date.now() < until) await sleep(100); expect(gateway.finished).toBe(true); const back = await settled(page); + mark(`back: ${JSON.stringify(back)}`); await shoot(page, "back", name); expect(back).toEqual(WHOLE_ONCE); @@ -773,21 +794,31 @@ describe.skipIf(!asked)("switching conversations while a Bot answers", () => { await page.getByText("Here are the notes.").waitFor(); await switchTo(page, "Three landing page directions"); const backAgain = await settled(page); + mark(`back again: ${JSON.stringify(backAgain)}`); await shoot(page, "back-again", name); expect(backAgain).toEqual(WHOLE_ONCE); // And opened again from nothing, as a reload or a new window does. // The stored copy can be on screen before the page joins the thread again, so the // join is waited for, and the answer read again once the replay has landed on it. + mark("reload"); await page.reload(); + mark("reloaded"); const joined = Date.now() + 15_000; while (gateway.joins < 4 && Date.now() < joined) await sleep(100); + mark(`joins after wait: ${gateway.joins}`); expect(gateway.joins).toBe(4); const reopened = await settled(page, 15_000); + mark(`reopened: ${JSON.stringify(reopened)}`); await shoot(page, "reopened", name); expect(reopened).toEqual(WHOLE_ONCE); expect(gateway.joins).toBe(4); + passed = true; } finally { + if (!passed) { + mark(`at failure: joins=${gateway.joins} drawn=${JSON.stringify(await drawn(page).catch((error) => String(error)))}`); + console.error(`SWITCHDIAG ${name}\n${timeline.join("\n")}\nSWITCHDIAG END`); + } await page.close(); } }, 120_000);