50 lines
2.6 KiB
JavaScript
50 lines
2.6 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { Worker } from "node:worker_threads";
|
|
import { pathToFileURL } from "node:url";
|
|
|
|
const root = path.resolve(path.dirname(new URL(import.meta.url).pathname), "..");
|
|
const facadePath = path.resolve(process.argv[2]);
|
|
const build = path.resolve(process.argv[3]);
|
|
const facade = await import(pathToFileURL(facadePath));
|
|
const envelopePath = path.join(path.dirname(facadePath), "facade-envelope.js");
|
|
const envelope = await import(pathToFileURL(envelopePath));
|
|
const worker = new Worker(new URL("./surface-inspect-facade-smoke-worker.mjs", import.meta.url), { workerData: { facadePath, envelopePath, build } });
|
|
const pending = new Map();
|
|
const events = [];
|
|
worker.on("message", (message) => {
|
|
events.push(message.kind === "ready" ? "ready" : `${message.kind}:${message.requestId}`);
|
|
if (message.requestId && pending.has(message.requestId)) {
|
|
pending.get(message.requestId)(message);
|
|
pending.delete(message.requestId);
|
|
}
|
|
});
|
|
const waitFor = (id) => new Promise((resolve) => pending.set(id, resolve));
|
|
const ready = await new Promise((resolve) => worker.once("message", resolve));
|
|
assert.equal(ready.kind, "ready");
|
|
const send = (request) => { const response = waitFor(request.requestId); worker.postMessage(request); return response; };
|
|
|
|
const success = await send(facade.createSurfaceInspectRequest("sur-act02-e-success"));
|
|
const expected = await send(facade.createSurfaceInspectRequest("sur-act02-e-error", { ...facade.SURFACE_INSPECT_FIXTURE, sourceEntry: "src/Mod/Surface/App/Missing.cpp" }));
|
|
const duplicate = await send(facade.createSurfaceInspectRequest("sur-act02-e-success"));
|
|
const cancel = facade.createSurfaceInspectRequest("sur-act02-e-cancel");
|
|
const cancelledPromise = send(cancel);
|
|
worker.postMessage(envelope.createCancel("sur-act02-cancel-msg", cancel.requestId));
|
|
const cancelled = await cancelledPromise;
|
|
const after = await send(facade.createSurfaceInspectRequest("sur-act02-e-after"));
|
|
await worker.terminate();
|
|
console.error(JSON.stringify({ success, expected, duplicate, cancelled, after, events }));
|
|
|
|
assert.equal(success.kind, "result");
|
|
assert.equal(success.result.registeredTypeCount, 7);
|
|
assert.equal(expected.kind, "error");
|
|
assert.equal(expected.error.code, "revision_mismatch");
|
|
assert.equal(duplicate.kind, "error");
|
|
assert.equal(duplicate.error.code, "duplicate_request");
|
|
assert.equal(cancelled.kind, "error");
|
|
assert.equal(cancelled.error.code, "cancelled");
|
|
assert.equal(after.kind, "result");
|
|
assert.deepEqual(after.result, success.result);
|
|
console.log(JSON.stringify({ result: "pass", events, responses: 5 }));
|