Skip to content

Commit

Permalink
Fix unit test runner ConnectionReset bug (#4424)
Browse files Browse the repository at this point in the history
Fixes: #4373
  • Loading branch information
piscisaureus committed Mar 18, 2020
1 parent da8cb40 commit b79ab9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
6 changes: 4 additions & 2 deletions cli/js/tests/test_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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();
}
}

Expand Down
33 changes: 8 additions & 25 deletions cli/js/tests/unit_test_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function spawnWorkerRunner(
args.push(filter);
}

const ioMode = verbose ? "inherit" : "null";
const ioMode = verbose ? "inherit" : "inherit";

const p = Deno.run({
args,
Expand All @@ -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;

Expand All @@ -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");
}

Expand Down Expand Up @@ -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"
Expand All @@ -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 "--"
`;
Expand Down

0 comments on commit b79ab9e

Please sign in to comment.