Skip to content

Commit

Permalink
tests: add test for adaptor logs
Browse files Browse the repository at this point in the history
  • Loading branch information
josephjclark committed Feb 15, 2024
1 parent f92b9a3 commit 0801c28
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion integration-tests/worker/dummy-repo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"private": true,
"version": "1.0.0",
"dependencies": {
"@openfn/stateful-test_1.0.0": "@npm:@openfn/[email protected]"
"@openfn/stateful-test_1.0.0": "@npm:@openfn/[email protected]",
"@openfn/test-adaptor_1.0.0": "@npm:@openfn/[email protected]"
}
}
51 changes: 49 additions & 2 deletions integration-tests/worker/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ test.after(async () => {
await worker.destroy();
});

const createDummyWorker = () => {
const engineArgs = {
repoDir: path.resolve('./dummy-repo'),
maxWorkers: 1,
purge: false,
};
return initWorker(lightningPort, engineArgs);
};

test('should run a simple job with no compilation or adaptor', (t) => {
return new Promise(async (done) => {
lightning.once('run:complete', (evt) => {
Expand Down Expand Up @@ -148,7 +157,7 @@ test("Don't send job logs to stdout", (t) => {

lightning.once('run:complete', () => {
const jsonLogs = engineLogger._history;

console.log(jsonLogs);
// The engine logger shouldn't print out any job logs
const jobLog = jsonLogs.find((l) => l.name === 'JOB');
t.falsy(jobLog);
Expand All @@ -157,7 +166,44 @@ test("Don't send job logs to stdout", (t) => {

// But it SHOULD log engine stuff
const runtimeLog = jsonLogs.find(
(l) => l.name === 'R/T' && l.message[0].match(/completed step/i)
(l) => l.name === 'R/T' && l.message[0].match(/completed workflow/i)
);
t.truthy(runtimeLog);
done();
});

lightning.enqueueRun(attempt);
});
});

test("Don't send adaptor logs to stdout", (t) => {
return new Promise(async (done) => {
// We have to create a new worker with a different repo for this one
await worker.destroy();
({ worker, engineLogger } = await createDummyWorker());

const message = 've have been expecting you meester bond';
const attempt = {
id: crypto.randomUUID(),
jobs: [
{
adaptor: '@openfn/[email protected]',
body: `import { log } from '@openfn/test-adaptor'; log("${message}")`,
},
],
};

lightning.once('run:complete', (evt) => {
const jsonLogs = engineLogger._history;
// The engine logger shouldn't print out any adaptor logs
const jobLog = jsonLogs.find((l) => l.name === 'ADA');
t.falsy(jobLog);
const jobLog2 = jsonLogs.find((l) => l.message[0] === message);
t.falsy(jobLog2);

// But it SHOULD log engine stuff
const runtimeLog = jsonLogs.find(
(l) => l.name === 'R/T' && l.message[0].match(/completed workflow/i)
);
t.truthy(runtimeLog);
done();
Expand Down Expand Up @@ -433,6 +479,7 @@ test('stateful adaptor should create a new client for each attempt', (t) => {
return new Promise(async (done) => {
// We want to create our own special worker here
await worker.destroy();
({ worker } = await createDummyWorker());

const attempt1 = {
id: crypto.randomUUID(),
Expand Down

0 comments on commit 0801c28

Please sign in to comment.