Skip to content

Commit ecfa0f4

Browse files
committed
test(org): settle on the page's own reads
Router prefetches, static chunks and the analytics host kept pages from going quiet, and a request a navigation cancelled could stay out across routes. Those no longer count; a data read still does, and settle still fails at its deadline.
1 parent f7649ee commit ecfa0f4

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

‎apps/sim/scripts/org-redesign-e2e/harness.ts‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ export function refused(status: number, method: string, path: string) {
213213
return new RegExp(`^http \\S+ ${status} ${method} ${escapeRegExp(path)}${query}$`)
214214
}
215215

216+
/**
217+
* A read this page is waiting on. Router prefetches, static chunks and other hosts come and go on
218+
* their own schedule, and no check reasons about them.
219+
*/
220+
function isPageRead(request: Request) {
221+
if (request.resourceType() === 'eventsource' || !isSameOrigin(request.url())) return false
222+
if (new URL(request.url()).pathname.startsWith('/_next/static/')) return false
223+
return request.headers()['next-router-prefetch'] === undefined
224+
}
225+
216226
class Session {
217227
private readonly inflight = new Set<Request>()
218228
private lastActivity = Date.now()
@@ -239,8 +249,13 @@ class Session {
239249
})
240250
page.on('request', (request) => {
241251
if (HIGH_VOLUME_REQUEST.test(request.url())) return
242-
if (request.resourceType() !== 'eventsource') this.inflight.add(request)
243-
this.lastActivity = Date.now()
252+
// A navigation does not report every request it cancels, and none of them still matters.
253+
if (request.isNavigationRequest() && request.frame() === page.mainFrame())
254+
this.inflight.clear()
255+
if (isPageRead(request)) {
256+
this.inflight.add(request)
257+
this.lastActivity = Date.now()
258+
}
244259
if (isSameOrigin(request.url()))
245260
this.requests.push({
246261
method: request.method(),
@@ -249,8 +264,7 @@ class Session {
249264
})
250265
})
251266
const settled = (request: Request) => {
252-
this.inflight.delete(request)
253-
this.lastActivity = Date.now()
267+
if (this.inflight.delete(request)) this.lastActivity = Date.now()
254268
}
255269
page.on('requestfinished', settled)
256270
page.on('requestfailed', (request) => {
@@ -278,8 +292,9 @@ class Session {
278292
}
279293

280294
/**
281-
* Quiet for 400ms, ignoring the SSE and socket connections that never finish. Fails at its
282-
* deadline, naming what is still out, because every caller goes on to reason about a quiet page.
295+
* Quiet for 400ms on the page's own reads (`isPageRead`), ignoring the SSE and socket connections
296+
* that never finish. Fails at its deadline, naming what is still out, because every caller goes on
297+
* to reason about a quiet page.
283298
*/
284299
async settle(maxMs = 8_000) {
285300
const deadline = Date.now() + maxMs

0 commit comments

Comments
 (0)