Repository navigation
Track fetch() and stop waiting for requests after 15 s - #574
Merged
Merged
Conversation
- fetch() is tracked like XMLHttpRequest: the same trackMethods (GET by default), restartOnRequestAfter, ignoreURLs, Pace.ignore and Pace.track. Pace replaces window.fetch with a function that calls the original with the same this and arguments, never reads or copies a Request's body, and returns a promise that settles like the original's, so unhandled rejections are still reported. A fetch ends when that promise settles (on the response's headers, an error or an abort), since its body's progress can't be seen without reading it. ajax.trackFetch: false turns it off. - ajax.maxWait (15000 ms by default): pace waits for each tracked request, WebSocket and request forced with Pace.track at most that long from when it was sent, then stops waiting for it for good. The request keeps going. Before, one request that never ended held the bar near 100% forever. false, or anything other than a number from 0 to 2^31 - 1 ms (the most a timer can wait; setTimeout treats Infinity, null and larger numbers as 0), means no limit. - ajax.ignoreURLs patterns see the URL as the page wrote it, the full URL, and for requests to the page's own origin the part after the origin (/api/items?page=2), so a pattern matches however the URL was written: relative or absolute, a string, a URL or a Request. An XMLHttpRequest's URL is read when open() uses it. The real server the request tests use moves into the test fixtures, with endpoints for responses that arrive in parts, requests that never end and WebSocket handshakes that are never answered. The ajax rule tests now run for both XMLHttpRequest and fetch.
The two tests that run the page's fake clock for 15 and 60 seconds ran every timer and animation frame on the way, which took about 4 and 17 seconds of real time. They now run the clock only around the moments that matter and jump over the rest with fastForward(), so each takes about half a second and still fails if maxWait isn't applied or false doesn't turn it off.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tracks
fetch()requests and stops pace from waiting forever for a request that never ends.fetch()is tracked by default, with the same rules asXMLHttpRequest(trackMethods,restartOnRequestAfter,ignoreURLs,Pace.ignore,Pace.track). A fetch ends when its promise settles, on the response's headers, so a streaming body doesn't hold the bar. Pace's wrapper passesthisand the arguments through unchanged, never touches aRequest's body, and returns a promise that behaves like the native one.ajax: { trackFetch: false }turns it off.ajax.maxWait(15000 ms by default): pace waits for each request at most that long after it was sent, then stops waiting for it. The request itself keeps going. Before, a request that never ended held the bar near 100% forever, and a WebSocket that never connected held it until the browser gave up (minutes in Chrome, never in Safari).falseturns the limit off.ajax.ignoreURLspatterns see the URL as the page wrote it, the full URL, and for same-origin requests the part after the origin (/api/items?page=2), so a pattern matches however the request's URL was written.The README documents all three, plus a note that long polling and slow background requests such as prefetching need
ignoreURLs.Tests: new
fetch.spec.mjsandmax-wait.spec.mjs, the ajax rule tests run for bothXMLHttpRequestandfetch, and the request tests share one real local server (for responses in parts, requests that never end, and WebSocket handshakes). Each new behavior has a test that fails against the previouspace.jsin Chromium, Firefox and WebKit; the others check that fetch keeps behaving like the native one.