1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -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 // eslint-disable-next-line @typescript-eslint/no-explicit-any
async write(msg: any): Promise<void> { 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); await Deno.writeAll(this.conn, encodedMsg);
} }
@ -270,7 +270,9 @@ export class SocketReporter implements Deno.TestReporter {
} }
async end(msg: Deno.TestEventEnd): Promise<void> { 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 // Wait for worker subprocess to go online
const conn = await listener.accept(); const conn = await listener.accept();
let err: Error | undefined = undefined;
let expectedPassedTests; let expectedPassedTests;
let endEvent; let endEvent;
@ -138,41 +137,25 @@ async function runTestsForPermissionSet(
if (msg.kind === Deno.TestEvent.Start) { if (msg.kind === Deno.TestEvent.Start) {
expectedPassedTests = msg.tests; expectedPassedTests = msg.tests;
await reporter.start(msg); await reporter.start(msg);
continue;
} else if (msg.kind === Deno.TestEvent.TestStart) { } else if (msg.kind === Deno.TestEvent.TestStart) {
await reporter.testStart(msg); await reporter.testStart(msg);
continue;
} else if (msg.kind === Deno.TestEvent.TestEnd) { } else if (msg.kind === Deno.TestEvent.TestEnd) {
await reporter.testEnd(msg); await reporter.testEnd(msg);
continue;
} else { } else {
endEvent = msg; endEvent = msg;
await reporter.end(msg); await reporter.end(msg);
break;
} }
} }
} catch (e) {
err = e;
} finally { } finally {
// Close socket to worker, it should shutdown gracefully. // Close socket to worker.
conn.close(); conn.close();
} }
if (err) { if (expectedPassedTests === undefined) {
if (err instanceof Deno.errors.ConnectionReset) {
if (!endEvent) {
throw err;
}
} else {
throw err;
}
}
if (typeof expectedPassedTests === "undefined") {
throw new Error("Worker runner didn't report start"); 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"); throw new Error("Worker runner didn't report end");
} }