Skip to content

Commit

Permalink
Add request timeout to license URL check (#1700)
Browse files Browse the repository at this point in the history
Resolves #1689

By default, Playwright limits each test to a 30s runtime. Unfortunately,
when the the test reaches its timeout, it displays an opaque error
message:
<img width="331" alt="Screen Shot 2023-12-05 at 14 42 47"
src="https://github.com/tiny-pilot/tinypilot/assets/6730025/e44424f0-89f3-4569-98b2-7dd3a8dde7ee">

In this case, the test timed out because one of the license URLs took
>30s to respond.

To avoid this issue, I've applied a 10s timeout to each license URL
check.

### Notes
1. I couldn't find a way to catch the actual test's
[TimeoutError](https://playwright.dev/docs/api/class-timeouterror) or
how to set a custom test timeout message 🤷‍♂️
2. I tested this PR via
    * #1701
    * #1702

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1700"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
  • Loading branch information
jdeanwallace authored Dec 8, 2023
1 parent 55c4b36 commit d3739b5
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions e2e/about.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,23 @@ test.describe("about dialog", () => {
const paths = await Promise.all(
links.map((link) => link.getAttribute("href"))
);
const responses = await Promise.all(
paths.map((path) => fetch(`${baseURL}${path}`))
const failedUrls = [];
await Promise.all(
paths
.map((path) => `${baseURL}${path}`)
.map((url) =>
fetch(url, { signal: AbortSignal.timeout(10000) })
.then((res) => {
if (res.status !== 200) {
failedUrls.push(url);
}
})
.catch(() => failedUrls.push(url))
)
);
const failedResponses = responses.filter((res) => res.status !== 200);
expect(
failedResponses.length,
`License link broken for URLs: ${failedResponses
.map((response) => response.url)
.join(", ")}`
failedUrls.length,
`License link broken for URLs: ${failedUrls.join(", ")}`
).toBe(0);
});
});

0 comments on commit d3739b5

Please sign in to comment.