ci: try to fix request timeouts (#11190)
This commit is contained in:
parent
00ef6d7fce
commit
11da21cac2
1
.github/workflows/changed-packages.yml
vendored
1
.github/workflows/changed-packages.yml
vendored
@ -38,6 +38,7 @@ jobs:
|
|||||||
- 'packages/browsers/src/browser-data/firefox.ts'
|
- 'packages/browsers/src/browser-data/firefox.ts'
|
||||||
- 'packages/puppeteer/**'
|
- 'packages/puppeteer/**'
|
||||||
- 'packages/puppeteer-core/**'
|
- 'packages/puppeteer-core/**'
|
||||||
|
- 'packages/testserver/**'
|
||||||
- 'docker/**'
|
- 'docker/**'
|
||||||
- 'test/**'
|
- 'test/**'
|
||||||
- 'test-d/**'
|
- 'test-d/**'
|
||||||
|
@ -66,6 +66,7 @@ export class TestServer {
|
|||||||
#csp = new Map<string, string>();
|
#csp = new Map<string, string>();
|
||||||
#gzipRoutes = new Set<string>();
|
#gzipRoutes = new Set<string>();
|
||||||
#requestSubscribers = new Map<string, Subscriber>();
|
#requestSubscribers = new Map<string, Subscriber>();
|
||||||
|
#requests = new Set<ServerResponse>();
|
||||||
|
|
||||||
static async create(dirPath: string): Promise<TestServer> {
|
static async create(dirPath: string): Promise<TestServer> {
|
||||||
let res!: (value: unknown) => void;
|
let res!: (value: unknown) => void;
|
||||||
@ -192,12 +193,20 @@ export class TestServer {
|
|||||||
subscriber.reject.call(undefined, error);
|
subscriber.reject.call(undefined, error);
|
||||||
}
|
}
|
||||||
this.#requestSubscribers.clear();
|
this.#requestSubscribers.clear();
|
||||||
|
for (const request of this.#requests.values()) {
|
||||||
|
if (!request.writableEnded) {
|
||||||
|
request.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.#requests.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
#onRequest: RequestListener = (
|
#onRequest: RequestListener = (
|
||||||
request: TestIncomingMessage,
|
request: TestIncomingMessage,
|
||||||
response
|
response
|
||||||
): void => {
|
): void => {
|
||||||
|
this.#requests.add(response);
|
||||||
|
|
||||||
request.on('error', (error: {code: string}) => {
|
request.on('error', (error: {code: string}) => {
|
||||||
if (error.code === 'ECONNRESET') {
|
if (error.code === 'ECONNRESET') {
|
||||||
response.end();
|
response.end();
|
||||||
@ -271,6 +280,12 @@ export class TestServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
readFile(filePath, (err, data) => {
|
readFile(filePath, (err, data) => {
|
||||||
|
// This can happen if the request is not awaited but started
|
||||||
|
// in the test and get clean via `reset()`
|
||||||
|
if (response.writableEnded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
response.statusCode = 404;
|
response.statusCode = 404;
|
||||||
response.end(`File not found: ${filePath}`);
|
response.end(`File not found: ${filePath}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user