@mongosh/node-runtime-worker-thread 2.3.0 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUTHORS +1 -0
- package/dist/153.js +1 -0
- package/dist/41.js +1 -0
- package/dist/502.js +1 -0
- package/dist/{578.js → 503.js} +1 -1
- package/dist/{43.js → 527.js} +1 -1
- package/dist/534.js +1 -0
- package/dist/711.js +1 -0
- package/dist/739.js +1 -0
- package/dist/index.d.ts +6 -8
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/report.html +2 -2
- package/dist/rpc.d.ts +6 -15
- package/dist/rpc.js +7 -71
- package/dist/rpc.js.map +1 -1
- package/dist/worker-process-mongosh-bus.d.ts +7 -0
- package/dist/{child-process-mongosh-bus.js → worker-process-mongosh-bus.js} +8 -8
- package/dist/worker-process-mongosh-bus.js.map +1 -0
- package/dist/worker-runtime.js +16 -16
- package/dist/worker-runtime.js.map +1 -1
- package/dist/{child-process-evaluation-listener.d.ts → worker-thread-evaluation-listener.d.ts} +2 -4
- package/dist/{child-process-evaluation-listener.js → worker-thread-evaluation-listener.js} +6 -6
- package/dist/worker-thread-evaluation-listener.js.map +1 -0
- package/package.json +13 -12
- package/src/index.spec.ts +148 -147
- package/src/index.ts +98 -120
- package/src/lock.spec.ts +1 -1
- package/src/rpc.spec.ts +24 -90
- package/src/rpc.ts +17 -98
- package/src/{child-process-mongosh-bus.ts → worker-process-mongosh-bus.ts} +5 -6
- package/src/worker-runtime.spec.ts +19 -29
- package/src/worker-runtime.ts +15 -22
- package/src/{child-process-evaluation-listener.ts → worker-thread-evaluation-listener.ts} +3 -4
- package/tests/register-worker.js +1 -0
- package/tsconfig.json +2 -1
- package/webpack.config.js +4 -6
- package/__fixtures__/script-that-throws.js +0 -1
- package/dist/354.js +0 -1
- package/dist/528.js +0 -1
- package/dist/650.js +0 -1
- package/dist/722.js +0 -1
- package/dist/777.js +0 -1
- package/dist/942.js +0 -1
- package/dist/child-process-evaluation-listener.js.map +0 -1
- package/dist/child-process-mongosh-bus.d.ts +0 -9
- package/dist/child-process-mongosh-bus.js.map +0 -1
- package/dist/child-process-proxy.d.ts +0 -1
- package/dist/child-process-proxy.js +0 -1
- package/dist/child-process-proxy.js.map +0 -1
- package/dist/spawn-child-from-source.d.ts +0 -5
- package/dist/spawn-child-from-source.js +0 -74
- package/dist/spawn-child-from-source.js.map +0 -1
- package/src/child-process-proxy.spec.ts +0 -84
- package/src/child-process-proxy.ts +0 -124
- package/src/spawn-child-from-source.spec.ts +0 -90
- package/src/spawn-child-from-source.ts +0 -102
- package/tsconfig.test.json +0 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-runtime.js","sourceRoot":"","sources":["../src/worker-runtime.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"worker-runtime.js","sourceRoot":"","sources":["../src/worker-runtime.ts"],"names":[],"mappings":";;AASA,gFAAoE;AAEpE,8EAA0E;AAC1E,+BAAgD;AAChD,6CAGsB;AAGtB,iCAA8B;AAE9B,6CAA+C;AAE/C,MAAM,cAAc,GAAG;IACrB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC;IAClD,mBAAmB,EAAE,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC;IACxD,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;CACzC,CAAC;AAMF,IAAI,OAAO,GAAmB,IAAI,CAAC;AACnC,IAAI,QAAQ,GAA2B,IAAI,CAAC;AAE5C,MAAM,cAAc,GAAG,IAAI,WAAI,EAAE,CAAC;AAElC,SAAS,aAAa,CAAC,UAAkB;IACvC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,cAAc,UAAU,oCAAoC,CAC7D,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AA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C;IAC3C,CAAC;IAED,cAAc,CAAC,IAAY;QACzB,OAAO,aAAa,CAAC,gBAAgB,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAC9D,CAAC;IAED,cAAc;QACZ,OAAO,aAAa,CAAC,gBAAgB,CAAC,CAAC,cAAc,EAAE,CAAC;IAC1D,CAAC;IAED,qBAAqB;QACnB,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;IACJ,CAAC;IAED,SAAS;QACP,OAAO,cAAc,CAAC,MAAM,EAAE,CAAC;IACjC,CAAC;CACF,CAAC;AAEF,IAAA,eAAS,EAAC,aAAa,EAAE,cAAc,CAAC,CAAC;AAEzC,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE;IACpB,cAAc,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC,CAAC,CAAC"}
|
package/dist/{child-process-evaluation-listener.d.ts → worker-thread-evaluation-listener.d.ts}
RENAMED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { ChildProcess } from 'child_process';
|
|
3
1
|
import type { Exposed } from './rpc';
|
|
4
2
|
import type { WorkerRuntime } from './index';
|
|
5
3
|
import type { RuntimeEvaluationListener } from '@mongosh/browser-runtime-core';
|
|
6
|
-
export declare class
|
|
4
|
+
export declare class WorkerThreadEvaluationListener {
|
|
7
5
|
exposedListener: Exposed<Required<Omit<RuntimeEvaluationListener, 'onLoad' | 'getCryptLibraryOptions'>>>;
|
|
8
|
-
constructor(workerRuntime: WorkerRuntime,
|
|
6
|
+
constructor(workerRuntime: WorkerRuntime, worker: Worker);
|
|
9
7
|
terminate(): void;
|
|
10
8
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.WorkerThreadEvaluationListener = void 0;
|
|
4
4
|
const rpc_1 = require("./rpc");
|
|
5
5
|
const serializer_1 = require("./serializer");
|
|
6
|
-
class
|
|
7
|
-
constructor(workerRuntime,
|
|
6
|
+
class WorkerThreadEvaluationListener {
|
|
7
|
+
constructor(workerRuntime, worker) {
|
|
8
8
|
this.exposedListener = (0, rpc_1.exposeAll)({
|
|
9
9
|
onPrompt(question, type) {
|
|
10
10
|
var _a, _b, _c;
|
|
@@ -43,11 +43,11 @@ class ChildProcessEvaluationListener {
|
|
|
43
43
|
var _a, _b, _c;
|
|
44
44
|
return ((_c = (_b = (_a = workerRuntime.evaluationListener) === null || _a === void 0 ? void 0 : _a.onExit) === null || _b === void 0 ? void 0 : _b.call(_a, exitCode)) !== null && _c !== void 0 ? _c : Promise.resolve());
|
|
45
45
|
},
|
|
46
|
-
},
|
|
46
|
+
}, worker);
|
|
47
47
|
}
|
|
48
48
|
terminate() {
|
|
49
49
|
this.exposedListener[rpc_1.close]();
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
exports.
|
|
53
|
-
//# sourceMappingURL=
|
|
52
|
+
exports.WorkerThreadEvaluationListener = WorkerThreadEvaluationListener;
|
|
53
|
+
//# sourceMappingURL=worker-thread-evaluation-listener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-thread-evaluation-listener.js","sourceRoot":"","sources":["../src/worker-thread-evaluation-listener.ts"],"names":[],"mappings":";;;AACA,+BAAyC;AAEzC,6CAA2D;AAG3D,MAAa,8BAA8B;IAOzC,YAAY,aAA4B,EAAE,MAAc;QACtD,IAAI,CAAC,eAAe,GAAG,IAAA,eAAS,EAC9B;YACE,QAAQ,CAAC,QAAQ,EAAE,IAAI;;gBACrB,OAAO,CACL,MAAA,MAAA,MAAA,aAAa,CAAC,kBAAkB,0CAAE,QAAQ,mDAAG,QAAQ,EAAE,IAAI,CAAC,mCAAI,EAAE,CACnE,CAAC;YACJ,CAAC;YACD,OAAO,CAAC,MAAM;;gBACZ,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,wCAA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IAED,SAAS;QACP,IAAI,CAAC,eAAe,CAAC,WAAK,CAAC,EAAE,CAAC;IAChC,CAAC;CACF;AA5DD,wEA4DC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mongosh/node-runtime-worker-thread",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "MongoDB shell runtime that lives in a worker thread",
|
|
5
5
|
"homepage": "https://github.com/mongodb-js/mongosh",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"node": ">=14.15.1"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
|
-
"test": "
|
|
20
|
+
"test": "mocha -r \"../../scripts/import-expansions.js\" -r \"./tests/register-worker.js \" --timeout 15000 -r ts-node/register \"./src/**/*.spec.ts\"",
|
|
21
21
|
"pretest-ci": "node ../../scripts/run-if-package-requested.js npm run webpack-build -- --no-stats --no-devtool",
|
|
22
22
|
"test-ci": "node ../../scripts/run-if-package-requested.js npm test",
|
|
23
23
|
"test-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test",
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
"reformat": "npm run prettier -- --write . && npm run eslint --fix"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@mongodb-js/eslint-config-mongosh": "2.3.
|
|
37
|
+
"@mongodb-js/eslint-config-mongosh": "2.3.2",
|
|
38
38
|
"@mongodb-js/prettier-config-devtools": "^1.0.1",
|
|
39
|
-
"@mongodb-js/tsconfig-mongosh": "2.3.
|
|
40
|
-
"@mongosh/browser-runtime-core": "2.3.
|
|
41
|
-
"@mongosh/browser-runtime-electron": "2.3.
|
|
42
|
-
"@mongosh/service-provider-core": "2.3.
|
|
43
|
-
"@mongosh/service-provider-server": "2.3.
|
|
44
|
-
"@mongosh/types": "2.3.
|
|
45
|
-
"bson": "^6.
|
|
39
|
+
"@mongodb-js/tsconfig-mongosh": "2.3.2",
|
|
40
|
+
"@mongosh/browser-runtime-core": "2.3.2",
|
|
41
|
+
"@mongosh/browser-runtime-electron": "2.3.2",
|
|
42
|
+
"@mongosh/service-provider-core": "2.3.2",
|
|
43
|
+
"@mongosh/service-provider-server": "2.3.2",
|
|
44
|
+
"@mongosh/types": "2.3.2",
|
|
45
|
+
"bson": "^6.8.0",
|
|
46
46
|
"depcheck": "^1.4.3",
|
|
47
47
|
"eslint": "^7.25.0",
|
|
48
48
|
"mocha": "^10.2.0",
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"interruptor": "^1.0.1",
|
|
55
|
-
"system-ca": "^2.0.1"
|
|
55
|
+
"system-ca": "^2.0.1",
|
|
56
|
+
"web-worker": "^1.3.0"
|
|
56
57
|
},
|
|
57
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "591aaa54de23dfd7a4457835353dbfed40524057"
|
|
58
59
|
}
|
package/src/index.spec.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import chai, { expect } from 'chai';
|
|
3
2
|
import sinon from 'sinon';
|
|
4
3
|
import sinonChai from 'sinon-chai';
|
|
@@ -24,7 +23,7 @@ function sleep(ms: number) {
|
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
describe('WorkerRuntime', function () {
|
|
27
|
-
let runtime: WorkerRuntime;
|
|
26
|
+
let runtime: WorkerRuntime | null = null;
|
|
28
27
|
|
|
29
28
|
afterEach(async function () {
|
|
30
29
|
if (runtime) {
|
|
@@ -33,69 +32,6 @@ describe('WorkerRuntime', function () {
|
|
|
33
32
|
}
|
|
34
33
|
});
|
|
35
34
|
|
|
36
|
-
describe('spawn errors', function () {
|
|
37
|
-
const brokenScript = path.resolve(
|
|
38
|
-
__dirname,
|
|
39
|
-
'..',
|
|
40
|
-
'__fixtures__',
|
|
41
|
-
'script-that-throws.js'
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
afterEach(function () {
|
|
45
|
-
delete process
|
|
46
|
-
.env.CHILD_PROCESS_PROXY_SRC_PATH_DO_NOT_USE_THIS_EXCEPT_FOR_TESTING;
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should return init error if child process failed to spawn', async function () {
|
|
50
|
-
process.env.CHILD_PROCESS_PROXY_SRC_PATH_DO_NOT_USE_THIS_EXCEPT_FOR_TESTING =
|
|
51
|
-
brokenScript;
|
|
52
|
-
|
|
53
|
-
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
54
|
-
nodb: true,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
let err;
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
await runtime.evaluate('1+1');
|
|
61
|
-
} catch (e: any) {
|
|
62
|
-
err = e;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
expect(err).to.be.instanceof(Error);
|
|
66
|
-
expect(err)
|
|
67
|
-
.to.have.property('message')
|
|
68
|
-
.match(/Child process failed to start/);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should return init error if worker in child process failed to spawn', async function () {
|
|
72
|
-
runtime = new WorkerRuntime(
|
|
73
|
-
'mongodb://nodb/',
|
|
74
|
-
dummyOptions,
|
|
75
|
-
{ nodb: true },
|
|
76
|
-
{
|
|
77
|
-
env: {
|
|
78
|
-
WORKER_RUNTIME_SRC_PATH_DO_NOT_USE_THIS_EXCEPT_FOR_TESTING:
|
|
79
|
-
brokenScript,
|
|
80
|
-
},
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
let err;
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
await runtime.evaluate('1+1');
|
|
88
|
-
} catch (e: any) {
|
|
89
|
-
err = e;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
expect(err).to.be.instanceof(Error);
|
|
93
|
-
expect(err)
|
|
94
|
-
.to.have.property('message')
|
|
95
|
-
.match(/Worker thread failed to start/);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
35
|
describe('evaluate', function () {
|
|
100
36
|
it('should evaluate and return basic values', async function () {
|
|
101
37
|
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
@@ -112,7 +48,7 @@ describe('WorkerRuntime', function () {
|
|
|
112
48
|
nodb: true,
|
|
113
49
|
});
|
|
114
50
|
|
|
115
|
-
let err
|
|
51
|
+
let err!: Error;
|
|
116
52
|
|
|
117
53
|
try {
|
|
118
54
|
await runtime.evaluate('throw new TypeError("Oh no, types!")');
|
|
@@ -267,39 +203,23 @@ describe('WorkerRuntime', function () {
|
|
|
267
203
|
});
|
|
268
204
|
|
|
269
205
|
describe('terminate', function () {
|
|
270
|
-
function isRunning(pid: number): boolean {
|
|
271
|
-
try {
|
|
272
|
-
process.kill(pid, 0);
|
|
273
|
-
return true;
|
|
274
|
-
} catch (e: any) {
|
|
275
|
-
return false;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
206
|
// We will be testing a bunch of private props that can be accessed only with
|
|
280
207
|
// strings to make TS happy
|
|
281
208
|
it('should terminate child process', async function () {
|
|
282
209
|
const runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
283
210
|
nodb: true,
|
|
284
211
|
});
|
|
212
|
+
await runtime.waitForRuntimeToBeReady();
|
|
213
|
+
const terminateSpy = sinon.spy(runtime['workerProcess'], 'terminate');
|
|
285
214
|
await runtime.terminate();
|
|
286
|
-
expect(
|
|
287
|
-
expect(isRunning(runtime['childProcess'].pid)).to.equal(false);
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
it('should remove all listeners from childProcess', async function () {
|
|
291
|
-
const runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
292
|
-
nodb: true,
|
|
293
|
-
});
|
|
294
|
-
await runtime.terminate();
|
|
295
|
-
expect(runtime['childProcess'].listenerCount('message')).to.equal(0);
|
|
215
|
+
expect(terminateSpy.calledOnce).to.be.true;
|
|
296
216
|
});
|
|
297
217
|
|
|
298
218
|
it('should cancel any in-flight runtime calls', async function () {
|
|
299
219
|
const runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
300
220
|
nodb: true,
|
|
301
221
|
});
|
|
302
|
-
let err
|
|
222
|
+
let err!: Error;
|
|
303
223
|
try {
|
|
304
224
|
await Promise.all([
|
|
305
225
|
runtime.evaluate('while(true){}'),
|
|
@@ -318,85 +238,166 @@ describe('WorkerRuntime', function () {
|
|
|
318
238
|
});
|
|
319
239
|
|
|
320
240
|
describe('interrupt', function () {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
nodb
|
|
241
|
+
context('async tasks', function () {
|
|
242
|
+
it('should interrupt in-flight tasks', async function () {
|
|
243
|
+
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
244
|
+
nodb: true,
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
await runtime.waitForRuntimeToBeReady();
|
|
248
|
+
|
|
249
|
+
let err!: Error;
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
await Promise.all([
|
|
253
|
+
runtime.evaluate('sleep(1000000)'),
|
|
254
|
+
(async () => {
|
|
255
|
+
// This is flaky when not enough time is given to the worker to
|
|
256
|
+
// finish the sync part of the work. If it causes too much issues
|
|
257
|
+
// it would be okay to disable this test completely
|
|
258
|
+
await sleep(5000);
|
|
259
|
+
await runtime.interrupt();
|
|
260
|
+
})(),
|
|
261
|
+
]);
|
|
262
|
+
} catch (e: any) {
|
|
263
|
+
err = e;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
expect(err).to.be.instanceof(Error);
|
|
267
|
+
expect(err)
|
|
268
|
+
.to.have.property('message')
|
|
269
|
+
.match(/Async script execution was interrupted/);
|
|
324
270
|
});
|
|
325
271
|
|
|
326
|
-
|
|
272
|
+
it('should allow to evaluate again after interruption', async function () {
|
|
273
|
+
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
274
|
+
nodb: true,
|
|
275
|
+
});
|
|
327
276
|
|
|
328
|
-
|
|
277
|
+
await runtime.waitForRuntimeToBeReady();
|
|
329
278
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
} catch (e: any) {
|
|
342
|
-
err = e;
|
|
343
|
-
}
|
|
279
|
+
try {
|
|
280
|
+
await Promise.all([
|
|
281
|
+
runtime.evaluate('sleep(1000000)'),
|
|
282
|
+
(async () => {
|
|
283
|
+
await sleep(200);
|
|
284
|
+
await runtime.interrupt();
|
|
285
|
+
})(),
|
|
286
|
+
]);
|
|
287
|
+
} catch (e: any) {
|
|
288
|
+
// ignore
|
|
289
|
+
}
|
|
344
290
|
|
|
345
|
-
|
|
346
|
-
expect(err)
|
|
347
|
-
.to.have.property('message')
|
|
348
|
-
.match(/Async script execution was interrupted/);
|
|
349
|
-
});
|
|
291
|
+
const result = await runtime.evaluate('1+1');
|
|
350
292
|
|
|
351
|
-
|
|
352
|
-
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
353
|
-
nodb: true,
|
|
293
|
+
expect(result).to.have.property('printable', 2);
|
|
354
294
|
});
|
|
355
295
|
|
|
356
|
-
|
|
296
|
+
it('should preserve the context after interruption', async function () {
|
|
297
|
+
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
298
|
+
nodb: true,
|
|
299
|
+
});
|
|
357
300
|
|
|
358
|
-
|
|
301
|
+
await runtime.waitForRuntimeToBeReady();
|
|
359
302
|
|
|
360
|
-
|
|
361
|
-
await
|
|
362
|
-
runtime.evaluate('while(true){}'),
|
|
363
|
-
(async () => {
|
|
364
|
-
await sleep(200);
|
|
365
|
-
await runtime.interrupt();
|
|
366
|
-
})(),
|
|
367
|
-
]);
|
|
368
|
-
} catch (e: any) {
|
|
369
|
-
err = e;
|
|
370
|
-
}
|
|
303
|
+
await runtime.evaluate('let x = 1');
|
|
304
|
+
await runtime.evaluate('x = x + 2');
|
|
371
305
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
306
|
+
try {
|
|
307
|
+
await Promise.all([
|
|
308
|
+
runtime.evaluate('sleep(1000000)'),
|
|
309
|
+
(async () => {
|
|
310
|
+
await sleep(200);
|
|
311
|
+
await runtime.interrupt();
|
|
312
|
+
})(),
|
|
313
|
+
]);
|
|
314
|
+
} catch (e: any) {
|
|
315
|
+
// ignore
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const result = await runtime.evaluate('x + 3');
|
|
319
|
+
|
|
320
|
+
expect(result).to.have.property('printable', 6);
|
|
321
|
+
});
|
|
376
322
|
});
|
|
377
323
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
nodb
|
|
324
|
+
context('sync tasks', function () {
|
|
325
|
+
it('should interrupt in-flight tasks', async function () {
|
|
326
|
+
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
327
|
+
nodb: true,
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
await runtime.waitForRuntimeToBeReady();
|
|
331
|
+
|
|
332
|
+
let err!: Error;
|
|
333
|
+
|
|
334
|
+
try {
|
|
335
|
+
await Promise.all([
|
|
336
|
+
runtime.evaluate('while(true){}'),
|
|
337
|
+
(async () => {
|
|
338
|
+
await sleep(200);
|
|
339
|
+
await runtime.interrupt();
|
|
340
|
+
})(),
|
|
341
|
+
]);
|
|
342
|
+
} catch (e: any) {
|
|
343
|
+
err = e;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
expect(err).to.be.instanceof(Error);
|
|
347
|
+
expect(err)
|
|
348
|
+
.to.have.property('message')
|
|
349
|
+
.match(/Script execution was interrupted/);
|
|
381
350
|
});
|
|
382
351
|
|
|
383
|
-
|
|
352
|
+
it('should allow to evaluate again after interruption', async function () {
|
|
353
|
+
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
354
|
+
nodb: true,
|
|
355
|
+
});
|
|
384
356
|
|
|
385
|
-
|
|
386
|
-
await Promise.all([
|
|
387
|
-
runtime.evaluate('while(true){}'),
|
|
388
|
-
(async () => {
|
|
389
|
-
await sleep(200);
|
|
390
|
-
await runtime.interrupt();
|
|
391
|
-
})(),
|
|
392
|
-
]);
|
|
393
|
-
} catch (e: any) {
|
|
394
|
-
// ignore
|
|
395
|
-
}
|
|
357
|
+
await runtime.waitForRuntimeToBeReady();
|
|
396
358
|
|
|
397
|
-
|
|
359
|
+
try {
|
|
360
|
+
await Promise.all([
|
|
361
|
+
runtime.evaluate('while(true){}'),
|
|
362
|
+
(async () => {
|
|
363
|
+
await sleep(200);
|
|
364
|
+
await runtime.interrupt();
|
|
365
|
+
})(),
|
|
366
|
+
]);
|
|
367
|
+
} catch (e: any) {
|
|
368
|
+
// ignore
|
|
369
|
+
}
|
|
398
370
|
|
|
399
|
-
|
|
371
|
+
const result = await runtime.evaluate('1+1');
|
|
372
|
+
|
|
373
|
+
expect(result).to.have.property('printable', 2);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it('should preserve the context after interruption', async function () {
|
|
377
|
+
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
378
|
+
nodb: true,
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
await runtime.waitForRuntimeToBeReady();
|
|
382
|
+
|
|
383
|
+
await runtime.evaluate('let x = 1');
|
|
384
|
+
await runtime.evaluate('x = x + 2');
|
|
385
|
+
|
|
386
|
+
try {
|
|
387
|
+
await Promise.all([
|
|
388
|
+
runtime.evaluate('while(true){}'),
|
|
389
|
+
(async () => {
|
|
390
|
+
await sleep(200);
|
|
391
|
+
await runtime.interrupt();
|
|
392
|
+
})(),
|
|
393
|
+
]);
|
|
394
|
+
} catch (e: any) {
|
|
395
|
+
// ignore
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const result = await runtime.evaluate('x + 3');
|
|
399
|
+
expect(result).to.have.property('printable', 6);
|
|
400
|
+
});
|
|
400
401
|
});
|
|
401
402
|
});
|
|
402
403
|
});
|