send-many-64K-messages-with-backpressure.any.js (1498B)
1 // META: global=window,worker 2 // META: script=constants.sub.js 3 // META: timeout=long 4 // META: variant=?default 5 // META: variant=?wss 6 // META: variant=?wpt_flags=h2 7 8 // This is a repro for Chromium bug https://crbug.com/1286909. It will timeout 9 // if the bug is present. 10 11 // With 0.1 second server-side delay per message, sending 50 messages will take 12 // around 5 seconds. 13 const MESSAGES_TO_SEND = 50; 14 15 // 65536 is the magic number that triggers the bug, as it precisely fills the 16 // mojo pipe. 17 const MESSAGE_SIZE = 65536; 18 19 promise_test(async t => { 20 const message = new Uint8Array(MESSAGE_SIZE); 21 const ws = 22 new WebSocket(SCHEME_DOMAIN_PORT + '/receive-many-with-backpressure'); 23 let opened = false; 24 ws.onopen = t.step_func(() => { 25 opened = true; 26 for (let i = 0; i < MESSAGES_TO_SEND; i++) { 27 ws.send(message); 28 } 29 }); 30 let responsesReceived = 0; 31 ws.onmessage = t.step_func(({data}) => { 32 assert_equals(data, String(MESSAGE_SIZE), 'size must match'); 33 if (++responsesReceived == MESSAGES_TO_SEND) { 34 ws.close(); 35 } 36 }); 37 let resolvePromise; 38 const promise = new Promise(resolve => { 39 resolvePromise = resolve; 40 }); 41 ws.onclose = t.step_func(({wasClean}) => { 42 assert_true(opened, 'connection should have been opened'); 43 assert_true(wasClean, 'close should be clean'); 44 resolvePromise(); 45 }); 46 return promise; 47 }, 48 `sending ${MESSAGES_TO_SEND} messages of size ${MESSAGE_SIZE} with ` + 49 'backpressure applied should not hang');