Skip to content

Commit 7d09ad3

Browse files
committed
Timeout on test fetches
1 parent fd6777d commit 7d09ad3

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

test-engine/client/config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export let fetch = null
22
export let useBrowserCache = false
33
export let baseUrl = ''
4+
export const requestTimeout = 10 // seconds
45

56
export function setFetch (call) {
67
if (call !== undefined) {

test-engine/client/test.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,20 @@ export function makeTest (test) {
2828
prevRes = Object.fromEntries(responses[i - 1].headers)
2929
}
3030
const init = fetching.init(idx, reqConfig, prevRes)
31+
const controller = new AbortController()
32+
const timeout = setTimeout(() => {
33+
controller.abort()
34+
}, config.requestTimeout * 1000)
35+
init.signal = controller.signal
3136
if (test.dump === true) clientUtils.logRequest(url, init, reqNum)
3237
return config.fetch(url, init)
3338
.then(response => {
3439
responses.push(response)
3540
return checkResponse(test, requests, idx, response)
3641
})
42+
.finally(() => {
43+
clearTimeout(timeout)
44+
})
3745
},
3846
pauseAfter: 'pause_after' in requests[i]
3947
})
@@ -55,6 +63,7 @@ export function makeTest (test) {
5563
}
5664

5765
return clientUtils.putTestConfig(uuid, requests)
66+
.catch(handleError)
5867
.then(runNextStep)
5968
.then(() => {
6069
return clientUtils.getServerState(uuid)
@@ -288,3 +297,7 @@ function checkServerRequests (requests, responses, serverState) {
288297
}
289298
}
290299
}
300+
301+
function handleError (err) {
302+
console.error(`ERROR: ${err}`)
303+
}

0 commit comments

Comments
 (0)