Skip to content

Commit

Permalink
fix(tests): Fixed flacky worker test case (#318)
Browse files Browse the repository at this point in the history
* fix(tests): Fixed flacky worker test case

* refactor: made use of deferred
  • Loading branch information
lucsoft authored Dec 16, 2021
1 parent 655e207 commit 524e67d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
22 changes: 5 additions & 17 deletions tests/cases/07_worker.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
import { assert } from "../test.deps.ts";
import { assertEquals, deferred } from "../test.deps.ts";

export default function workerTests() {
Deno.test({
name: "WORKER: Deno does not throw when deno_mongo is imported in worker",
fn: async function () {
let workerFinished: (p: void | PromiseLike<void>) => void;

const p = new Promise<void>((resolve, _reject) => {
workerFinished = resolve;
});

fn: async () => {
const importWorker = new Worker(
new URL("import_worker.ts", import.meta.url).href,
{ type: "module" },
);

importWorker.onmessage = (_e) => {
workerFinished();
};

const p = deferred<string>();
importWorker.onmessage = (e) => p.resolve(e.data);
importWorker.postMessage("startWorker");

await p;

assert(true);
assertEquals(await p, "done");
},
});
}
1 change: 1 addition & 0 deletions tests/test.deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export {
assertThrows,
} from "https://deno.land/std@0.117.0/testing/asserts.ts";
export * as semver from "https://deno.land/x/semver@v1.4.0/mod.ts";
export { deferred } from "https://deno.land/std/async/mod.ts";

0 comments on commit 524e67d

Please sign in to comment.