backpressure-send.any.js (1005B)
1 // META: script=../../constants.sub.js 2 // META: script=resources/url-constants.js 3 // META: global=window,worker 4 // META: timeout=long 5 // META: variant=?wss 6 // META: variant=?wpt_flags=h2 7 8 // Allow for this much timer jitter. 9 const JITTER_ALLOWANCE_MS = 200; 10 11 // The amount of buffering a WebSocket connection has is not standardised, but 12 // it's reasonable to expect that it will not be as large as 8MB. 13 const MESSAGE_SIZE = 8 * 1024 * 1024; 14 15 // In this test, the server WebSocket handler waits 2 seconds, and the browser 16 // times how long it takes to send the first message. 17 promise_test(async t => { 18 const wss = new WebSocketStream(`${BASEURL}/receive-backpressure`); 19 const { writable } = await wss.opened; 20 const writer = writable.getWriter(); 21 const start = performance.now(); 22 await writer.write(new Uint8Array(MESSAGE_SIZE)); 23 const elapsed = performance.now() - start; 24 assert_greater_than_equal(elapsed, 2000 - JITTER_ALLOWANCE_MS); 25 }, 'backpressure should be applied to sent messages');