diff --git a/testing/web-platform/tests/websockets/handlers/send-backpressure_wsh.py b/testing/web-platform/tests/websockets/handlers/send-backpressure_wsh.py index fe69b8f9c017..c57b997b7efb 100755 --- a/testing/web-platform/tests/websockets/handlers/send-backpressure_wsh.py +++ b/testing/web-platform/tests/websockets/handlers/send-backpressure_wsh.py @@ -2,13 +2,18 @@ import time -# The amount of buffering a WebSocket connection has is not standardised, but -# it's reasonable to expect that it will not be as large as 8MB. -MESSAGE_SIZE = 8 * 1024 * 1024 +# The amount of internal buffering a WebSocket connection has is not +# standardised, and varies depending upon the OS. Setting this number too small +# will result in false negatives, as the entire message gets buffered. Setting +# this number too large will result in false positives, when it takes more than +# 2 seconds to transmit the message anyway. This number was arrived at by +# trial-and-error. +MESSAGE_SIZE = 16 * 1024 * 1024 def web_socket_do_extra_handshake(request): - # Turn off permessage-deflate, otherwise it shrinks our 8MB buffer to 8KB. + # Turn off permessage-deflate, otherwise it shrinks our big message to a + # tiny message. request.ws_extension_processors = [] diff --git a/testing/web-platform/tests/websockets/stream-tentative/backpressure-receive.any.js b/testing/web-platform/tests/websockets/stream-tentative/backpressure-receive.any.js index 11f4bd9d3501..b4b090958818 100644 --- a/testing/web-platform/tests/websockets/stream-tentative/backpressure-receive.any.js +++ b/testing/web-platform/tests/websockets/stream-tentative/backpressure-receive.any.js @@ -3,11 +3,14 @@ // META: global=window,worker // META: timeout=long -// This test works by using a server WebSocket handler which sends an 8MB +// Allow for this much timer jitter. +const JITTER_ALLOWANCE_MS = 200; + +// This test works by using a server WebSocket handler which sends a large // message, and then sends a second message with the time it measured the first // message taking. On the browser side, we wait 2 seconds before reading from // the socket. This should ensure it takes at least 2 seconds to finish sending -// the 8MB message. +// the large message. promise_test(async t => { const wss = new WebSocketStream(`${BASEURL}/send-backpressure`); const { readable } = await wss.connection; @@ -16,7 +19,7 @@ promise_test(async t => { // Create backpressure for 2 seconds. await new Promise(resolve => t.step_timeout(resolve, 2000)); - // Skip the 8MB message. + // Skip the large message. await reader.read(); // Read the time it took. @@ -24,6 +27,6 @@ promise_test(async t => { // A browser can pass this test simply by being slow. This may be a source of // flakiness for browsers that do not implement backpressure properly. - assert_greater_than_equal(Number(value), 2, + assert_greater_than_equal(Number(value), 2 - JITTER_ALLOWANCE_MS / 1000, 'data send should have taken at least 2 seconds'); }, 'backpressure should be applied to received messages');