1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-26 17:19:06 -05:00

Fix unit test runner ConnectionReset bug (#4424)

Fixes: #4373
This commit is contained in:
Bert Belder 2020-03-18 12:08:06 -07:00
parent da8cb408c8
commit 070464e2cc
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461
2 changed files with 11 additions and 26 deletions

View file

@ -244,7 +244,7 @@ export class SocketReporter implements Deno.TestReporter {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async write(msg: any): Promise<void> {
const encodedMsg = this.encoder.encode(`${JSON.stringify(msg)}\n`);
const encodedMsg = this.encoder.encode(JSON.stringify(msg) + "\n");
await Deno.writeAll(this.conn, encodedMsg);
}
@ -270,7 +270,9 @@ export class SocketReporter implements Deno.TestReporter {
}
async end(msg: Deno.TestEventEnd): Promise<void> {
await this.write(msg);
const encodedMsg = this.encoder.encode(JSON.stringify(msg));
await Deno.writeAll(this.conn, encodedMsg);
this.conn.closeWrite();
}
}

View file

@ -127,7 +127,6 @@ async function runTestsForPermissionSet(
// Wait for worker subprocess to go online
const conn = await listener.accept();
let err: Error | undefined = undefined;
let expectedPassedTests;
let endEvent;
@ -138,41 +137,25 @@ async function runTestsForPermissionSet(
if (msg.kind === Deno.TestEvent.Start) {
expectedPassedTests = msg.tests;
await reporter.start(msg);
continue;
} else if (msg.kind === Deno.TestEvent.TestStart) {
await reporter.testStart(msg);
continue;
} else if (msg.kind === Deno.TestEvent.TestEnd) {
await reporter.testEnd(msg);
continue;
} else {
endEvent = msg;
await reporter.end(msg);
break;
}
}
} catch (e) {
err = e;
} finally {
// Close socket to worker, it should shutdown gracefully.
// Close socket to worker.
conn.close();
}
if (err) {
if (err instanceof Deno.errors.ConnectionReset) {
if (!endEvent) {
throw err;
}
} else {
throw err;
}
}
if (typeof expectedPassedTests === "undefined") {
if (expectedPassedTests === undefined) {
throw new Error("Worker runner didn't report start");
}
if (typeof endEvent === "undefined") {
if (endEvent === undefined) {
throw new Error("Worker runner didn't report end");
}
@ -274,11 +257,11 @@ Run worker process for given permissions:
OPTIONS:
--master
--master
Run in master mode, spawning worker processes for
each discovered permission combination
--worker
--worker
Run in worker mode, requires "perms" and "addr" flags,
should be run with "-A" flag; after setup worker will
drop permissions to required set specified in "perms"
@ -290,7 +273,7 @@ OPTIONS:
Address of TCP socket for reporting
ARGS:
-- <filter>...
-- <filter>...
Run only tests with names matching filter, must
be used after "--"
`;