abort-keepalive.any.js (1546B)
1 // META: timeout=long 2 // META: global=worker 3 // META: script=/common/utils.js 4 // META: script=/common/get-host-info.sub.js 5 // META: script=/fetch/api/request/request-error.js 6 7 // this adopted from fetch keepalive abort test for windows from /fetch/api/abort/keepalive.html 8 async function fetchJson(url) { 9 const response = await fetch(url); 10 assert_true(response.ok, 'response should be ok'); 11 return response.json(); 12 } 13 14 promise_test(async () => { 15 const stateKey = token(); 16 const controller = new AbortController(); 17 // infinites-slow-response writes a response to the client until client closes connection 18 // or it receives the abortKey. In our case the we expect the connection to be closed from client, 19 // i.e. the fetch keep-alive request is aborted. 20 21 await fetch(`/fetch/api/resources/infinite-slow-response.py?stateKey=${stateKey}`, 22 { 23 signal: controller.signal, 24 keepalive: true 25 }); 26 const before = await fetchJson(`/fetch/api/resources/stash-take.py?key=${stateKey}`); 27 assert_equals(before, 'open', 'connection should be open'); 28 29 controller.abort(); 30 31 // Spin until the abort completes. 32 while (true) { 33 const after = await fetchJson(`/fetch/api/resources/stash-take.py?key=${stateKey}`); 34 if (after) { 35 // stateKey='open' was removed from the dictionary by the first fetch of 36 // stash-take.py, so we should only ever see the value 'closed' here. 37 assert_equals(after, 'closed', 'connection should have closed'); 38 break; 39 } 40 } 41 }, 'aborting a keepalive worker should work');