From d3739b57953ba89672a6f1c74b1f32dd2dfab077 Mon Sep 17 00:00:00 2001 From: Jason Wallace Date: Fri, 8 Dec 2023 13:35:29 +0200 Subject: [PATCH] Add request timeout to license URL check (#1700) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves https://github.com/tiny-pilot/tinypilot/issues/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: Screen Shot 2023-12-05 at 14 42 47 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 * https://github.com/tiny-pilot/tinypilot/pull/1701 * https://github.com/tiny-pilot/tinypilot/pull/1702 Review
on CodeApprove --- e2e/about.spec.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/e2e/about.spec.js b/e2e/about.spec.js index ac8331b9a..1ceb73756 100644 --- a/e2e/about.spec.js +++ b/e2e/about.spec.js @@ -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); }); });