stats.https.any.js (3976B)
1 // META: global=window,worker 2 // META: script=/common/get-host-info.sub.js 3 // META: script=resources/webtransport-test-helpers.sub.js 4 5 function validate_rtt_stats(stats) { 6 // The assumption below is that the RTT to localhost is under 5 seconds, 7 // which is fairly generous. 8 assert_greater_than(stats.minRtt, 0, "minRtt"); 9 assert_less_than(stats.minRtt, 5 * 1000, "minRtt"); 10 assert_greater_than(stats.smoothedRtt, 0, "smoothedRtt"); 11 assert_less_than(stats.smoothedRtt, 5 * 1000, "smoothedRtt"); 12 } 13 14 promise_test(async t => { 15 const wt = new WebTransport(webtransport_url('echo.py')); 16 await wt.ready; 17 const stats = await wt.getStats(); 18 validate_rtt_stats(stats); 19 assert_equals(stats.datagrams.expiredOutgoing, 0); 20 assert_equals(stats.datagrams.droppedIncoming, 0); 21 assert_equals(stats.datagrams.lostOutgoing, 0); 22 }, "WebTransport client should be able to provide stats after connection has been established"); 23 24 promise_test(async t => { 25 const wt = new WebTransport(webtransport_url('echo.py')); 26 await wt.ready; 27 wt.close(); 28 29 const stats = await wt.getStats(); 30 validate_rtt_stats(stats); 31 }, "WebTransport client should be able to provide stats after connection has been closed"); 32 33 promise_test(async t => { 34 const wt = new WebTransport(webtransport_url('echo.py')); 35 await wt.ready; 36 const statsPromise = wt.getStats(); 37 wt.close(); 38 39 const stats = await statsPromise; 40 validate_rtt_stats(stats); 41 }, "WebTransport client should be able to provide stats requested right before connection has been closed"); 42 43 promise_test(async t => { 44 const wt = new WebTransport(webtransport_url('echo.py')); 45 const stats = await wt.getStats(); 46 validate_rtt_stats(stats); 47 }, "WebTransport client should be able to provide valid stats when requested before connection established"); 48 49 promise_test(async t => { 50 const wt = new WebTransport("https://webtransport.invalid/"); 51 wt.ready.catch(e => {}); 52 wt.closed.catch(e => {}); 53 const error = await wt.getStats().catch(e => e); 54 assert_equals(error.code, DOMException.INVALID_STATE_ERR); 55 const error2 = await wt.getStats().catch(e => e); 56 assert_equals(error2.code, DOMException.INVALID_STATE_ERR); 57 }, "WebTransport client should throw an error when stats are requested for a failed connection"); 58 59 promise_test(async t => { 60 const wt = new WebTransport(webtransport_url('echo.py')); 61 await wt.ready; 62 const stats1 = wt.getStats(); 63 const stats2 = wt.getStats(); 64 assert_true(stats1 != stats2, "different promise returned for different getStats() calls"); 65 validate_rtt_stats(await stats1); 66 validate_rtt_stats(await stats2); 67 }, "WebTransport client should be able to handle multiple concurrent stats requests"); 68 69 promise_test(async t => { 70 const wt = new WebTransport(webtransport_url('echo.py')); 71 await wt.ready; 72 const stats1 = await wt.getStats(); 73 validate_rtt_stats(stats1); 74 const stats2 = await wt.getStats(); 75 validate_rtt_stats(stats2); 76 }, "WebTransport client should be able to handle multiple sequential stats requests"); 77 78 promise_test(async t => { 79 const wt = new WebTransport(webtransport_url('echo.py')); 80 await wt.ready; 81 82 const numDatagrams = 64; 83 wt.datagrams.incomingHighWaterMark = 4; 84 85 const writer = wt.datagrams.writable.getWriter(); 86 const encoder = new TextEncoder(); 87 const promises = []; 88 while (promises.length < numDatagrams) { 89 const token = promises.length.toString(); 90 promises.push(writer.write(encoder.encode(token))); 91 } 92 await Promise.all(promises); 93 94 const maxAttempts = 40; 95 let stats; 96 for (let i = 0; i < maxAttempts; i++) { 97 wait(50); 98 stats = await wt.getStats(); 99 if (stats.datagrams.droppedIncoming > 0) { 100 break; 101 } 102 } 103 assert_greater_than(stats.datagrams.droppedIncoming, 0); 104 assert_less_than_equal(stats.datagrams.droppedIncoming, 105 numDatagrams - wt.datagrams.incomingHighWaterMark); 106 }, "WebTransport client should be able to provide droppedIncoming values for datagrams");