Skip to content

Commit

Permalink
Timeout on test fetches
Browse files Browse the repository at this point in the history
  • Loading branch information
mnot committed Dec 26, 2023
1 parent fd6777d commit 7d09ad3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions test-engine/client/config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export let fetch = null
export let useBrowserCache = false
export let baseUrl = ''
export const requestTimeout = 10 // seconds

export function setFetch (call) {
if (call !== undefined) {
Expand Down
13 changes: 13 additions & 0 deletions test-engine/client/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@ export function makeTest (test) {
prevRes = Object.fromEntries(responses[i - 1].headers)
}
const init = fetching.init(idx, reqConfig, prevRes)
const controller = new AbortController()
const timeout = setTimeout(() => {
controller.abort()
}, config.requestTimeout * 1000)
init.signal = controller.signal
if (test.dump === true) clientUtils.logRequest(url, init, reqNum)
return config.fetch(url, init)
.then(response => {
responses.push(response)
return checkResponse(test, requests, idx, response)
})
.finally(() => {
clearTimeout(timeout)
})
},
pauseAfter: 'pause_after' in requests[i]
})
Expand All @@ -55,6 +63,7 @@ export function makeTest (test) {
}

return clientUtils.putTestConfig(uuid, requests)
.catch(handleError)
.then(runNextStep)
.then(() => {
return clientUtils.getServerState(uuid)
Expand Down Expand Up @@ -288,3 +297,7 @@ function checkServerRequests (requests, responses, serverState) {
}
}
}

function handleError (err) {
console.error(`ERROR: ${err}`)
}

0 comments on commit 7d09ad3

Please sign in to comment.