Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added ava-force-exit.js
Empty file.
9 changes: 9 additions & 0 deletions ava-force-exit.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import process from 'node:process';
import { registerCompletionHandler } from 'ava';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ava says to do this in the docs, and I can see the export in the code. But at runtime I'm told that registerCompletionHandler does not exist!


// For ava 6.0+
// See https://github.com/avajs/ava/blob/main/docs/08-common-pitfalls.md#timeouts-because-a-file-failed-to-exit
// It might be better to do this on a per test basis
registerCompletionHandler(() => {
process.exit();
});
9 changes: 6 additions & 3 deletions ava.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const semver = require("semver")

const loader_arg = semver.lte(process.version, 'v20.5.0') ? '--loader=@swc-node/register/esm' : '--import=@swc-node/register/esm-register'
const semver = require('semver');
const path = require('node:path');
const loader_arg = semver.lte(process.version, 'v20.5.0')
? '--loader=@swc-node/register/esm'
: '--import=@swc-node/register/esm-register';
module.exports = {
extensions: {
ts: 'module',
Expand All @@ -17,4 +19,5 @@ module.exports = {
],

files: ['test/**/*test.ts'],
// require: [path.resolve('../../ava-force-exit.mjs')],
};
4 changes: 2 additions & 2 deletions integration-tests/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"@openfn/lightning-mock": "workspace:^",
"@openfn/project": "workspace:*",
"@types/node": "^18.19.127",
"ava": "5.3.1",
"ava": "7.0.0",
"date-fns": "^2.30.0",
"rimraf": "^6.0.1",
"rimraf": "^6.1.3",
"tslib": "^2.8.1",
"typescript": "^5.9.2"
},
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/execute/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
},
"dependencies": {
"@openfn/compiler": "workspace:^",
"@openfn/language-common": "2.0.1",
"@openfn/language-common": "3.2.3",
"@openfn/language-http": "6.4.3",
"@openfn/runtime": "workspace:^",
"@types/node": "^18.19.127",
"ava": "5.3.1",
"ava": "7.0.0",
"date-fns": "^2.30.0",
"rimraf": "^3.0.2",
"rimraf": "^6.1.3",
"tslib": "^2.8.1",
"typescript": "^5.9.2"
},
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"@openfn/ws-worker": "workspace:^",
"@types/node": "^18.19.127",
"@types/rimraf": "^3.0.2",
"ava": "5.3.1",
"ava": "7.0.0",
"date-fns": "^2.30.0",
"koa": "^2.16.2",
"rimraf": "^3.0.2",
"rimraf": "^6.1.3",
"tslib": "^2.8.1",
"typescript": "^5.9.2"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@types/tar-stream": "^2.2.3",
"gunzip-maybe": "^1.4.2",
"prettier": "^2.8.8",
"rimraf": "^3.0.2",
"rimraf": "^6.1.3",
"semver": "^7.7.2",
"tar-stream": "^3.1.7",
"typesync": "^0.13.4"
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@
"license": "ISC",
"devDependencies": {
"@openfn/language-collections": "^0.6.2",
"@openfn/language-common": "2.0.0-rc3",
"@openfn/language-common": "3.2.3",
"@types/mock-fs": "^4.13.4",
"@types/node": "^18.19.127",
"@types/rimraf": "^3.0.2",
"@types/treeify": "^1.0.3",
"@types/ws": "^8.18.1",
"@types/yargs": "^17.0.33",
"ava": "5.3.1",
"ava": "7.0.0",
"lodash-es": "^4.17.21",
"mock-fs": "^5.5.0",
"tslib": "^2.8.1",
"tsup": "^7.2.0",
"tsup": "^8.5.1",
"typescript": "^5.9.2"
},
"dependencies": {
Expand All @@ -61,9 +61,9 @@
"dotenv": "^17.2.3",
"dotenv-expand": "^12.0.3",
"figures": "^5.0.0",
"rimraf": "^6.0.1",
"rimraf": "^6.1.3",
"treeify": "^1.1.0",
"undici": "7.12.0",
"undici": "7.24.4",
"ws": "^8.18.3",
"yargs": "^17.7.2"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
"devDependencies": {
"@types/node": "^18.19.127",
"@types/yargs": "^17.0.33",
"ava": "5.3.1",
"ava": "7.0.0",
"tslib": "^2.8.1",
"tsup": "^7.2.0",
"tsup": "^8.5.1",
"typescript": "^5.9.2",
"yargs": "^17.7.2"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/deploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"@types/jsonpath": "^0.2.4",
"@types/mock-fs": "^4.13.4",
"@types/node": "^18.19.127",
"ava": "5.3.1",
"jsonpath": "^1.1.1",
"ava": "7.0.0",
"jsonpath": "^1.3.0",
"mock-fs": "^5.5.0",
"tslib": "^2.8.1",
"tsup": "^7.2.0",
"tsup": "^8.5.1",
"typescript": "^5.9.2"
},
"files": [
Expand Down
8 changes: 4 additions & 4 deletions packages/describe-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@
},
"keywords": [],
"devDependencies": {
"@openfn/language-common": "2.0.1",
"@openfn/language-common": "3.2.3",
"@types/node": "^18.19.127",
"@types/node-localstorage": "^1.3.3",
"@types/rimraf": "^3.0.2",
"ava": "5.3.1",
"ava": "7.0.0",
"esbuild": "^0.18.20",
"rimraf": "^3.0.2",
"rimraf": "^6.1.3",
"threads": "1.7.0",
"tslib": "^2.8.1",
"tsm": "^2.3.0",
"tsup": "^7.2.0"
"tsup": "^8.5.1"
},
"files": [
"dist",
Expand Down
6 changes: 3 additions & 3 deletions packages/engine-multi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"license": "ISC",
"dependencies": {
"@openfn/compiler": "workspace:*",
"@openfn/language-common": "2.0.0-rc3",
"@openfn/language-common": "3.2.3",
"@openfn/lexicon": "workspace:^",
"@openfn/logger": "workspace:*",
"@openfn/runtime": "workspace:*",
Expand All @@ -25,10 +25,10 @@
},
"devDependencies": {
"@types/node": "^18.19.127",
"ava": "5.3.1",
"ava": "7.0.0",
"tslib": "^2.8.1",
"tsm": "^2.3.0",
"tsup": "^7.2.0",
"tsup": "^8.5.1",
"tsx": "^4.20.5",
"typescript": "^5.9.2"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/lightning-mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"@types/ws": "^8.18.1",
"fast-safe-stringify": "^2.1.1",
"jose": "^4.15.9",
"koa": "^2.16.2",
"koa": "^3.1.2",
"koa-bodyparser": "^4.4.1",
"koa-logger": "^3.2.1",
"phoenix": "^1.8.1",
"phoenix": "^1.8.5",
"ws": "^8.18.3"
},
"devDependencies": {
Expand All @@ -43,12 +43,12 @@
"@types/nodemon": "1.19.3",
"@types/phoenix": "^1.6.6",
"@types/yargs": "^17.0.33",
"ava": "5.1.0",
"ava": "7.0.0",
"koa-route": "^3.2.0",
"koa-websocket": "^7.0.0",
"query-string": "^8.2.0",
"tslib": "^2.8.1",
"tsup": "^6.7.0",
"tsup": "^8.5.1",
"typescript": "^4.9.5",
"yargs": "^17.7.2"
}
Expand Down
1 change: 1 addition & 0 deletions packages/lightning-mock/src/api-sockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ const createSocketAPI = (
startRun,
messageClients: wss.sendToClients.bind(this),
close: () => {
server.clients.forEach((client) => client.terminate());
server.close();
(wss as any).close();
},
Expand Down
15 changes: 14 additions & 1 deletion packages/lightning-mock/src/socket-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type MockSocketServer = typeof WebSocketServer & {
events: Record<string, EventHandler>
) => { unsubscribe: () => void };
sendToClients: (message: PhoenixEvent) => void;
destroy: () => Promise<void>;
};

function createServer({
Expand Down Expand Up @@ -140,7 +141,7 @@ function createServer({
},
};

// @ts-ignore something wierd about the wsServer typing
// @ts-ignore something weird about the wsServer typing
wsServer.on('connection', function (ws: DevSocket, req: any) {
logger?.info('new client connected');
state.events.emit(CONNECT); // todo client details maybe
Expand Down Expand Up @@ -286,6 +287,18 @@ function createServer({
});
};

mockServer.destroy = () =>
new Promise<void>((resolve) => {
// Terminate WebSocket clients first so any pending socketDelay
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

claude has been pushing all sorts of weirdness here which at the end of the day just isn't working.

// setTimeout callbacks don't try to send on a destroyed socket.
(wsServer as any).clients.forEach((client: any) => client.terminate());
// Also force-close any connections the HTTP server is still tracking
// (upgraded WS sockets may or may not still be in its pool depending
// on Node version). Without this, httpServer.close() can hang.
(wsServer as any)._server?.closeAllConnections?.();
(wsServer as any).close(() => resolve());
});

return mockServer as MockSocketServer;
}

Expand Down
7 changes: 4 additions & 3 deletions packages/lightning-mock/test/channels/claim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ type Channel = any;

let server: any;
let client: any;
let close: any;

test.before(async () => ({ server, client } = await setup(port)));
test.before(async () => ({ server, client, close } = await setup(port)));

test.afterEach(() => {
server.reset();
});

test.after(() => {
server.destroy();
test.after(async () => {
await close();
});

const run1 = runs['run-1'];
Expand Down
54 changes: 33 additions & 21 deletions packages/lightning-mock/test/channels/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,29 @@ const port = 7777;

let server: any;
let client: any;
let close: any;

// Set up a lightning server and a phoenix socket client before each test
test.before(async () => ({ server, client } = await setup(port)));
test.before(async () => ({ server, client, close } = await setup(port)));

test.afterEach(() => {
server.reset();
});

test.after(() => {
server.destroy();
test.after(async () => {
await close();
console.log('closed');

setTimeout(() => {
console.log('--- active handles ---');
process
._getActiveHandles()
.forEach((h) => console.log(h.constructor.name, h));
console.log('--- active requests ---');
process
._getActiveRequests()
.forEach((r) => console.log(r.constructor.name, r));
}, 200);
});

const run1 = runs['run-1'];
Expand All @@ -51,7 +64,7 @@ const join = (channelName: string, params: any = {}): Promise<Channel> =>
});
});

test.serial('create a channel for an run', async (t) => {
test.serial('create a channel for a run', async (t) => {
server.startRun('wibble');
await join('run:wibble', { token: 'a.b.c' });
t.pass('connection ok');
Expand Down Expand Up @@ -211,25 +224,24 @@ test.serial(
);

// TODO this should probably return reason AND state?
test.serial(
test.serial.only(
'getResult should return the correct resulting dataclip',
async (t) => {
return new Promise(async (done) => {
const result = { answer: 42 };

server.startRun(run1.id);

server.waitForResult(run1.id).then(() => {
const dataclip = server.getResult(run1.id);
t.deepEqual(result, dataclip);
done();
});

const channel = await join(`run:${run1.id}`, { token: 'a.b.c' });
channel.push(RUN_COMPLETE, {
final_state: result,
} as RunCompletePayload);
});
// return new Promise(async (done) => {
// const result = { answer: 42 };
// server.startRun(run1.id);
// server.waitForResult(run1.id).then(() => {
// const dataclip = server.getResult(run1.id);
// t.deepEqual(result, dataclip);
// done();
// });
// const channel = await join(`run:${run1.id}`, { token: 'a.b.c' });
// channel.push(RUN_COMPLETE, {
// final_state: result,
// } as RunCompletePayload);
// });

t.pass();
}
);

Expand Down
7 changes: 6 additions & 1 deletion packages/lightning-mock/test/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import { setup } from './util';

// @ts-ignore
let server: any;
let close: any;

const port = 3334;

test.before(async () => ({ server } = await setup(port)));
test.before(async () => ({ server, close } = await setup(port)));

test.after(async () => {
await close();
});

test('addProject: add a project from yaml', async (t) => {
const yaml = `
Expand Down
7 changes: 6 additions & 1 deletion packages/lightning-mock/test/rest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import { DEFAULT_PROJECT_ID } from '../src/api-rest';

// @ts-ignore
let server: any;
let close: any;

const port = 3334;

const endpoint = `http://localhost:${port}`;

test.before(async () => ({ server } = await setup(port)));
test.before(async () => ({ server, close } = await setup(port)));

test.after(async () => {
await close();
});

test.serial('should pull a project', async (t) => {
const response = await fetch(
Expand Down
Loading