Skip to content
Closed
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
67 changes: 67 additions & 0 deletions .github/workflows/switch-repeat.yml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 32 additions & 1 deletion app/tests/conversation-switch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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" }),
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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);
Expand Down
Loading