@mongosh/node-runtime-worker-thread 1.10.1 → 1.10.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/.depcheckrc +14 -2
- package/.eslintignore +2 -1
- package/.eslintrc.js +10 -1
- package/.prettierignore +6 -0
- package/.prettierrc.json +1 -0
- package/dist/child-process-evaluation-listener.d.ts +3 -3
- package/dist/child-process-evaluation-listener.js +4 -4
- package/dist/child-process-evaluation-listener.js.map +1 -1
- package/dist/child-process-mongosh-bus.d.ts +3 -3
- package/dist/child-process-mongosh-bus.js +1 -1
- package/dist/child-process-mongosh-bus.js.map +1 -1
- package/dist/child-process-proxy.js +1 -1
- package/dist/child-process-proxy.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lock.d.ts +1 -1
- package/dist/lock.js +1 -1
- package/dist/lock.js.map +1 -1
- package/dist/report.html +2 -2
- package/dist/rpc.d.ts +4 -4
- package/dist/rpc.js +4 -4
- package/dist/rpc.js.map +1 -1
- package/dist/serializer.d.ts +3 -3
- package/dist/serializer.js +11 -14
- package/dist/serializer.js.map +1 -1
- package/dist/spawn-child-from-source.d.ts +2 -1
- package/dist/spawn-child-from-source.js +1 -1
- package/dist/spawn-child-from-source.js.map +1 -1
- package/dist/worker-runtime.d.ts +5 -5
- package/dist/worker-runtime.js +34 -46
- package/dist/worker-runtime.js.map +1 -1
- package/package.json +26 -15
- package/src/child-process-evaluation-listener.ts +25 -10
- package/src/child-process-mongosh-bus.ts +5 -4
- package/src/child-process-proxy.spec.ts +22 -12
- package/src/child-process-proxy.ts +18 -15
- package/src/index.spec.ts +109 -68
- package/src/index.ts +25 -13
- package/src/lock.spec.ts +9 -9
- package/src/lock.ts +1 -1
- package/src/rpc.spec.ts +33 -34
- package/src/rpc.ts +17 -16
- package/src/serializer.spec.ts +85 -63
- package/src/serializer.ts +24 -17
- package/src/spawn-child-from-source.spec.ts +10 -9
- package/src/spawn-child-from-source.ts +5 -5
- package/src/worker-runtime.spec.ts +117 -98
- package/src/worker-runtime.ts +26 -21
- package/tsconfig-lint.json +5 -0
- package/tsconfig.json +5 -11
- package/tsconfig.test.json +3 -5
- package/webpack.config.js +4 -4
- package/tsconfig.lint.json +0 -8
package/src/index.spec.ts
CHANGED
|
@@ -2,7 +2,7 @@ import path from 'path';
|
|
|
2
2
|
import chai, { expect } from 'chai';
|
|
3
3
|
import sinon from 'sinon';
|
|
4
4
|
import sinonChai from 'sinon-chai';
|
|
5
|
-
import { MongoshBus } from '@mongosh/types';
|
|
5
|
+
import type { MongoshBus } from '@mongosh/types';
|
|
6
6
|
import { startTestServer } from '../../../testing/integration-testing-hooks';
|
|
7
7
|
import { WorkerRuntime } from '../dist/index';
|
|
8
8
|
|
|
@@ -10,30 +10,30 @@ import type { DevtoolsConnectOptions } from '@mongosh/service-provider-server';
|
|
|
10
10
|
|
|
11
11
|
export const dummyOptions: DevtoolsConnectOptions = Object.freeze({
|
|
12
12
|
productName: 'Test Product',
|
|
13
|
-
productDocsLink: 'https://example.com/'
|
|
13
|
+
productDocsLink: 'https://example.com/',
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
chai.use(sinonChai);
|
|
17
17
|
|
|
18
18
|
function createMockEventEmitter() {
|
|
19
|
-
return
|
|
19
|
+
return sinon.stub({ on() {}, emit() {} }) as unknown as MongoshBus;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function sleep(ms: number) {
|
|
23
23
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
describe('WorkerRuntime', ()
|
|
26
|
+
describe('WorkerRuntime', function () {
|
|
27
27
|
let runtime: WorkerRuntime;
|
|
28
28
|
|
|
29
|
-
afterEach(async()
|
|
29
|
+
afterEach(async function () {
|
|
30
30
|
if (runtime) {
|
|
31
31
|
await runtime.terminate();
|
|
32
32
|
runtime = null;
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
describe('spawn errors', ()
|
|
36
|
+
describe('spawn errors', function () {
|
|
37
37
|
const brokenScript = path.resolve(
|
|
38
38
|
__dirname,
|
|
39
39
|
'..',
|
|
@@ -41,14 +41,18 @@ describe('WorkerRuntime', () => {
|
|
|
41
41
|
'script-that-throws.js'
|
|
42
42
|
);
|
|
43
43
|
|
|
44
|
-
afterEach(()
|
|
45
|
-
delete process
|
|
44
|
+
afterEach(function () {
|
|
45
|
+
delete process
|
|
46
|
+
.env.CHILD_PROCESS_PROXY_SRC_PATH_DO_NOT_USE_THIS_EXCEPT_FOR_TESTING;
|
|
46
47
|
});
|
|
47
48
|
|
|
48
|
-
it('should return init error if child process failed to spawn', async()
|
|
49
|
-
process.env.CHILD_PROCESS_PROXY_SRC_PATH_DO_NOT_USE_THIS_EXCEPT_FOR_TESTING =
|
|
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;
|
|
50
52
|
|
|
51
|
-
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
53
|
+
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
54
|
+
nodb: true,
|
|
55
|
+
});
|
|
52
56
|
|
|
53
57
|
let err;
|
|
54
58
|
|
|
@@ -59,15 +63,23 @@ describe('WorkerRuntime', () => {
|
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
expect(err).to.be.instanceof(Error);
|
|
62
|
-
expect(err)
|
|
66
|
+
expect(err)
|
|
67
|
+
.to.have.property('message')
|
|
68
|
+
.match(/Child process failed to start/);
|
|
63
69
|
});
|
|
64
70
|
|
|
65
|
-
it('should return init error if worker in child process failed to spawn', async()
|
|
66
|
-
runtime = new WorkerRuntime(
|
|
67
|
-
|
|
68
|
-
|
|
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
|
+
},
|
|
69
81
|
}
|
|
70
|
-
|
|
82
|
+
);
|
|
71
83
|
|
|
72
84
|
let err;
|
|
73
85
|
|
|
@@ -78,21 +90,27 @@ describe('WorkerRuntime', () => {
|
|
|
78
90
|
}
|
|
79
91
|
|
|
80
92
|
expect(err).to.be.instanceof(Error);
|
|
81
|
-
expect(err)
|
|
93
|
+
expect(err)
|
|
94
|
+
.to.have.property('message')
|
|
95
|
+
.match(/Worker thread failed to start/);
|
|
82
96
|
});
|
|
83
97
|
});
|
|
84
98
|
|
|
85
|
-
describe('evaluate', ()
|
|
86
|
-
it('should evaluate and return basic values', async()
|
|
87
|
-
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
99
|
+
describe('evaluate', function () {
|
|
100
|
+
it('should evaluate and return basic values', async function () {
|
|
101
|
+
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
102
|
+
nodb: true,
|
|
103
|
+
});
|
|
88
104
|
const result = await runtime.evaluate('1+1');
|
|
89
105
|
|
|
90
106
|
expect(result.printable).to.equal(2);
|
|
91
107
|
});
|
|
92
108
|
|
|
93
|
-
describe('errors', ()
|
|
94
|
-
it("should throw an error if it's thrown during evaluation", async()
|
|
95
|
-
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
109
|
+
describe('errors', function () {
|
|
110
|
+
it("should throw an error if it's thrown during evaluation", async function () {
|
|
111
|
+
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
112
|
+
nodb: true,
|
|
113
|
+
});
|
|
96
114
|
|
|
97
115
|
let err: Error;
|
|
98
116
|
|
|
@@ -110,8 +128,10 @@ describe('WorkerRuntime', () => {
|
|
|
110
128
|
.matches(/TypeError: Oh no, types!/);
|
|
111
129
|
});
|
|
112
130
|
|
|
113
|
-
it("should return an error if it's returned from evaluation", async()
|
|
114
|
-
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
131
|
+
it("should return an error if it's returned from evaluation", async function () {
|
|
132
|
+
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
133
|
+
nodb: true,
|
|
134
|
+
});
|
|
115
135
|
|
|
116
136
|
const { printable } = await runtime.evaluate(
|
|
117
137
|
'new SyntaxError("Syntax!")'
|
|
@@ -127,35 +147,43 @@ describe('WorkerRuntime', () => {
|
|
|
127
147
|
});
|
|
128
148
|
});
|
|
129
149
|
|
|
130
|
-
describe('getCompletions', ()
|
|
150
|
+
describe('getCompletions', function () {
|
|
131
151
|
const testServer = startTestServer('shared');
|
|
132
152
|
|
|
133
|
-
it('should return completions', async()
|
|
134
|
-
runtime = new WorkerRuntime(
|
|
153
|
+
it('should return completions', async function () {
|
|
154
|
+
runtime = new WorkerRuntime(
|
|
155
|
+
await testServer.connectionString(),
|
|
156
|
+
dummyOptions
|
|
157
|
+
);
|
|
135
158
|
const completions = await runtime.getCompletions('db.coll1.f');
|
|
136
159
|
|
|
137
160
|
expect(completions).to.deep.contain({ completion: 'db.coll1.find' });
|
|
138
161
|
});
|
|
139
162
|
});
|
|
140
163
|
|
|
141
|
-
describe('getShellPrompt', ()
|
|
164
|
+
describe('getShellPrompt', function () {
|
|
142
165
|
const testServer = startTestServer('shared');
|
|
143
166
|
|
|
144
|
-
it('should return prompt when connected to the server', async()
|
|
145
|
-
runtime = new WorkerRuntime(
|
|
167
|
+
it('should return prompt when connected to the server', async function () {
|
|
168
|
+
runtime = new WorkerRuntime(
|
|
169
|
+
await testServer.connectionString(),
|
|
170
|
+
dummyOptions
|
|
171
|
+
);
|
|
146
172
|
const result = await runtime.getShellPrompt();
|
|
147
173
|
|
|
148
174
|
expect(result).to.match(/>/);
|
|
149
175
|
});
|
|
150
176
|
});
|
|
151
177
|
|
|
152
|
-
describe('setEvaluationListener', ()
|
|
153
|
-
it('allows to set evaluation listener for runtime', async()
|
|
178
|
+
describe('setEvaluationListener', function () {
|
|
179
|
+
it('allows to set evaluation listener for runtime', async function () {
|
|
154
180
|
const evalListener = {
|
|
155
|
-
onPrompt: sinon.spy(() => 'password123')
|
|
181
|
+
onPrompt: sinon.spy(() => 'password123'),
|
|
156
182
|
};
|
|
157
183
|
|
|
158
|
-
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
184
|
+
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
185
|
+
nodb: true,
|
|
186
|
+
});
|
|
159
187
|
|
|
160
188
|
runtime.setEvaluationListener(evalListener);
|
|
161
189
|
|
|
@@ -166,10 +194,10 @@ describe('WorkerRuntime', () => {
|
|
|
166
194
|
});
|
|
167
195
|
});
|
|
168
196
|
|
|
169
|
-
describe('eventEmitter', ()
|
|
197
|
+
describe('eventEmitter', function () {
|
|
170
198
|
const testServer = startTestServer('shared');
|
|
171
199
|
|
|
172
|
-
it('should propagate emitted events from worker', async()
|
|
200
|
+
it('should propagate emitted events from worker', async function () {
|
|
173
201
|
const eventEmitter = createMockEventEmitter();
|
|
174
202
|
|
|
175
203
|
runtime = new WorkerRuntime(
|
|
@@ -182,16 +210,19 @@ describe('WorkerRuntime', () => {
|
|
|
182
210
|
|
|
183
211
|
await runtime.evaluate('db.getCollectionNames()');
|
|
184
212
|
|
|
185
|
-
expect(eventEmitter.emit).to.have.been.calledWith(
|
|
186
|
-
arguments
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
213
|
+
expect(eventEmitter.emit).to.have.been.calledWith(
|
|
214
|
+
'mongosh:api-call-with-arguments',
|
|
215
|
+
{
|
|
216
|
+
arguments: {},
|
|
217
|
+
class: 'Database',
|
|
218
|
+
db: 'test',
|
|
219
|
+
method: 'getCollectionNames',
|
|
220
|
+
}
|
|
221
|
+
);
|
|
191
222
|
});
|
|
192
223
|
});
|
|
193
224
|
|
|
194
|
-
describe('terminate', ()
|
|
225
|
+
describe('terminate', function () {
|
|
195
226
|
function isRunning(pid: number): boolean {
|
|
196
227
|
try {
|
|
197
228
|
process.kill(pid, 0);
|
|
@@ -203,32 +234,36 @@ describe('WorkerRuntime', () => {
|
|
|
203
234
|
|
|
204
235
|
// We will be testing a bunch of private props that can be accessed only with
|
|
205
236
|
// strings to make TS happy
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
237
|
+
it('should terminate child process', async function () {
|
|
238
|
+
const runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
239
|
+
nodb: true,
|
|
240
|
+
});
|
|
209
241
|
await runtime.terminate();
|
|
210
242
|
expect(runtime['childProcess']).to.have.property('killed', true);
|
|
211
243
|
expect(isRunning(runtime['childProcess'].pid)).to.equal(false);
|
|
212
244
|
});
|
|
213
245
|
|
|
214
|
-
it('should remove all listeners from childProcess', async()
|
|
215
|
-
const runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
246
|
+
it('should remove all listeners from childProcess', async function () {
|
|
247
|
+
const runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
248
|
+
nodb: true,
|
|
249
|
+
});
|
|
216
250
|
await runtime.terminate();
|
|
217
251
|
expect(runtime['childProcess'].listenerCount('message')).to.equal(0);
|
|
218
252
|
});
|
|
219
|
-
/* eslint-enable dot-notation */
|
|
220
253
|
|
|
221
|
-
it('should cancel any in-flight runtime calls', async()
|
|
222
|
-
const runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
254
|
+
it('should cancel any in-flight runtime calls', async function () {
|
|
255
|
+
const runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
256
|
+
nodb: true,
|
|
257
|
+
});
|
|
223
258
|
let err: Error;
|
|
224
259
|
try {
|
|
225
260
|
await Promise.all([
|
|
226
261
|
runtime.evaluate('while(true){}'),
|
|
227
|
-
(async() => {
|
|
262
|
+
(async () => {
|
|
228
263
|
// smol sleep to make sure we actually issued a call
|
|
229
264
|
await sleep(100);
|
|
230
265
|
await runtime.terminate();
|
|
231
|
-
})()
|
|
266
|
+
})(),
|
|
232
267
|
]);
|
|
233
268
|
} catch (e: any) {
|
|
234
269
|
err = e;
|
|
@@ -238,9 +273,11 @@ describe('WorkerRuntime', () => {
|
|
|
238
273
|
});
|
|
239
274
|
});
|
|
240
275
|
|
|
241
|
-
describe('interrupt', ()
|
|
242
|
-
it('should interrupt in-flight async tasks', async()
|
|
243
|
-
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
276
|
+
describe('interrupt', function () {
|
|
277
|
+
it('should interrupt in-flight async tasks', async function () {
|
|
278
|
+
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
279
|
+
nodb: true,
|
|
280
|
+
});
|
|
244
281
|
|
|
245
282
|
await runtime.waitForRuntimeToBeReady();
|
|
246
283
|
|
|
@@ -249,13 +286,13 @@ describe('WorkerRuntime', () => {
|
|
|
249
286
|
try {
|
|
250
287
|
await Promise.all([
|
|
251
288
|
runtime.evaluate('sleep(1000000)'),
|
|
252
|
-
(async() => {
|
|
289
|
+
(async () => {
|
|
253
290
|
// This is flaky when not enought time given to the worker to
|
|
254
291
|
// finish the sync part of the work. If it causes too much issues
|
|
255
292
|
// it would be okay to disable this test completely
|
|
256
293
|
await sleep(5000);
|
|
257
294
|
await runtime.interrupt();
|
|
258
|
-
})()
|
|
295
|
+
})(),
|
|
259
296
|
]);
|
|
260
297
|
} catch (e: any) {
|
|
261
298
|
err = e;
|
|
@@ -267,8 +304,10 @@ describe('WorkerRuntime', () => {
|
|
|
267
304
|
.match(/Async script execution was interrupted/);
|
|
268
305
|
});
|
|
269
306
|
|
|
270
|
-
it('should interrupt in-flight synchronous tasks', async()
|
|
271
|
-
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
307
|
+
it('should interrupt in-flight synchronous tasks', async function () {
|
|
308
|
+
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
309
|
+
nodb: true,
|
|
310
|
+
});
|
|
272
311
|
|
|
273
312
|
await runtime.waitForRuntimeToBeReady();
|
|
274
313
|
|
|
@@ -277,10 +316,10 @@ describe('WorkerRuntime', () => {
|
|
|
277
316
|
try {
|
|
278
317
|
await Promise.all([
|
|
279
318
|
runtime.evaluate('while(true){}'),
|
|
280
|
-
(async() => {
|
|
319
|
+
(async () => {
|
|
281
320
|
await sleep(200);
|
|
282
321
|
await runtime.interrupt();
|
|
283
|
-
})()
|
|
322
|
+
})(),
|
|
284
323
|
]);
|
|
285
324
|
} catch (e: any) {
|
|
286
325
|
err = e;
|
|
@@ -292,18 +331,20 @@ describe('WorkerRuntime', () => {
|
|
|
292
331
|
.match(/Script execution was interrupted/);
|
|
293
332
|
});
|
|
294
333
|
|
|
295
|
-
it('should allow to evaluate again after interruption', async()
|
|
296
|
-
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
334
|
+
it('should allow to evaluate again after interruption', async function () {
|
|
335
|
+
runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
|
|
336
|
+
nodb: true,
|
|
337
|
+
});
|
|
297
338
|
|
|
298
339
|
await runtime.waitForRuntimeToBeReady();
|
|
299
340
|
|
|
300
341
|
try {
|
|
301
342
|
await Promise.all([
|
|
302
343
|
runtime.evaluate('while(true){}'),
|
|
303
|
-
(async() => {
|
|
344
|
+
(async () => {
|
|
304
345
|
await sleep(200);
|
|
305
346
|
await runtime.interrupt();
|
|
306
|
-
})()
|
|
347
|
+
})(),
|
|
307
348
|
]);
|
|
308
349
|
} catch (e: any) {
|
|
309
350
|
// ignore
|
package/src/index.ts
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
/* istanbul ignore file */
|
|
2
2
|
/* ^^^ we test the dist directly, so isntanbul can't calculate the coverage correctly */
|
|
3
3
|
|
|
4
|
-
import { ChildProcess,
|
|
5
|
-
import {
|
|
4
|
+
import type { ChildProcess, SpawnOptionsWithoutStdio } from 'child_process';
|
|
5
|
+
import { spawn } from 'child_process';
|
|
6
|
+
import type {
|
|
6
7
|
Runtime,
|
|
7
8
|
RuntimeEvaluationListener,
|
|
8
|
-
RuntimeEvaluationResult
|
|
9
|
+
RuntimeEvaluationResult,
|
|
9
10
|
} from '@mongosh/browser-runtime-core';
|
|
10
11
|
import type { MongoshBus } from '@mongosh/types';
|
|
11
12
|
import path from 'path';
|
|
12
13
|
import { EventEmitter, once } from 'events';
|
|
13
14
|
import { kill } from './spawn-child-from-source';
|
|
14
|
-
import { Caller
|
|
15
|
+
import type { Caller } from './rpc';
|
|
16
|
+
import { createCaller, cancel } from './rpc';
|
|
15
17
|
import { ChildProcessEvaluationListener } from './child-process-evaluation-listener';
|
|
16
18
|
import type { WorkerRuntime as WorkerThreadWorkerRuntime } from './worker-runtime';
|
|
17
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
deserializeEvaluationResult,
|
|
21
|
+
serializeConnectOptions,
|
|
22
|
+
} from './serializer';
|
|
18
23
|
import { ChildProcessMongoshBus } from './child-process-mongosh-bus';
|
|
19
24
|
import type { CompassServiceProvider } from '@mongosh/service-provider-server';
|
|
20
25
|
|
|
21
|
-
type DevtoolsConnectOptions = Parameters<
|
|
26
|
+
type DevtoolsConnectOptions = Parameters<
|
|
27
|
+
(typeof CompassServiceProvider)['connect']
|
|
28
|
+
>[1];
|
|
22
29
|
type ChildProcessRuntime = Caller<WorkerThreadWorkerRuntime>;
|
|
23
30
|
|
|
24
31
|
function parseStderrToError(str: string): Error | null {
|
|
@@ -93,11 +100,11 @@ class WorkerRuntime implements Runtime {
|
|
|
93
100
|
[this.childProcessProxySrcPath],
|
|
94
101
|
{
|
|
95
102
|
stdio: ['inherit', 'inherit', 'pipe', 'ipc'],
|
|
96
|
-
...spawnOptions
|
|
103
|
+
...spawnOptions,
|
|
97
104
|
}
|
|
98
105
|
);
|
|
99
106
|
|
|
100
|
-
const waitForReadyMessage = async() => {
|
|
107
|
+
const waitForReadyMessage = async () => {
|
|
101
108
|
let msg: string;
|
|
102
109
|
while (([msg] = await once(this.childProcess, 'message'))) {
|
|
103
110
|
if (msg === 'ready') return;
|
|
@@ -106,12 +113,11 @@ class WorkerRuntime implements Runtime {
|
|
|
106
113
|
|
|
107
114
|
let spawnError = '';
|
|
108
115
|
|
|
109
|
-
// eslint-disable-next-line chai-friendly/no-unused-expressions
|
|
110
116
|
this.childProcess?.stderr?.setEncoding('utf8')?.on('data', (chunk) => {
|
|
111
117
|
spawnError += chunk;
|
|
112
118
|
});
|
|
113
119
|
|
|
114
|
-
const waitForError = async() => {
|
|
120
|
+
const waitForError = async () => {
|
|
115
121
|
const [exitCode] = await once(this.childProcess, 'exit');
|
|
116
122
|
|
|
117
123
|
if (exitCode) {
|
|
@@ -121,7 +127,9 @@ class WorkerRuntime implements Runtime {
|
|
|
121
127
|
error.message = `Child process failed to start with the following error: ${error.message}`;
|
|
122
128
|
} else {
|
|
123
129
|
error = new Error(
|
|
124
|
-
`Worker runtime failed to start: child process exited with code ${
|
|
130
|
+
`Worker runtime failed to start: child process exited with code ${
|
|
131
|
+
exitCode as number | string
|
|
132
|
+
}`
|
|
125
133
|
);
|
|
126
134
|
}
|
|
127
135
|
|
|
@@ -144,7 +152,7 @@ class WorkerRuntime implements Runtime {
|
|
|
144
152
|
'getCompletions',
|
|
145
153
|
'setEvaluationListener',
|
|
146
154
|
'getShellPrompt',
|
|
147
|
-
'interrupt'
|
|
155
|
+
'interrupt',
|
|
148
156
|
],
|
|
149
157
|
this.childProcess
|
|
150
158
|
);
|
|
@@ -159,7 +167,11 @@ class WorkerRuntime implements Runtime {
|
|
|
159
167
|
this.childProcess
|
|
160
168
|
);
|
|
161
169
|
|
|
162
|
-
await this.childProcessRuntime.init(
|
|
170
|
+
await this.childProcessRuntime.init(
|
|
171
|
+
uri,
|
|
172
|
+
serializeConnectOptions(driverOptions),
|
|
173
|
+
cliOptions
|
|
174
|
+
);
|
|
163
175
|
}
|
|
164
176
|
|
|
165
177
|
async evaluate(code: string): Promise<RuntimeEvaluationResult> {
|
package/src/lock.spec.ts
CHANGED
|
@@ -5,21 +5,21 @@ function sleep(ms: number): Promise<void> {
|
|
|
5
5
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
describe('Lock', ()
|
|
9
|
-
it('should allow to create a lock promise that can be resolved programmatically', async()
|
|
8
|
+
describe('Lock', function () {
|
|
9
|
+
it('should allow to create a lock promise that can be resolved programmatically', async function () {
|
|
10
10
|
const lock = new Lock();
|
|
11
11
|
const [token, wasUnlocked] = await Promise.all([
|
|
12
12
|
lock.lock(),
|
|
13
|
-
(async() => {
|
|
13
|
+
(async () => {
|
|
14
14
|
await sleep(50);
|
|
15
15
|
return lock.unlock();
|
|
16
|
-
})()
|
|
16
|
+
})(),
|
|
17
17
|
]);
|
|
18
18
|
expect(lock.isUnlockToken(token)).to.equal(true);
|
|
19
19
|
expect(wasUnlocked).to.equal(true);
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
it('throws when trying to create locks when locked', ()
|
|
22
|
+
it('throws when trying to create locks when locked', function () {
|
|
23
23
|
const lock = new Lock();
|
|
24
24
|
|
|
25
25
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
@@ -42,15 +42,15 @@ describe('Lock', () => {
|
|
|
42
42
|
.match(/Can't create another lock while locked/);
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
describe('unlock', ()
|
|
46
|
-
it('should return false if lock is not locked', ()
|
|
45
|
+
describe('unlock', function () {
|
|
46
|
+
it('should return false if lock is not locked', function () {
|
|
47
47
|
const lock = new Lock();
|
|
48
48
|
expect(lock.unlock()).to.equal(false);
|
|
49
49
|
});
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
describe('isLocked', ()
|
|
53
|
-
it('shoult return current lock status', ()
|
|
52
|
+
describe('isLocked', function () {
|
|
53
|
+
it('shoult return current lock status', function () {
|
|
54
54
|
const lock = new Lock();
|
|
55
55
|
expect(lock.isLocked()).to.equal(false);
|
|
56
56
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
package/src/lock.ts
CHANGED