Skip to content
Merged
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
33 changes: 28 additions & 5 deletions app/tests/first-message-thinking.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,17 @@ type By = "typing" | "starter";
* is when the page next took up a task after that, so whatever the page did straight after putting
* the line in, before it could be drawn, counts too. What is left between `free` and the frame that
* draws the line is the browser's wait for its next frame, which is what stretches on a loaded
* runner (eight files at once, Chromium and WebKit each). The bound used to be read off the frames'
* own timestamps, and Chromium stamps a frame with when it began it: a frame begun just before Send
* and drawn after the line was in was left out as too early, and the next frame, a starved frame's
* length later, counted instead, so the more starved the frames, the later the line seemed.
* runner (eight files at once, Chromium and WebKit each).
*
* The next task is not always the page's next moment, though: after a click or a key, the browser
* draws first, and the task waits behind that frame, a starved frame's length on a loaded runner. A
* frame begins only once the page's task is over, so the first frame read once the line was in
* marks the page free just as well, and `read` takes whichever came first.
*
* The bound used to be read off the frames' own timestamps, and Chromium stamps a frame with when
* it began it: a frame begun just before Send and drawn after the line was in was left out as too
* early, and the next frame, a starved frame's length later, counted instead, so the more starved
* the frames, the later the line seemed.
*/
async function watchFrames(page: Page, by: By) {
await page.evaluate(
Expand Down Expand Up @@ -802,9 +809,21 @@ function read({
);
const since = (at: number | null) =>
at === null ? null : Math.round(at - sent);
// Free once the page took up its next task, or began its next frame if it drew first: either way
// the work it did once the line was in is over (see `watchFrames`).
const drawing =
laidOut === null
? undefined
: frames.find((frame) => frame.at >= laidOut)?.at;
const freed =
free === null
? (drawing ?? null)
: drawing === undefined
? free
: Math.min(free, drawing);
return {
laidOutAfterMs: since(laidOut),
freeAfterMs: since(free),
freeAfterMs: since(freed),
shownAfterMs: since(first?.at ?? null),
framesWithout: before
.slice(Math.max(from, 0))
Expand Down Expand Up @@ -889,6 +908,10 @@ describe.skipIf(!asked)(
expect(seen.shownAfterMs).not.toBeNull();
// The page's own part, strictly: in, and free to be drawn, within the bound. Every
// frame from then on shows it (`framesWithout`), however late the browser draws one.
if (ownWork(seen) > SHOWN_WITHIN_MS)
console.error(
`"Thinking" after Send: in at ${seen.laidOutAfterMs} ms, page free at ${seen.freeAfterMs} ms, first drawn at ${seen.shownAfterMs} ms`,
);
expect(ownWork(seen)).toBeLessThanOrEqual(SHOWN_WITHIN_MS);
expect(seen.framesWithout).toEqual([]);
expect(seen.goneWithWords).toBe(true);
Expand Down