-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathexit-reasons.test.ts
More file actions
247 lines (208 loc) · 5.8 KB
/
exit-reasons.test.ts
File metadata and controls
247 lines (208 loc) · 5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import test from 'ava';
import crypto from 'node:crypto';
import path from 'node:path';
import { initLightning, initWorker } from '../src/init';
let lightning;
let worker;
test.before(async () => {
const lightningPort = 4321;
lightning = initLightning(lightningPort);
({ worker } = await initWorker(lightningPort, {
repoDir: path.resolve('tmp/repo/exit-reason'),
}));
});
test.after(async () => {
lightning.destroy();
await worker.destroy();
});
const run = async (attempt) => {
return new Promise<any>(async (done) => {
lightning.once('run:complete', (evt) => {
if (attempt.id === evt.runId) {
done(evt.payload);
}
});
lightning.enqueueRun(attempt);
});
};
test.serial('crash: syntax error', async (t) => {
const attempt = {
id: crypto.randomUUID(),
jobs: [
{
adaptor: '@openfn/language-common@latest',
body: 'fn(() => throw "e")',
},
],
};
const result = await run(attempt);
const { reason, error_type, error_message } = result;
t.is(reason, 'crash');
t.is(error_type, 'CompileError');
t.regex(error_message, /Unexpected token \(1:9\)$/);
});
// https://github.com/OpenFn/kit/issues/1045
test.serial('crash: reference error', async (t) => {
const attempt = {
id: crypto.randomUUID(),
jobs: [
{
name: 'x', // important!
adaptor: '@openfn/language-common@latest',
body: 'fn((s) => s.err.map(s => s))',
},
],
};
const result = await run(attempt);
const { reason, error_type, error_message } = result;
t.is(reason, 'fail');
t.is(error_type, 'RuntimeError');
t.regex(
error_message,
/TypeError: Cannot read properties of undefined \(reading \'map\'\)/
);
});
// https://github.com/OpenFn/kit/issues/758
test.serial('crash: job not found', async (t) => {
lightning.addDataclip('x', {});
const attempt = {
id: crypto.randomUUID(),
jobs: [
{
id: 'x',
adaptor: '@openfn/language-common@latest',
body: 'fn(s => s)',
},
],
dataclip_id: 'x', // having a data clip is important to trigger the crash
starting_node_id: 'y',
};
const result = await run(attempt);
const { reason, error_type, error_message } = result;
t.is(reason, 'crash');
t.is(error_type, 'ValidationError');
t.regex(error_message, /could not find start job: y/i);
});
test.serial('exception: autoinstall error', async (t) => {
const attempt = {
id: crypto.randomUUID(),
jobs: [
{
adaptor: '@openfn/language-worker-integration-tests@9.9.9',
body: 'fn((s) => s)',
},
],
};
const result = await run(attempt);
const { reason, error_type, error_message } = result;
t.is(reason, 'exception');
t.is(error_type, 'AutoinstallError');
t.regex(
error_message,
/Error installing @openfn\/language-worker-integration-tests@9.9.9/
);
});
test.serial('exception: bad credential (not found)', async (t) => {
const attempt = {
id: crypto.randomUUID(),
jobs: [
{
adaptor: '@openfn/language-common@latest',
body: 'fn((s) => s)',
credential: 'been-to-the-mountain', // the mock will return not_found
},
],
};
const expectedLightningErrorResponse = {
errors: { id: ['Credential not found!'] },
};
const result = await run(attempt);
const { reason, error_type, error_message } = result;
t.is(reason, 'exception');
t.is(error_type, 'CredentialLoadError');
t.is(
error_message,
`Failed to load credential been-to-the-mountain: [fetch:credential] ${JSON.stringify(
expectedLightningErrorResponse
)}`
);
});
test.serial('exception: credential timeout', async (t) => {
const attempt = {
id: crypto.randomUUID(),
jobs: [
{
adaptor: '@openfn/language-common@latest',
body: 'fn((s) => s)',
credential: '%TIMEOUT%', // special mock key
},
],
};
const result = await run(attempt);
const { reason, error_type, error_message } = result;
t.is(reason, 'exception');
t.is(error_type, 'CredentialLoadError');
t.is(
error_message,
'Failed to load credential %TIMEOUT%: [fetch:credential] timeout'
);
});
test.serial('kill: oom (small, kill worker)', async (t) => {
const attempt = {
id: crypto.randomUUID(),
jobs: [
{
adaptor: '@openfn/language-common@latest',
body: `fn((s) => {
s.data = [];
while(true) {
s.data.push(new Array(1e6).fill("xyz"))
}
})`,
},
],
};
const result = await run(attempt);
const { reason, error_type, error_message } = result;
t.is(reason, 'kill');
t.is(error_type, 'OOMError');
t.is(error_message, 'Run exceeded maximum memory usage');
});
// TODO this is failing locally... is it OK in CI?
test.serial('kill: oom (large, kill vm)', async (t) => {
const attempt = {
id: crypto.randomUUID(),
jobs: [
{
adaptor: '@openfn/language-common@latest',
body: `fn((s) => {
s.data = [];
while(true) {
s.data.push(new Array(1e9).fill("xyz"))
}
})`,
},
],
};
const result = await run(attempt);
const { reason, error_type, error_message } = result;
t.is(reason, 'kill');
t.is(error_type, 'OOMError');
t.is(error_message, 'Run exceeded maximum memory usage');
});
test.serial('crash: process.exit() triggered by postgres', async (t) => {
const attempt = {
id: crypto.randomUUID(),
jobs: [
{
adaptor: '@openfn/language-postgresql@4.1.8', // version number is important
body: "sql('select * from food_hygiene_interview');",
},
],
};
const result = await run(attempt);
const { reason, error_type, error_message } = result;
t.is(reason, 'crash');
t.is(error_type, 'ExitError');
t.regex(error_message, /Worker thread exited with code: 1/i);
});