tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

backpressure-receive.any.js (1541B)


      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 const LARGE_MESSAGE_COUNT = 16;
     11 
     12 // This test works by using a server WebSocket handler which sends a large
     13 // message, and then sends a second message with the time it measured the first
     14 // message taking. On the browser side, we wait 2 seconds before reading from
     15 // the socket. This should ensure it takes at least 2 seconds to finish sending
     16 // the large message.
     17 promise_test(async t => {
     18  const wss = new WebSocketStream(`${BASEURL}/send-backpressure`);
     19  const { readable } = await wss.opened;
     20  const reader = readable.getReader();
     21 
     22  // Create backpressure for 2 seconds.
     23  await new Promise(resolve => t.step_timeout(resolve, 2000));
     24 
     25  // Skip the empty message used to fill the readable queue.
     26  await reader.read();
     27 
     28  // Skip the large messages.
     29  for (let i = 0; i < LARGE_MESSAGE_COUNT; ++i) {
     30    await reader.read();
     31  }
     32 
     33  // Read the time it took.
     34  const { value, done } = await reader.read();
     35 
     36  // A browser can pass this test simply by being slow. This may be a source of
     37  // flakiness for browsers that do not implement backpressure properly.
     38  assert_greater_than_equal(Number(value), 2 - JITTER_ALLOWANCE_MS / 1000,
     39                            'data send should have taken at least 2 seconds');
     40 }, 'backpressure should be applied to received messages');