@elaraai/e3-web 0.0.0-stage → 1.0.85
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/LICENSE.md +54 -0
- package/README.md +395 -2
- package/dist/src/app.d.ts +91 -0
- package/dist/src/app.d.ts.map +1 -0
- package/dist/src/app.js +112 -0
- package/dist/src/app.js.map +1 -0
- package/dist/src/bridge/bridge.spec.d.ts +6 -0
- package/dist/src/bridge/bridge.spec.d.ts.map +1 -0
- package/dist/src/bridge/bridge.spec.js +56 -0
- package/dist/src/bridge/bridge.spec.js.map +1 -0
- package/dist/src/bridge/page.d.ts +149 -0
- package/dist/src/bridge/page.d.ts.map +1 -0
- package/dist/src/bridge/page.js +328 -0
- package/dist/src/bridge/page.js.map +1 -0
- package/dist/src/bridge/protocol.d.ts +181 -0
- package/dist/src/bridge/protocol.d.ts.map +1 -0
- package/dist/src/bridge/protocol.js +113 -0
- package/dist/src/bridge/protocol.js.map +1 -0
- package/dist/src/bridge/worker.d.ts +124 -0
- package/dist/src/bridge/worker.d.ts.map +1 -0
- package/dist/src/bridge/worker.js +185 -0
- package/dist/src/bridge/worker.js.map +1 -0
- package/dist/src/browser/bridge.page.d.ts +12 -0
- package/dist/src/browser/bridge.page.d.ts.map +1 -0
- package/dist/src/browser/bridge.page.js +79 -0
- package/dist/src/browser/bridge.page.js.map +1 -0
- package/dist/src/browser/bridge.spec.d.ts +6 -0
- package/dist/src/browser/bridge.spec.d.ts.map +1 -0
- package/dist/src/browser/bridge.spec.js +105 -0
- package/dist/src/browser/bridge.spec.js.map +1 -0
- package/dist/src/browser/bridge.worker.d.ts +6 -0
- package/dist/src/browser/bridge.worker.d.ts.map +1 -0
- package/dist/src/browser/bridge.worker.js +35 -0
- package/dist/src/browser/bridge.worker.js.map +1 -0
- package/dist/src/browser/compliance.d.ts +68 -0
- package/dist/src/browser/compliance.d.ts.map +1 -0
- package/dist/src/browser/compliance.js +30 -0
- package/dist/src/browser/compliance.js.map +1 -0
- package/dist/src/browser/compliance.page.d.ts +6 -0
- package/dist/src/browser/compliance.page.d.ts.map +1 -0
- package/dist/src/browser/compliance.page.js +204 -0
- package/dist/src/browser/compliance.page.js.map +1 -0
- package/dist/src/browser/compliance.spec.d.ts +6 -0
- package/dist/src/browser/compliance.spec.d.ts.map +1 -0
- package/dist/src/browser/compliance.spec.js +147 -0
- package/dist/src/browser/compliance.spec.js.map +1 -0
- package/dist/src/browser/e3-api-1.spec.d.ts +6 -0
- package/dist/src/browser/e3-api-1.spec.d.ts.map +1 -0
- package/dist/src/browser/e3-api-1.spec.js +12 -0
- package/dist/src/browser/e3-api-1.spec.js.map +1 -0
- package/dist/src/browser/e3-api-2.spec.d.ts +6 -0
- package/dist/src/browser/e3-api-2.spec.d.ts.map +1 -0
- package/dist/src/browser/e3-api-2.spec.js +12 -0
- package/dist/src/browser/e3-api-2.spec.js.map +1 -0
- package/dist/src/browser/e3-api-3.spec.d.ts +6 -0
- package/dist/src/browser/e3-api-3.spec.d.ts.map +1 -0
- package/dist/src/browser/e3-api-3.spec.js +12 -0
- package/dist/src/browser/e3-api-3.spec.js.map +1 -0
- package/dist/src/browser/e3-api-parts.spec.d.ts +6 -0
- package/dist/src/browser/e3-api-parts.spec.d.ts.map +1 -0
- package/dist/src/browser/e3-api-parts.spec.js +45 -0
- package/dist/src/browser/e3-api-parts.spec.js.map +1 -0
- package/dist/src/browser/e3-api.d.ts +28 -0
- package/dist/src/browser/e3-api.d.ts.map +1 -0
- package/dist/src/browser/e3-api.js +144 -0
- package/dist/src/browser/e3-api.js.map +1 -0
- package/dist/src/browser/e3-client.worker.d.ts +6 -0
- package/dist/src/browser/e3-client.worker.d.ts.map +1 -0
- package/dist/src/browser/e3-client.worker.js +19 -0
- package/dist/src/browser/e3-client.worker.js.map +1 -0
- package/dist/src/browser/e3-forward.d.ts +27 -0
- package/dist/src/browser/e3-forward.d.ts.map +1 -0
- package/dist/src/browser/e3-forward.js +81 -0
- package/dist/src/browser/e3-forward.js.map +1 -0
- package/dist/src/browser/e3-forward.spec.d.ts +6 -0
- package/dist/src/browser/e3-forward.spec.d.ts.map +1 -0
- package/dist/src/browser/e3-forward.spec.js +84 -0
- package/dist/src/browser/e3-forward.spec.js.map +1 -0
- package/dist/src/browser/e3-port.worker.d.ts +6 -0
- package/dist/src/browser/e3-port.worker.d.ts.map +1 -0
- package/dist/src/browser/e3-port.worker.js +21 -0
- package/dist/src/browser/e3-port.worker.js.map +1 -0
- package/dist/src/browser/e3-unit.worker.d.ts +6 -0
- package/dist/src/browser/e3-unit.worker.d.ts.map +1 -0
- package/dist/src/browser/e3-unit.worker.js +18 -0
- package/dist/src/browser/e3-unit.worker.js.map +1 -0
- package/dist/src/browser/e3-wire.d.ts +43 -0
- package/dist/src/browser/e3-wire.d.ts.map +1 -0
- package/dist/src/browser/e3-wire.js +32 -0
- package/dist/src/browser/e3-wire.js.map +1 -0
- package/dist/src/browser/e3.page.d.ts +21 -0
- package/dist/src/browser/e3.page.d.ts.map +1 -0
- package/dist/src/browser/e3.page.js +119 -0
- package/dist/src/browser/e3.page.js.map +1 -0
- package/dist/src/browser/e3.spec.d.ts +6 -0
- package/dist/src/browser/e3.spec.d.ts.map +1 -0
- package/dist/src/browser/e3.spec.js +358 -0
- package/dist/src/browser/e3.spec.js.map +1 -0
- package/dist/src/browser/e3.worker.d.ts +6 -0
- package/dist/src/browser/e3.worker.d.ts.map +1 -0
- package/dist/src/browser/e3.worker.js +38 -0
- package/dist/src/browser/e3.worker.js.map +1 -0
- package/dist/src/browser/harness.d.ts +175 -0
- package/dist/src/browser/harness.d.ts.map +1 -0
- package/dist/src/browser/harness.js +375 -0
- package/dist/src/browser/harness.js.map +1 -0
- package/dist/src/browser/page.d.ts +47 -0
- package/dist/src/browser/page.d.ts.map +1 -0
- package/dist/src/browser/page.js +47 -0
- package/dist/src/browser/page.js.map +1 -0
- package/dist/src/browser/repository.page.d.ts +85 -0
- package/dist/src/browser/repository.page.d.ts.map +1 -0
- package/dist/src/browser/repository.page.js +271 -0
- package/dist/src/browser/repository.page.js.map +1 -0
- package/dist/src/browser/runner.page.d.ts +6 -0
- package/dist/src/browser/runner.page.d.ts.map +1 -0
- package/dist/src/browser/runner.page.js +62 -0
- package/dist/src/browser/runner.page.js.map +1 -0
- package/dist/src/browser/runner.spec.d.ts +6 -0
- package/dist/src/browser/runner.spec.d.ts.map +1 -0
- package/dist/src/browser/runner.spec.js +46 -0
- package/dist/src/browser/runner.spec.js.map +1 -0
- package/dist/src/browser/storage.page.d.ts +6 -0
- package/dist/src/browser/storage.page.d.ts.map +1 -0
- package/dist/src/browser/storage.page.js +289 -0
- package/dist/src/browser/storage.page.js.map +1 -0
- package/dist/src/browser/storage.spec.d.ts +6 -0
- package/dist/src/browser/storage.spec.d.ts.map +1 -0
- package/dist/src/browser/storage.spec.js +211 -0
- package/dist/src/browser/storage.spec.js.map +1 -0
- package/dist/src/browser/unit.worker.d.ts +6 -0
- package/dist/src/browser/unit.worker.d.ts.map +1 -0
- package/dist/src/browser/unit.worker.js +17 -0
- package/dist/src/browser/unit.worker.js.map +1 -0
- package/dist/src/execution/WebTaskRunner.d.ts +159 -0
- package/dist/src/execution/WebTaskRunner.d.ts.map +1 -0
- package/dist/src/execution/WebTaskRunner.js +581 -0
- package/dist/src/execution/WebTaskRunner.js.map +1 -0
- package/dist/src/execution/WebTaskRunner.spec.d.ts +6 -0
- package/dist/src/execution/WebTaskRunner.spec.d.ts.map +1 -0
- package/dist/src/execution/WebTaskRunner.spec.js +91 -0
- package/dist/src/execution/WebTaskRunner.spec.js.map +1 -0
- package/dist/src/execution/e3-platform.d.ts +41 -0
- package/dist/src/execution/e3-platform.d.ts.map +1 -0
- package/dist/src/execution/e3-platform.js +52 -0
- package/dist/src/execution/e3-platform.js.map +1 -0
- package/dist/src/execution/in-process.d.ts +32 -0
- package/dist/src/execution/in-process.d.ts.map +1 -0
- package/dist/src/execution/in-process.js +89 -0
- package/dist/src/execution/in-process.js.map +1 -0
- package/dist/src/execution/pool.d.ts +172 -0
- package/dist/src/execution/pool.d.ts.map +1 -0
- package/dist/src/execution/pool.js +352 -0
- package/dist/src/execution/pool.js.map +1 -0
- package/dist/src/execution/pool.spec.d.ts +6 -0
- package/dist/src/execution/pool.spec.d.ts.map +1 -0
- package/dist/src/execution/pool.spec.js +252 -0
- package/dist/src/execution/pool.spec.js.map +1 -0
- package/dist/src/execution/protocol.d.ts +108 -0
- package/dist/src/execution/protocol.d.ts.map +1 -0
- package/dist/src/execution/protocol.js +27 -0
- package/dist/src/execution/protocol.js.map +1 -0
- package/dist/src/execution/unit-server.d.ts +131 -0
- package/dist/src/execution/unit-server.d.ts.map +1 -0
- package/dist/src/execution/unit-server.js +142 -0
- package/dist/src/execution/unit-server.js.map +1 -0
- package/dist/src/index.d.ts +39 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +37 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/index.spec.d.ts +6 -0
- package/dist/src/index.spec.d.ts.map +1 -0
- package/dist/src/index.spec.js +212 -0
- package/dist/src/index.spec.js.map +1 -0
- package/dist/src/node.d.ts +12 -0
- package/dist/src/node.d.ts.map +1 -0
- package/dist/src/node.js +12 -0
- package/dist/src/node.js.map +1 -0
- package/dist/src/storage/WebStateStore.d.ts +64 -0
- package/dist/src/storage/WebStateStore.d.ts.map +1 -0
- package/dist/src/storage/WebStateStore.js +237 -0
- package/dist/src/storage/WebStateStore.js.map +1 -0
- package/dist/src/storage/WebStorage.d.ts +225 -0
- package/dist/src/storage/WebStorage.d.ts.map +1 -0
- package/dist/src/storage/WebStorage.js +1462 -0
- package/dist/src/storage/WebStorage.js.map +1 -0
- package/dist/src/storage/adapters.d.ts +610 -0
- package/dist/src/storage/adapters.d.ts.map +1 -0
- package/dist/src/storage/adapters.js +246 -0
- package/dist/src/storage/adapters.js.map +1 -0
- package/dist/src/storage/indexeddb.d.ts +93 -0
- package/dist/src/storage/indexeddb.d.ts.map +1 -0
- package/dist/src/storage/indexeddb.js +384 -0
- package/dist/src/storage/indexeddb.js.map +1 -0
- package/dist/src/storage/indexeddb.spec.d.ts +6 -0
- package/dist/src/storage/indexeddb.spec.d.ts.map +1 -0
- package/dist/src/storage/indexeddb.spec.js +77 -0
- package/dist/src/storage/indexeddb.spec.js.map +1 -0
- package/dist/src/storage/memory.d.ts +275 -0
- package/dist/src/storage/memory.d.ts.map +1 -0
- package/dist/src/storage/memory.js +724 -0
- package/dist/src/storage/memory.js.map +1 -0
- package/dist/src/storage/memory.spec.d.ts +6 -0
- package/dist/src/storage/memory.spec.d.ts.map +1 -0
- package/dist/src/storage/memory.spec.js +71 -0
- package/dist/src/storage/memory.spec.js.map +1 -0
- package/dist/src/storage/node-files.d.ts +38 -0
- package/dist/src/storage/node-files.d.ts.map +1 -0
- package/dist/src/storage/node-files.js +148 -0
- package/dist/src/storage/node-files.js.map +1 -0
- package/dist/src/storage/node-files.spec.d.ts +6 -0
- package/dist/src/storage/node-files.spec.d.ts.map +1 -0
- package/dist/src/storage/node-files.spec.js +40 -0
- package/dist/src/storage/node-files.spec.js.map +1 -0
- package/dist/src/storage/opfs.d.ts +145 -0
- package/dist/src/storage/opfs.d.ts.map +1 -0
- package/dist/src/storage/opfs.js +514 -0
- package/dist/src/storage/opfs.js.map +1 -0
- package/dist/src/storage/opfs.spec.d.ts +6 -0
- package/dist/src/storage/opfs.spec.d.ts.map +1 -0
- package/dist/src/storage/opfs.spec.js +51 -0
- package/dist/src/storage/opfs.spec.js.map +1 -0
- package/dist/src/storage/record-keys.d.ts +78 -0
- package/dist/src/storage/record-keys.d.ts.map +1 -0
- package/dist/src/storage/record-keys.js +71 -0
- package/dist/src/storage/record-keys.js.map +1 -0
- package/dist/src/storage/stores.spec.d.ts +6 -0
- package/dist/src/storage/stores.spec.d.ts.map +1 -0
- package/dist/src/storage/stores.spec.js +326 -0
- package/dist/src/storage/stores.spec.js.map +1 -0
- package/dist/src/storage/web-locks.d.ts +103 -0
- package/dist/src/storage/web-locks.d.ts.map +1 -0
- package/dist/src/storage/web-locks.js +228 -0
- package/dist/src/storage/web-locks.js.map +1 -0
- package/dist/src/testing/adapter-contract.d.ts +116 -0
- package/dist/src/testing/adapter-contract.d.ts.map +1 -0
- package/dist/src/testing/adapter-contract.js +769 -0
- package/dist/src/testing/adapter-contract.js.map +1 -0
- package/dist/src/testing/assert.d.ts +75 -0
- package/dist/src/testing/assert.d.ts.map +1 -0
- package/dist/src/testing/assert.js +146 -0
- package/dist/src/testing/assert.js.map +1 -0
- package/dist/src/testing/assert.spec.d.ts +6 -0
- package/dist/src/testing/assert.spec.d.ts.map +1 -0
- package/dist/src/testing/assert.spec.js +62 -0
- package/dist/src/testing/assert.spec.js.map +1 -0
- package/dist/src/testing/bridge-contract.d.ts +55 -0
- package/dist/src/testing/bridge-contract.d.ts.map +1 -0
- package/dist/src/testing/bridge-contract.js +376 -0
- package/dist/src/testing/bridge-contract.js.map +1 -0
- package/dist/src/testing/bridge-handler.d.ts +35 -0
- package/dist/src/testing/bridge-handler.d.ts.map +1 -0
- package/dist/src/testing/bridge-handler.js +108 -0
- package/dist/src/testing/bridge-handler.js.map +1 -0
- package/dist/src/testing/callers.d.ts +29 -0
- package/dist/src/testing/callers.d.ts.map +1 -0
- package/dist/src/testing/callers.js +24 -0
- package/dist/src/testing/callers.js.map +1 -0
- package/dist/src/testing/e3-fixtures.d.ts +38 -0
- package/dist/src/testing/e3-fixtures.d.ts.map +1 -0
- package/dist/src/testing/e3-fixtures.js +126 -0
- package/dist/src/testing/e3-fixtures.js.map +1 -0
- package/dist/src/testing/hold-platform.d.ts +33 -0
- package/dist/src/testing/hold-platform.d.ts.map +1 -0
- package/dist/src/testing/hold-platform.js +41 -0
- package/dist/src/testing/hold-platform.js.map +1 -0
- package/dist/src/testing/runner-cases.d.ts +112 -0
- package/dist/src/testing/runner-cases.d.ts.map +1 -0
- package/dist/src/testing/runner-cases.js +959 -0
- package/dist/src/testing/runner-cases.js.map +1 -0
- package/dist/src/testing/runner-fixtures.d.ts +13 -0
- package/dist/src/testing/runner-fixtures.d.ts.map +1 -0
- package/dist/src/testing/runner-fixtures.js +173 -0
- package/dist/src/testing/runner-fixtures.js.map +1 -0
- package/dist/src/testing/test-platform.d.ts +73 -0
- package/dist/src/testing/test-platform.d.ts.map +1 -0
- package/dist/src/testing/test-platform.js +143 -0
- package/dist/src/testing/test-platform.js.map +1 -0
- package/dist/src/transfer/WebTransferBackend.d.ts +780 -0
- package/dist/src/transfer/WebTransferBackend.d.ts.map +1 -0
- package/dist/src/transfer/WebTransferBackend.js +1140 -0
- package/dist/src/transfer/WebTransferBackend.js.map +1 -0
- package/dist/src/transfer/WebTransferBackend.spec.d.ts +6 -0
- package/dist/src/transfer/WebTransferBackend.spec.d.ts.map +1 -0
- package/dist/src/transfer/WebTransferBackend.spec.js +582 -0
- package/dist/src/transfer/WebTransferBackend.spec.js.map +1 -0
- package/dist/src/transfer/endpoints.d.ts +46 -0
- package/dist/src/transfer/endpoints.d.ts.map +1 -0
- package/dist/src/transfer/endpoints.js +157 -0
- package/dist/src/transfer/endpoints.js.map +1 -0
- package/dist/src/units.d.ts +51 -0
- package/dist/src/units.d.ts.map +1 -0
- package/dist/src/units.js +74 -0
- package/dist/src/units.js.map +1 -0
- package/dist/src/worker.d.ts +126 -0
- package/dist/src/worker.d.ts.map +1 -0
- package/dist/src/worker.js +186 -0
- package/dist/src/worker.js.map +1 -0
- package/dist/src/worker.spec.d.ts +6 -0
- package/dist/src/worker.spec.d.ts.map +1 -0
- package/dist/src/worker.spec.js +195 -0
- package/dist/src/worker.spec.js.map +1 -0
- package/package.json +76 -3
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The unit workers a page's runners run units on: a pool of dedicated Web
|
|
7
|
+
* Workers, started from the factory the app gives, as wide as the machine's
|
|
8
|
+
* cores unless set.
|
|
9
|
+
*
|
|
10
|
+
* A unit takes one of the pool's places, and runs on an idle worker or on one
|
|
11
|
+
* the pool starts for it; past the pool's width it waits for a place, in the
|
|
12
|
+
* order units asked. A worker is started with `start`, handed the port of the
|
|
13
|
+
* services its host serves units when the pool was given one, and serves units
|
|
14
|
+
* once it answers `ready`. A unit's run is stopped by terminating its worker
|
|
15
|
+
* — when the run is aborted, or runs past its timeout — and the worker is
|
|
16
|
+
* replaced by the next unit that needs one. A worker that fails, or never
|
|
17
|
+
* starts serving units, is let go the same way, failing the unit it was given;
|
|
18
|
+
* so is one that stops on its own — closes itself, say, which no event tells
|
|
19
|
+
* its pool — learned of through the Web Lock it holds while it lives. A worker
|
|
20
|
+
* let go has its host's services ended with it.
|
|
21
|
+
*
|
|
22
|
+
* @packageDocumentation
|
|
23
|
+
*/
|
|
24
|
+
import { UnitResultType, UnitType, decodeBeast2For, encodeBeast2For } from '@elaraai/east';
|
|
25
|
+
import { watchLifeline } from '../bridge/protocol.js';
|
|
26
|
+
import { transferOf } from './protocol.js';
|
|
27
|
+
/** How long a worker may take to start serving units. */
|
|
28
|
+
const START_TIMEOUT_MS = 60_000;
|
|
29
|
+
/** A worker the pool started, and the run it has in flight. */
|
|
30
|
+
class PooledWorker {
|
|
31
|
+
worker;
|
|
32
|
+
connection;
|
|
33
|
+
lost;
|
|
34
|
+
/** Settles once the worker serves units; rejects when it fails first, or
|
|
35
|
+
* takes too long. */
|
|
36
|
+
ready;
|
|
37
|
+
/** Why the worker is let go, once it is: it failed, or was terminated */
|
|
38
|
+
ended = null;
|
|
39
|
+
inFlight = null;
|
|
40
|
+
answerReady;
|
|
41
|
+
refuseReady;
|
|
42
|
+
startTimer;
|
|
43
|
+
/** Aborted as the worker is let go: withdraws the wait on its lifeline */
|
|
44
|
+
ending = new AbortController();
|
|
45
|
+
/**
|
|
46
|
+
* @param worker - The worker, just started
|
|
47
|
+
* @param connection - The services it is handed, or `null`
|
|
48
|
+
* @param startTimeoutMs - How long it may take to start serving units
|
|
49
|
+
* @param lost - Tells the pool the worker is let go
|
|
50
|
+
*/
|
|
51
|
+
constructor(worker, connection, startTimeoutMs, lost) {
|
|
52
|
+
this.worker = worker;
|
|
53
|
+
this.connection = connection;
|
|
54
|
+
this.lost = lost;
|
|
55
|
+
this.ready = new Promise((resolve, reject) => {
|
|
56
|
+
this.answerReady = resolve;
|
|
57
|
+
this.refuseReady = reject;
|
|
58
|
+
});
|
|
59
|
+
// Nothing need await it to hear it fail.
|
|
60
|
+
this.ready.catch(() => undefined);
|
|
61
|
+
this.startTimer = setTimeout(() => {
|
|
62
|
+
this.fail(`the unit worker did not start serving units in ${startTimeoutMs / 1000} s: its script calls serveUnits() from @elaraai/e3-web/units`);
|
|
63
|
+
}, startTimeoutMs);
|
|
64
|
+
worker.onmessage = (event) => this.hear(event.data);
|
|
65
|
+
worker.onerror = (event) => {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
this.fail(`the unit worker failed${event.message ? `: ${event.message}` : ''}`);
|
|
68
|
+
};
|
|
69
|
+
const port = connection?.port ?? null;
|
|
70
|
+
worker.postMessage({ kind: 'start', port }, port === null ? [] : [port]);
|
|
71
|
+
}
|
|
72
|
+
/** Whether the worker is let go. */
|
|
73
|
+
get gone() {
|
|
74
|
+
return this.ended !== null;
|
|
75
|
+
}
|
|
76
|
+
/** Hears a message from the worker. */
|
|
77
|
+
hear(message) {
|
|
78
|
+
if (message.kind === 'ready') {
|
|
79
|
+
clearTimeout(this.startTimer);
|
|
80
|
+
// A worker that stops on its own frees its lifeline: no event says so.
|
|
81
|
+
watchLifeline(message.lifeline, this.ending.signal, () => {
|
|
82
|
+
this.fail('the unit worker stopped: it closed itself, or something other than its pool ended it');
|
|
83
|
+
});
|
|
84
|
+
this.answerReady();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const flight = this.inFlight;
|
|
88
|
+
if (flight === null || message.id !== flight.id)
|
|
89
|
+
return;
|
|
90
|
+
if (message.kind === 'log') {
|
|
91
|
+
flight.onLog?.(message.stream, message.text);
|
|
92
|
+
}
|
|
93
|
+
else if (message.kind === 'broken') {
|
|
94
|
+
flight.settle({ kind: 'failed', message: `the unit worker could not run the unit: ${message.message}` });
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
let result;
|
|
98
|
+
try {
|
|
99
|
+
result = decodeBeast2For(UnitResultType)(message.result);
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
flight.settle({ kind: 'failed', message: `the unit worker's result does not decode: ${err instanceof Error ? err.message : String(err)}` });
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
flight.settle({ kind: 'done', result, files: new Map(message.files) });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/** Lets the worker go, failing what it was doing. */
|
|
109
|
+
fail(why) {
|
|
110
|
+
if (this.ended !== null)
|
|
111
|
+
return;
|
|
112
|
+
this.end(why);
|
|
113
|
+
this.refuseReady(new Error(why));
|
|
114
|
+
this.inFlight?.settle({ kind: 'failed', message: why });
|
|
115
|
+
}
|
|
116
|
+
/** Terminates the worker, ends the services it was handed, and tells the
|
|
117
|
+
* pool it is let go. */
|
|
118
|
+
end(why) {
|
|
119
|
+
this.ended = why;
|
|
120
|
+
clearTimeout(this.startTimer);
|
|
121
|
+
this.ending.abort();
|
|
122
|
+
this.worker.terminate();
|
|
123
|
+
this.connection?.close();
|
|
124
|
+
this.lost(this);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Terminates the worker at once, whatever it runs: the run in flight is
|
|
128
|
+
* settled as `stop` says.
|
|
129
|
+
*
|
|
130
|
+
* @param stop - How the run in flight ended
|
|
131
|
+
*/
|
|
132
|
+
terminate(stop = { kind: 'failed', message: 'the unit pool was closed' }) {
|
|
133
|
+
if (this.ended !== null)
|
|
134
|
+
return;
|
|
135
|
+
this.end('terminated');
|
|
136
|
+
this.refuseReady(new Error('the unit worker was terminated'));
|
|
137
|
+
this.inFlight?.settle(stop);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Runs a unit on the worker, which serves units.
|
|
141
|
+
*
|
|
142
|
+
* @param id - The run's id, which the worker's answers name
|
|
143
|
+
* @param unit - The unit's bytes
|
|
144
|
+
* @param files - The files it names: their bytes are the worker's once sent
|
|
145
|
+
* @param options - Its signal, timeout and log
|
|
146
|
+
* @returns How it ended
|
|
147
|
+
*/
|
|
148
|
+
run(id, unit, files, options) {
|
|
149
|
+
return new Promise((resolve) => {
|
|
150
|
+
let timer;
|
|
151
|
+
const onAbort = () => this.terminate({ kind: 'aborted', started: true });
|
|
152
|
+
const settle = (run) => {
|
|
153
|
+
if (this.inFlight?.id !== id)
|
|
154
|
+
return;
|
|
155
|
+
this.inFlight = null;
|
|
156
|
+
clearTimeout(timer);
|
|
157
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
158
|
+
resolve(run);
|
|
159
|
+
};
|
|
160
|
+
if (this.ended !== null) {
|
|
161
|
+
resolve({ kind: 'failed', message: this.ended });
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
// Aborted once it was recorded running, and before it was sent.
|
|
165
|
+
if (options.signal?.aborted) {
|
|
166
|
+
resolve({ kind: 'aborted', started: true });
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
this.inFlight = { id, onLog: options.onLog, settle };
|
|
170
|
+
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
171
|
+
if (options.timeoutMs !== undefined) {
|
|
172
|
+
timer = setTimeout(() => this.terminate({ kind: 'timed_out' }), options.timeoutMs);
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
this.worker.postMessage({ kind: 'run', id, unit, files }, transferOf(files));
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
settle({ kind: 'failed', message: `the unit could not be sent to its worker: ${err instanceof Error ? err.message : String(err)}` });
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** An error's message. */
|
|
184
|
+
function messageOf(err) {
|
|
185
|
+
return err instanceof Error ? err.message : String(err);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* A pool of unit workers, which a page's runners share.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* const pool = new UnitPool({
|
|
193
|
+
* units: () => new Worker(new URL('./unit.worker.js', import.meta.url), { type: 'module' }),
|
|
194
|
+
* });
|
|
195
|
+
* const run = await pool.run(unit, files, { timeoutMs: 60_000 });
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export class UnitPool {
|
|
199
|
+
options;
|
|
200
|
+
/** The most units that run at once. */
|
|
201
|
+
width;
|
|
202
|
+
startTimeoutMs;
|
|
203
|
+
/** Workers serving units, or starting to, with no run in flight */
|
|
204
|
+
idle = [];
|
|
205
|
+
/** Every worker not let go */
|
|
206
|
+
live = new Set();
|
|
207
|
+
/** The units waiting for a place, first first */
|
|
208
|
+
waiting = [];
|
|
209
|
+
/** The places taken */
|
|
210
|
+
taken = 0;
|
|
211
|
+
nextId = 1;
|
|
212
|
+
closed = false;
|
|
213
|
+
/**
|
|
214
|
+
* @param options - Its worker factory, its width, the port each worker is
|
|
215
|
+
* handed, and how long a worker may take to start
|
|
216
|
+
* @throws {RangeError} When the width is not a whole number of at least one,
|
|
217
|
+
* or none is given and the platform reports no cores
|
|
218
|
+
*/
|
|
219
|
+
constructor(options) {
|
|
220
|
+
this.options = options;
|
|
221
|
+
const width = options.width ?? globalThis.navigator?.hardwareConcurrency;
|
|
222
|
+
if (width === undefined || !Number.isSafeInteger(width) || width < 1) {
|
|
223
|
+
throw new RangeError(`a unit pool's width is a whole number of at least one, not ${width}: set it where the platform reports no cores`);
|
|
224
|
+
}
|
|
225
|
+
this.width = width;
|
|
226
|
+
this.startTimeoutMs = options.startTimeoutMs ?? START_TIMEOUT_MS;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Runs a unit on a worker of the pool, once it has a place.
|
|
230
|
+
*
|
|
231
|
+
* @param unit - The unit
|
|
232
|
+
* @param files - Every file it names, by its path relative to the unit: the
|
|
233
|
+
* bytes are the worker's once sent, so a caller keeps none of them
|
|
234
|
+
* @param options - Its signal and timeout, what hears its console and its
|
|
235
|
+
* wait for a place, and what records it running
|
|
236
|
+
* @returns How its run ended
|
|
237
|
+
* @throws {Error} When the pool is closed, or `onStart` throws.
|
|
238
|
+
*/
|
|
239
|
+
async run(unit, files, options = {}) {
|
|
240
|
+
if (this.closed)
|
|
241
|
+
throw new Error('the unit pool is closed');
|
|
242
|
+
const placed = await this.place(options);
|
|
243
|
+
if (placed === 'aborted')
|
|
244
|
+
return { kind: 'aborted', started: false };
|
|
245
|
+
if (placed === 'closed')
|
|
246
|
+
return { kind: 'failed', message: 'the unit pool was closed' };
|
|
247
|
+
let worker;
|
|
248
|
+
try {
|
|
249
|
+
try {
|
|
250
|
+
worker = this.idle.pop() ?? this.start();
|
|
251
|
+
}
|
|
252
|
+
catch (err) {
|
|
253
|
+
return { kind: 'failed', message: `the unit worker did not start: ${messageOf(err)}` };
|
|
254
|
+
}
|
|
255
|
+
try {
|
|
256
|
+
await worker.ready;
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
return { kind: 'failed', message: messageOf(err) };
|
|
260
|
+
}
|
|
261
|
+
if (options.signal?.aborted)
|
|
262
|
+
return { kind: 'aborted', started: false };
|
|
263
|
+
await options.onStart?.();
|
|
264
|
+
return await worker.run(this.nextId++, encodeBeast2For(UnitType)(unit), [...files], options);
|
|
265
|
+
}
|
|
266
|
+
finally {
|
|
267
|
+
if (worker !== undefined && !worker.gone && !this.closed)
|
|
268
|
+
this.idle.push(worker);
|
|
269
|
+
this.leave();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Terminates every worker, whatever it runs, and refuses every unit after:
|
|
274
|
+
* a unit running fails, and one waiting for its place never runs.
|
|
275
|
+
*/
|
|
276
|
+
close() {
|
|
277
|
+
if (this.closed)
|
|
278
|
+
return;
|
|
279
|
+
this.closed = true;
|
|
280
|
+
for (const waiter of this.waiting.splice(0))
|
|
281
|
+
waiter.answer('closed');
|
|
282
|
+
for (const worker of [...this.live])
|
|
283
|
+
worker.terminate();
|
|
284
|
+
this.idle.length = 0;
|
|
285
|
+
}
|
|
286
|
+
/** Starts a worker. */
|
|
287
|
+
start() {
|
|
288
|
+
const connection = this.options.connect?.() ?? null;
|
|
289
|
+
let unit;
|
|
290
|
+
try {
|
|
291
|
+
unit = this.options.units();
|
|
292
|
+
}
|
|
293
|
+
catch (err) {
|
|
294
|
+
connection?.close();
|
|
295
|
+
throw err;
|
|
296
|
+
}
|
|
297
|
+
const worker = new PooledWorker(unit, connection, this.startTimeoutMs, (gone) => {
|
|
298
|
+
this.live.delete(gone);
|
|
299
|
+
const at = this.idle.indexOf(gone);
|
|
300
|
+
if (at >= 0)
|
|
301
|
+
this.idle.splice(at, 1);
|
|
302
|
+
});
|
|
303
|
+
this.live.add(worker);
|
|
304
|
+
return worker;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Takes a place for a unit: at once while the pool has one, and otherwise
|
|
308
|
+
* once a unit before it leaves one.
|
|
309
|
+
*
|
|
310
|
+
* @returns Whether it took one: not when the run was aborted, or the pool
|
|
311
|
+
* closed, while it waited
|
|
312
|
+
*/
|
|
313
|
+
async place(options) {
|
|
314
|
+
if (options.signal?.aborted)
|
|
315
|
+
return 'aborted';
|
|
316
|
+
if (this.taken < this.width) {
|
|
317
|
+
this.taken++;
|
|
318
|
+
return 'placed';
|
|
319
|
+
}
|
|
320
|
+
options.onWaiting?.(0);
|
|
321
|
+
try {
|
|
322
|
+
return await new Promise((resolve) => {
|
|
323
|
+
const waiter = {
|
|
324
|
+
answer: (placed) => {
|
|
325
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
326
|
+
resolve(placed);
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
const onAbort = () => {
|
|
330
|
+
const at = this.waiting.indexOf(waiter);
|
|
331
|
+
if (at >= 0)
|
|
332
|
+
this.waiting.splice(at, 1);
|
|
333
|
+
waiter.answer('aborted');
|
|
334
|
+
};
|
|
335
|
+
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
336
|
+
this.waiting.push(waiter);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
finally {
|
|
340
|
+
options.onWaiting?.(null);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/** Leaves a place: to the unit waiting longest, or free. */
|
|
344
|
+
leave() {
|
|
345
|
+
const next = this.waiting.shift();
|
|
346
|
+
if (next !== undefined)
|
|
347
|
+
next.answer('placed');
|
|
348
|
+
else
|
|
349
|
+
this.taken--;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
//# sourceMappingURL=pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/execution/pool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,eAAe,EAAE,eAAe,EAA8B,MAAM,eAAe,CAAC;AACvH,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAsD,MAAM,eAAe,CAAC;AAE/F,yDAAyD;AACzD,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAyFhC,+DAA+D;AAC/D,MAAM,YAAY;IAoBG;IACA;IAEA;IAtBnB;0BACsB;IACb,KAAK,CAAgB;IAC9B,yEAAyE;IACjE,KAAK,GAAkB,IAAI,CAAC;IAC5B,QAAQ,GAAoB,IAAI,CAAC;IACjC,WAAW,CAAc;IACzB,WAAW,CAAwB;IAC1B,UAAU,CAAgC;IAC3D,0EAA0E;IACzD,MAAM,GAAG,IAAI,eAAe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wBACjB,OAAO,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;wBACtD,OAAO,CAAC,MAAM,CAAC,CAAC;oBAClB,CAAC;iBACF,CAAC;gBACF,MAAM,OAAO,GAAG,GAAS,EAAE;oBACzB,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;oBACxC,IAAI,EAAE,IAAI,CAAC;wBAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;oBACxC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;gBAC3B,CAAC,CAAC;gBACF,OAAO,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;gBACnE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;QACL,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,4DAA4D;IACpD,KAAK;QACX,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAClC,IAAI,IAAI,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;;YACzC,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.spec.d.ts","sourceRoot":"","sources":["../../../src/execution/pool.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The unit protocol's edges, which a working worker never shows: the pool
|
|
7
|
+
* over workers that never start, fail, cannot run a unit or answer what does
|
|
8
|
+
* not decode, and a pool closed with units in it; what a message moves rather
|
|
9
|
+
* than copies; the unit server's answers to a host; the in-process host's
|
|
10
|
+
* terminate, which leaves no timer of the unit's behind; and what refuses to
|
|
11
|
+
* be set up wrong. Every unit a worker runs is the runner cases' business
|
|
12
|
+
* (`WebTaskRunner.spec.ts`, and in Chromium `../browser/runner.spec.ts`).
|
|
13
|
+
*/
|
|
14
|
+
import { describe, it } from 'node:test';
|
|
15
|
+
import assert from 'node:assert/strict';
|
|
16
|
+
import { East, NullType, encodeEastIR, variant } from '@elaraai/east';
|
|
17
|
+
import { callUnitOf } from '@elaraai/e3-core/portable';
|
|
18
|
+
import { Console, Time } from '@elaraai/east-web-std';
|
|
19
|
+
import { MemoryLockSpace } from '../storage/memory.js';
|
|
20
|
+
import { serveUnits } from '../units.js';
|
|
21
|
+
import { inProcessUnits } from './in-process.js';
|
|
22
|
+
import { UnitPool } from './pool.js';
|
|
23
|
+
import { transferOf } from './protocol.js';
|
|
24
|
+
import { UnitServer } from './unit-server.js';
|
|
25
|
+
import { WebTaskRunner } from './WebTaskRunner.js';
|
|
26
|
+
/** A unit, as the pool sends one: a call of a program on a platform-free
|
|
27
|
+
* runner. */
|
|
28
|
+
const UNIT = callUnitOf(variant('east_node', { platforms: [], decode: variant('lazy', null) }), 'program.beast2', [], 'output.beast2', 1, false);
|
|
29
|
+
/**
|
|
30
|
+
* A unit worker that answers as a test says: each message it is sent is
|
|
31
|
+
* handed to `answer` in a later task, as a worker answers.
|
|
32
|
+
*/
|
|
33
|
+
class FakeWorker {
|
|
34
|
+
answer;
|
|
35
|
+
onmessage = null;
|
|
36
|
+
onerror = null;
|
|
37
|
+
sent = [];
|
|
38
|
+
terminated = false;
|
|
39
|
+
constructor(answer = () => { }) {
|
|
40
|
+
this.answer = answer;
|
|
41
|
+
}
|
|
42
|
+
postMessage(message) {
|
|
43
|
+
this.sent.push(message);
|
|
44
|
+
setTimeout(() => this.answer(message, this), 0);
|
|
45
|
+
}
|
|
46
|
+
/** Sends the pool a message, as a worker's script does. */
|
|
47
|
+
say(message) {
|
|
48
|
+
this.onmessage?.(new MessageEvent('message', { data: message }));
|
|
49
|
+
}
|
|
50
|
+
/** Fails, as a worker whose script throws does. */
|
|
51
|
+
fail(message) {
|
|
52
|
+
this.onerror?.({ message, preventDefault: () => { } });
|
|
53
|
+
}
|
|
54
|
+
terminate() {
|
|
55
|
+
this.terminated = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** A worker that serves units, and answers each it is given as `run` says. */
|
|
59
|
+
function serving(run = () => { }) {
|
|
60
|
+
return new FakeWorker((message, worker) => {
|
|
61
|
+
if (message.kind === 'start')
|
|
62
|
+
worker.say({ kind: 'ready', lifeline: null });
|
|
63
|
+
else
|
|
64
|
+
run(message, worker);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** A pool over the workers a list makes, one each time it starts one. */
|
|
68
|
+
function poolOver(workers, options = {}) {
|
|
69
|
+
const started = [];
|
|
70
|
+
const pool = new UnitPool({
|
|
71
|
+
units: () => {
|
|
72
|
+
const make = workers[started.length];
|
|
73
|
+
if (make === undefined)
|
|
74
|
+
throw new Error('no more workers');
|
|
75
|
+
const worker = make();
|
|
76
|
+
started.push(worker);
|
|
77
|
+
return worker;
|
|
78
|
+
},
|
|
79
|
+
width: options.width ?? 1,
|
|
80
|
+
...(options.startTimeoutMs !== undefined && { startTimeoutMs: options.startTimeoutMs }),
|
|
81
|
+
});
|
|
82
|
+
return { pool, started };
|
|
83
|
+
}
|
|
84
|
+
/** A run's failure message, or what it was instead. */
|
|
85
|
+
function failure(run) {
|
|
86
|
+
return run.kind === 'failed' ? run.message : `a run that ended ${run.kind}`;
|
|
87
|
+
}
|
|
88
|
+
describe('the unit pool', () => {
|
|
89
|
+
it('is as wide as the machine has cores unless given a width, and refuses one that is not a whole number of at least one', () => {
|
|
90
|
+
assert.equal(new UnitPool({ units: () => new FakeWorker() }).width, navigator.hardwareConcurrency);
|
|
91
|
+
for (const width of [0, -1, 1.5, Number.NaN]) {
|
|
92
|
+
assert.throws(() => new UnitPool({ units: () => new FakeWorker(), width }), {
|
|
93
|
+
name: 'RangeError',
|
|
94
|
+
message: /a unit pool's width is a whole number of at least one/,
|
|
95
|
+
}, `a width of ${width}`);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
it('fails a unit whose worker never starts serving units, naming serveUnits, and starts another for the next', async () => {
|
|
99
|
+
const { pool, started } = poolOver([() => new FakeWorker(), () => new FakeWorker()], { startTimeoutMs: 20 });
|
|
100
|
+
const first = await pool.run(UNIT, []);
|
|
101
|
+
assert.match(failure(first), /^the unit worker did not start serving units in 0\.02 s: its script calls serveUnits\(\) from @elaraai\/e3-web\/units$/);
|
|
102
|
+
assert.equal(started[0].terminated, true, 'the worker is let go');
|
|
103
|
+
await pool.run(UNIT, []);
|
|
104
|
+
assert.equal(started.length, 2, 'the next unit starts a worker of its own');
|
|
105
|
+
pool.close();
|
|
106
|
+
});
|
|
107
|
+
it('fails a unit whose worker fails, with what it said, letting the worker go', async () => {
|
|
108
|
+
const { pool, started } = poolOver([() => serving((_message, worker) => worker.fail('boom')), () => serving()]);
|
|
109
|
+
assert.equal(failure(await pool.run(UNIT, [])), 'the unit worker failed: boom');
|
|
110
|
+
assert.equal(started[0].terminated, true);
|
|
111
|
+
pool.close();
|
|
112
|
+
});
|
|
113
|
+
it('fails a unit its worker could not run, or whose result does not decode, and keeps the worker for the next', async () => {
|
|
114
|
+
const { pool, started } = poolOver([() => serving((message, worker) => {
|
|
115
|
+
if (message.id === 1)
|
|
116
|
+
worker.say({ kind: 'broken', id: message.id, message: 'no such unit' });
|
|
117
|
+
else
|
|
118
|
+
worker.say({ kind: 'done', id: message.id, result: new Uint8Array([1, 2, 3]), files: [] });
|
|
119
|
+
})]);
|
|
120
|
+
assert.equal(failure(await pool.run(UNIT, [])), 'the unit worker could not run the unit: no such unit');
|
|
121
|
+
assert.match(failure(await pool.run(UNIT, [])), /^the unit worker's result does not decode: /);
|
|
122
|
+
assert.equal(started.length, 1, 'one worker ran both');
|
|
123
|
+
assert.equal(started[0].terminated, false);
|
|
124
|
+
assert.deepEqual(started[0].sent.map(({ kind }) => kind), ['start', 'run', 'run']);
|
|
125
|
+
pool.close();
|
|
126
|
+
});
|
|
127
|
+
it('runs no unit whose run was aborted before it had a place', async () => {
|
|
128
|
+
const { pool, started } = poolOver([() => serving()]);
|
|
129
|
+
assert.deepEqual(await pool.run(UNIT, [], { signal: AbortSignal.abort() }), { kind: 'aborted', started: false });
|
|
130
|
+
assert.equal(started.length, 0, 'no worker was started for it');
|
|
131
|
+
pool.close();
|
|
132
|
+
});
|
|
133
|
+
it('fails the units in it once closed, the one running and the one waiting, and refuses any after', async () => {
|
|
134
|
+
const { pool, started } = poolOver([() => serving()]);
|
|
135
|
+
const running = pool.run(UNIT, []);
|
|
136
|
+
const waited = [];
|
|
137
|
+
const waiting = pool.run(UNIT, [], { onWaiting: (needs) => waited.push(needs) });
|
|
138
|
+
while (started[0]?.sent.some(({ kind }) => kind === 'run') !== true || waited.length === 0)
|
|
139
|
+
await new Promise((resolve) => setTimeout(resolve, 1));
|
|
140
|
+
pool.close();
|
|
141
|
+
assert.equal(failure(await running), 'the unit pool was closed');
|
|
142
|
+
assert.equal(failure(await waiting), 'the unit pool was closed');
|
|
143
|
+
assert.deepEqual(waited, [0, null]);
|
|
144
|
+
assert.equal(started[0].terminated, true, 'its worker is terminated');
|
|
145
|
+
await assert.rejects(pool.run(UNIT, []), /the unit pool is closed/);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
describe('the unit protocol', () => {
|
|
149
|
+
it('moves only the buffers a file\'s bytes are the whole of, each once', () => {
|
|
150
|
+
const whole = new Uint8Array([1, 2, 3]);
|
|
151
|
+
const pooled = new Uint8Array(16);
|
|
152
|
+
const shared = new Uint8Array(new SharedArrayBuffer(4));
|
|
153
|
+
assert.deepEqual(transferOf([['a', whole], ['b', whole], ['c', pooled.subarray(4, 8)], ['d', shared]]), [whole.buffer], 'a view into a larger buffer, or into shared memory, is copied with the message');
|
|
154
|
+
});
|
|
155
|
+
it('serves a host: answers start ready, and a unit that does not decode broken, naming why', async () => {
|
|
156
|
+
const said = [];
|
|
157
|
+
const server = new UnitServer({ postMessage: (message) => said.push(message) }, { platforms: {} });
|
|
158
|
+
await server.receive({ kind: 'start', port: null });
|
|
159
|
+
await server.receive({ kind: 'run', id: 7, unit: new Uint8Array([1, 2, 3]), files: [] });
|
|
160
|
+
assert.equal(said.length, 2);
|
|
161
|
+
assert.deepEqual(said[0], { kind: 'ready', lifeline: null }, 'a server that takes no lifeline names none');
|
|
162
|
+
const broken = said[1];
|
|
163
|
+
assert.ok(broken.kind === 'broken' && broken.id === 7 && /^the unit does not decode: /.test(broken.message), JSON.stringify(broken));
|
|
164
|
+
});
|
|
165
|
+
it('serves units only in a dedicated Web Worker', () => {
|
|
166
|
+
assert.throws(() => serveUnits(), /serveUnits serves units in a dedicated Web Worker/);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
/** How long the sleeping unit sleeps: ten minutes, which a timer no one
|
|
170
|
+
* clears holds the process for. */
|
|
171
|
+
const SLEEP_MS = 600_000;
|
|
172
|
+
/**
|
|
173
|
+
* Watches the timers this thread sets for a while: those of a delay, as they
|
|
174
|
+
* are set, and every timer cleared.
|
|
175
|
+
*
|
|
176
|
+
* @param ms - The delay of the timers watched
|
|
177
|
+
* @returns What it saw, and what puts the thread's timers back
|
|
178
|
+
*/
|
|
179
|
+
function watchTimers(ms) {
|
|
180
|
+
const setTimer = globalThis.setTimeout;
|
|
181
|
+
const clearTimer = globalThis.clearTimeout;
|
|
182
|
+
const set = new Set();
|
|
183
|
+
const cleared = new Set();
|
|
184
|
+
globalThis.setTimeout = ((handler, delay, ...args) => {
|
|
185
|
+
const timer = setTimer(handler, delay, ...args);
|
|
186
|
+
if (delay === ms)
|
|
187
|
+
set.add(timer);
|
|
188
|
+
return timer;
|
|
189
|
+
});
|
|
190
|
+
globalThis.clearTimeout = ((timer) => {
|
|
191
|
+
cleared.add(timer);
|
|
192
|
+
clearTimer(timer);
|
|
193
|
+
});
|
|
194
|
+
return {
|
|
195
|
+
set,
|
|
196
|
+
cleared,
|
|
197
|
+
restore: () => {
|
|
198
|
+
globalThis.setTimeout = setTimer;
|
|
199
|
+
globalThis.clearTimeout = clearTimer;
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
describe('the in-process host', () => {
|
|
204
|
+
it('clears the timer of a sleep under way as it terminates the unit\'s worker, so nothing of the unit\'s holds the process', async () => {
|
|
205
|
+
// A program that says it sleeps, and sleeps ten minutes.
|
|
206
|
+
const sleeper = East.asyncFunction([], NullType, ($) => {
|
|
207
|
+
$(Console.log('sleeping'));
|
|
208
|
+
$(Time.sleep(BigInt(SLEEP_MS)));
|
|
209
|
+
});
|
|
210
|
+
const unit = callUnitOf(variant('east_node', { platforms: ['@elaraai/east-node-std'], decode: variant('lazy', null) }), 'program.beast2', [], 'output.beast2', 1, false);
|
|
211
|
+
const pool = new UnitPool({ units: inProcessUnits(), width: 1 });
|
|
212
|
+
const timers = watchTimers(SLEEP_MS);
|
|
213
|
+
try {
|
|
214
|
+
const controller = new AbortController();
|
|
215
|
+
let said = '';
|
|
216
|
+
const running = pool.run(unit, [['program.beast2', encodeEastIR(sleeper.toIR())]], {
|
|
217
|
+
signal: controller.signal,
|
|
218
|
+
onLog: (_stream, text) => {
|
|
219
|
+
said += text;
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
// Its sleep has begun once its timer is set, and what it said has come.
|
|
223
|
+
for (let waited = 0; (timers.set.size === 0 || said === '') && waited < 10_000; waited += 5) {
|
|
224
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
225
|
+
}
|
|
226
|
+
assert.equal(said, 'sleeping\n', 'the unit said it sleeps');
|
|
227
|
+
assert.equal(timers.set.size, 1, 'its sleep set its timer');
|
|
228
|
+
controller.abort();
|
|
229
|
+
assert.deepEqual(await running, { kind: 'aborted', started: true });
|
|
230
|
+
assert.deepEqual([...timers.set].filter((timer) => !timers.cleared.has(timer)), [], 'the sleep\'s timer was cleared: it holds the process for ten minutes no more');
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
timers.restore();
|
|
234
|
+
pool.close();
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
describe('WebTaskRunner\'s options', () => {
|
|
239
|
+
it('refuses a whole-intake limit that is not a whole number of bytes, zero or more', async () => {
|
|
240
|
+
const locks = await new MemoryLockSpace().open();
|
|
241
|
+
const pool = new UnitPool({ units: () => new FakeWorker(), width: 1 });
|
|
242
|
+
for (const wholeIntakeLimit of [-1, 1.5]) {
|
|
243
|
+
assert.throws(() => new WebTaskRunner({ repo: 'default', pool, locks, wholeIntakeLimit }), {
|
|
244
|
+
name: 'RangeError',
|
|
245
|
+
message: /a runner's whole-intake limit is a whole number of bytes, zero or more/,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
assert.equal(new WebTaskRunner({ repo: 'default', pool, locks, wholeIntakeLimit: 0 }).wholeIntakeLimit, 0);
|
|
249
|
+
await locks.close();
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
//# sourceMappingURL=pool.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.spec.js","sourceRoot":"","sources":["../../../src/execution/pool.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE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