@mark1russell7/service 0.8.18 → 0.8.20
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/README.md +19 -0
- package/build/backoff.d.ts +44 -2
- package/build/{builder-zO48Vgoj.d.ts → builder.d.ts} +14 -101
- package/build/builder.js +499 -0
- package/build/builder.js.map +1 -0
- package/build/{call-context-DDhcVvn5.d.ts → call-context.d.ts} +3 -4
- package/build/channel.d.ts +1 -1
- package/build/{core-BSzt4RI2.d.ts → client/core.d.ts} +32 -61
- package/build/{machine-BhVeHr_m.js → client/core.js} +4 -153
- package/build/client/core.js.map +1 -0
- package/build/{dial-ChwIcvd4.d.ts → client/dial.d.ts} +3 -4
- package/build/client/dial.js +52 -0
- package/build/client/dial.js.map +1 -0
- package/build/client/machine.js +29 -0
- package/build/client/machine.js.map +1 -0
- package/build/client/meets.d.ts +35 -0
- package/build/client/meets.js +78 -0
- package/build/client/meets.js.map +1 -0
- package/build/clock.d.ts +1 -1
- package/build/conformance.d.ts +122 -0
- package/build/conformance.js +470 -0
- package/build/conformance.js.map +1 -0
- package/build/contract.d.ts +28 -0
- package/build/contract.js +184 -0
- package/build/contract.js.map +1 -0
- package/build/description.d.ts +161 -0
- package/build/description.js +11 -0
- package/build/description.js.map +1 -0
- package/build/drains.js +35 -0
- package/build/drains.js.map +1 -0
- package/build/events.d.ts +25 -0
- package/build/fakes.d.ts +43 -0
- package/build/fakes.js +93 -0
- package/build/fakes.js.map +1 -0
- package/build/grpc/client.d.ts +153 -0
- package/build/grpc/client.js +474 -0
- package/build/grpc/client.js.map +1 -0
- package/build/grpc/connection.d.ts +97 -0
- package/build/grpc/connection.js +59 -0
- package/build/grpc/connection.js.map +1 -0
- package/build/grpc/machine.d.ts +12 -0
- package/build/grpc/machine.js +149 -0
- package/build/grpc/machine.js.map +1 -0
- package/build/grpc/meets.d.ts +14 -0
- package/build/grpc/meets.js +105 -0
- package/build/grpc/meets.js.map +1 -0
- package/build/grpc/starting.d.ts +33 -0
- package/build/grpc/starting.js +89 -0
- package/build/grpc/starting.js.map +1 -0
- package/build/grpc.d.ts +9 -303
- package/build/grpc.js +7 -854
- package/build/health.d.ts +93 -0
- package/build/health.js +223 -0
- package/build/health.js.map +1 -0
- package/build/heartbeat.d.ts +1 -1
- package/build/host/discovery.d.ts +61 -0
- package/build/host/discovery.js +113 -0
- package/build/host/discovery.js.map +1 -0
- package/build/host/env.d.ts +14 -0
- package/build/host/env.js +57 -0
- package/build/host/env.js.map +1 -0
- package/build/host/fakes.d.ts +82 -0
- package/build/host/fakes.js +239 -0
- package/build/host/fakes.js.map +1 -0
- package/build/host/group.d.ts +142 -0
- package/build/host/group.js +517 -0
- package/build/host/group.js.map +1 -0
- package/build/host/install.d.ts +96 -0
- package/build/host/install.js +330 -0
- package/build/host/install.js.map +1 -0
- package/build/host/lock.d.ts +78 -0
- package/build/host/lock.js +190 -0
- package/build/host/lock.js.map +1 -0
- package/build/host/logs.d.ts +26 -0
- package/build/host/logs.js +48 -0
- package/build/host/logs.js.map +1 -0
- package/build/host/node.d.ts +14 -0
- package/build/host/node.js +309 -0
- package/build/host/node.js.map +1 -0
- package/build/{ports-B1ayTL-j.d.ts → host/ports.d.ts} +15 -16
- package/build/host/ports.js +17 -0
- package/build/host/ports.js.map +1 -0
- package/build/host/probes.d.ts +51 -0
- package/build/host/probes.js +139 -0
- package/build/host/probes.js.map +1 -0
- package/build/host/processes.d.ts +32 -0
- package/build/host/processes.js +63 -0
- package/build/host/processes.js.map +1 -0
- package/build/host/render.d.ts +84 -0
- package/build/host/render.js +235 -0
- package/build/host/render.js.map +1 -0
- package/build/host/watch.d.ts +90 -0
- package/build/host/watch.js +165 -0
- package/build/host/watch.js.map +1 -0
- package/build/host.d.ts +13 -671
- package/build/host.js +12 -2126
- package/build/http/answers.js +29 -0
- package/build/http/answers.js.map +1 -0
- package/build/http/fake-server.js +61 -0
- package/build/http/fake-server.js.map +1 -0
- package/build/http/outcome.d.ts +115 -0
- package/build/http/outcome.js +325 -0
- package/build/http/outcome.js.map +1 -0
- package/build/http/probes.d.ts +83 -0
- package/build/http/probes.js +232 -0
- package/build/http/probes.js.map +1 -0
- package/build/http/transport.d.ts +165 -0
- package/build/http/transport.js +517 -0
- package/build/http/transport.js.map +1 -0
- package/build/http-client/client.d.ts +121 -0
- package/build/http-client/client.js +330 -0
- package/build/http-client/client.js.map +1 -0
- package/build/http-client/connection.d.ts +78 -0
- package/build/http-client/connection.js +54 -0
- package/build/http-client/connection.js.map +1 -0
- package/build/http-client/machine.d.ts +14 -0
- package/build/http-client/machine.js +109 -0
- package/build/http-client/machine.js.map +1 -0
- package/build/http-client/meets.d.ts +11 -0
- package/build/http-client/meets.js +74 -0
- package/build/http-client/meets.js.map +1 -0
- package/build/http-client/session.d.ts +87 -0
- package/build/http-client/session.js +99 -0
- package/build/http-client/session.js.map +1 -0
- package/build/http-client/starting.d.ts +25 -0
- package/build/http-client/starting.js +65 -0
- package/build/http-client/starting.js.map +1 -0
- package/build/http-client.d.ts +9 -330
- package/build/http-client.js +8 -707
- package/build/http.d.ts +5 -353
- package/build/http.js +3 -1086
- package/build/identity.d.ts +16 -0
- package/build/identity.js +44 -0
- package/build/identity.js.map +1 -0
- package/build/index.d.ts +35 -412
- package/build/index.js +24 -3277
- package/build/knobs.d.ts +1 -0
- package/build/{knobs-BJcz6m01.js → knobs.js} +2 -34
- package/build/knobs.js.map +1 -0
- package/build/latch.d.ts +29 -0
- package/build/latch.js +122 -0
- package/build/latch.js.map +1 -0
- package/build/{rules-HyFCBStQ.d.ts → law.d.ts} +19 -37
- package/build/law.js +149 -0
- package/build/law.js.map +1 -0
- package/build/lifecycle.d.ts +144 -0
- package/build/lifecycle.js +411 -0
- package/build/lifecycle.js.map +1 -0
- package/build/limiter/machine.d.ts +40 -0
- package/build/limiter/machine.js +279 -0
- package/build/limiter/machine.js.map +1 -0
- package/build/{policy-CBcK2XGg.d.ts → limiter/policy.d.ts} +28 -29
- package/build/{policy-UYALkqVq.js → limiter/policy.js} +10 -9
- package/build/limiter/policy.js.map +1 -0
- package/build/{limiter-Cm8nC-Gd.d.ts → limiter/quota.d.ts} +50 -76
- package/build/{limiter-Bgy6Gmvl.js → limiter/quota.js} +32 -425
- package/build/limiter/quota.js.map +1 -0
- package/build/{store-DFwFKrsB.d.ts → limiter/store.d.ts} +10 -11
- package/build/limiter/store.js +145 -0
- package/build/limiter/store.js.map +1 -0
- package/build/limiter.d.ts +4 -3
- package/build/limiter.js +4 -2
- package/build/lint.d.ts +152 -0
- package/build/lint.js +576 -0
- package/build/lint.js.map +1 -0
- package/build/logger.d.ts +71 -0
- package/build/logger.js +183 -0
- package/build/logger.js.map +1 -0
- package/build/machines.d.ts +41 -0
- package/build/machines.js +451 -0
- package/build/machines.js.map +1 -0
- package/build/metrics.d.ts +53 -0
- package/build/metrics.js +111 -0
- package/build/metrics.js.map +1 -0
- package/build/mongodb/client.d.ts +131 -0
- package/build/mongodb/client.js +388 -0
- package/build/mongodb/client.js.map +1 -0
- package/build/mongodb/connection.d.ts +112 -0
- package/build/mongodb/connection.js +12 -0
- package/build/mongodb/connection.js.map +1 -0
- package/build/mongodb/machine.d.ts +14 -0
- package/build/mongodb/machine.js +122 -0
- package/build/mongodb/machine.js.map +1 -0
- package/build/mongodb/meets.d.ts +15 -0
- package/build/mongodb/meets.js +103 -0
- package/build/mongodb/meets.js.map +1 -0
- package/build/mongodb/starting.d.ts +29 -0
- package/build/mongodb/starting.js +77 -0
- package/build/mongodb/starting.js.map +1 -0
- package/build/mongodb.d.ts +8 -296
- package/build/mongodb.js +7 -682
- package/build/operation.d.ts +27 -0
- package/build/{operation-DF73RZOI.js → operation.js} +2 -2
- package/build/operation.js.map +1 -0
- package/build/otel.d.ts +2 -2
- package/build/pg/client.d.ts +96 -0
- package/build/pg/client.js +277 -0
- package/build/pg/client.js.map +1 -0
- package/build/pg/connection.d.ts +75 -0
- package/build/pg/connection.js +11 -0
- package/build/pg/connection.js.map +1 -0
- package/build/pg/machine.d.ts +13 -0
- package/build/pg/machine.js +111 -0
- package/build/pg/machine.js.map +1 -0
- package/build/pg/meets.d.ts +14 -0
- package/build/pg/meets.js +83 -0
- package/build/pg/meets.js.map +1 -0
- package/build/pg/starting.d.ts +26 -0
- package/build/pg/starting.js +62 -0
- package/build/pg/starting.js.map +1 -0
- package/build/pg.d.ts +8 -219
- package/build/pg.js +7 -525
- package/build/poller.d.ts +9 -0
- package/build/poller.js +152 -0
- package/build/poller.js.map +1 -0
- package/build/process.d.ts +114 -0
- package/build/process.js +170 -0
- package/build/process.js.map +1 -0
- package/build/profiles.d.ts +68 -0
- package/build/profiles.js +120 -0
- package/build/profiles.js.map +1 -0
- package/build/{queue-DXdw1vLO.d.ts → queue.d.ts} +16 -29
- package/build/queue.js +279 -0
- package/build/queue.js.map +1 -0
- package/build/rabbitmq/client.d.ts +144 -0
- package/build/rabbitmq/client.js +426 -0
- package/build/rabbitmq/client.js.map +1 -0
- package/build/rabbitmq/connection.d.ts +91 -0
- package/build/rabbitmq/connection.js +15 -0
- package/build/rabbitmq/connection.js.map +1 -0
- package/build/rabbitmq/machine.d.ts +13 -0
- package/build/rabbitmq/machine.js +159 -0
- package/build/rabbitmq/machine.js.map +1 -0
- package/build/rabbitmq/meets.d.ts +12 -0
- package/build/rabbitmq/meets.js +96 -0
- package/build/rabbitmq/meets.js.map +1 -0
- package/build/rabbitmq/starting.d.ts +27 -0
- package/build/rabbitmq/starting.js +67 -0
- package/build/rabbitmq/starting.js.map +1 -0
- package/build/rabbitmq.d.ts +8 -283
- package/build/rabbitmq.js +7 -742
- package/build/redis/client.d.ts +86 -0
- package/build/redis/client.js +285 -0
- package/build/redis/client.js.map +1 -0
- package/build/redis/connection.d.ts +57 -0
- package/build/redis/connection.js +11 -0
- package/build/redis/connection.js.map +1 -0
- package/build/redis/limiter.d.ts +43 -0
- package/build/redis/limiter.js +164 -0
- package/build/redis/limiter.js.map +1 -0
- package/build/redis/machine.d.ts +12 -0
- package/build/redis/machine.js +144 -0
- package/build/redis/machine.js.map +1 -0
- package/build/redis/meets.d.ts +11 -0
- package/build/redis/meets.js +75 -0
- package/build/redis/meets.js.map +1 -0
- package/build/redis/operations.d.ts +5 -0
- package/build/redis/operations.js +114 -0
- package/build/redis/operations.js.map +1 -0
- package/build/redis.d.ts +10 -207
- package/build/redis.js +9 -771
- package/build/requests.d.ts +66 -0
- package/build/requests.js +279 -0
- package/build/requests.js.map +1 -0
- package/build/retrier.d.ts +62 -0
- package/build/{retrier-Dnjhvxol.js → retrier.js} +2 -2
- package/build/retrier.js.map +1 -0
- package/build/routes.d.ts +35 -0
- package/build/routes.js +77 -0
- package/build/routes.js.map +1 -0
- package/build/rules.d.ts +19 -2
- package/build/stops.d.ts +51 -0
- package/build/stops.js +86 -0
- package/build/stops.js.map +1 -0
- package/build/testing.d.ts +8 -270
- package/build/testing.js +4 -1027
- package/build/testing.js.map +1 -1
- package/build/timing.d.ts +63 -0
- package/build/{timing-DZl36uXs.js → timing.js} +2 -2
- package/build/timing.js.map +1 -0
- package/build/units.d.ts +17 -0
- package/build/units.js +236 -0
- package/build/units.js.map +1 -0
- package/build/watchdog.d.ts +34 -0
- package/build/watchdog.js +53 -0
- package/build/watchdog.js.map +1 -0
- package/build/websocket/client.d.ts +136 -0
- package/build/websocket/client.js +422 -0
- package/build/websocket/client.js.map +1 -0
- package/build/websocket/connection.d.ts +83 -0
- package/build/websocket/connection.js +57 -0
- package/build/websocket/connection.js.map +1 -0
- package/build/websocket/machine.d.ts +12 -0
- package/build/websocket/machine.js +155 -0
- package/build/websocket/machine.js.map +1 -0
- package/build/websocket/meets.d.ts +14 -0
- package/build/websocket/meets.js +92 -0
- package/build/websocket/meets.js.map +1 -0
- package/build/websocket/starting.d.ts +25 -0
- package/build/websocket/starting.js +69 -0
- package/build/websocket/starting.js.map +1 -0
- package/build/websocket.d.ts +9 -264
- package/build/websocket.js +8 -774
- package/build/worker.d.ts +92 -0
- package/build/worker.js +153 -0
- package/build/worker.js.map +1 -0
- package/package.json +4 -3
- package/build/backoff-QTRGfkEK.d.ts +0 -45
- package/build/clock-DpVgpY4h.d.ts +0 -2
- package/build/grpc.js.map +0 -1
- package/build/host.js.map +0 -1
- package/build/http-client.js.map +0 -1
- package/build/http.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/knobs-BJcz6m01.js.map +0 -1
- package/build/lifecycle-D0J-zwZF.d.ts +0 -374
- package/build/limiter-Bgy6Gmvl.js.map +0 -1
- package/build/logger-B6drv9w0.d.ts +0 -488
- package/build/machine-BhVeHr_m.js.map +0 -1
- package/build/mongodb.js.map +0 -1
- package/build/operation-DF73RZOI.js.map +0 -1
- package/build/pg.js.map +0 -1
- package/build/policy-UYALkqVq.js.map +0 -1
- package/build/process-7R9M29wN.js +0 -437
- package/build/process-7R9M29wN.js.map +0 -1
- package/build/rabbitmq.js.map +0 -1
- package/build/redis.js.map +0 -1
- package/build/requests-DD2ALv0_.js +0 -583
- package/build/requests-DD2ALv0_.js.map +0 -1
- package/build/retrier-Dnjhvxol.js.map +0 -1
- package/build/timing-DZl36uXs.js.map +0 -1
- package/build/websocket.js.map +0 -1
package/build/testing.js
CHANGED
|
@@ -1,1031 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { valueIn } from "@mark1russell7/quantity";
|
|
6
|
-
import { delay, fakeClock } from "@mark1russell7/algebra/clock";
|
|
1
|
+
import { fakeClock, fakeProcess, seeded } from "./fakes.js";
|
|
2
|
+
import { contractCases } from "./contract.js";
|
|
3
|
+
import { detachedLifecycle, transportConformance } from "./conformance.js";
|
|
4
|
+
import { fakeHost } from "./host/fakes.js";
|
|
7
5
|
import { createServer } from "node:net";
|
|
8
|
-
import { mulberry32 } from "@mark1russell7/rigor-generators";
|
|
9
|
-
import "node:events";
|
|
10
|
-
// src/fakes.ts
|
|
11
|
-
/** This function makes a fake process. */
|
|
12
|
-
const fakeProcess = (options = {}) => {
|
|
13
|
-
const handlers = /* @__PURE__ */ new Map();
|
|
14
|
-
const uncaughtHandlers = /* @__PURE__ */ new Set();
|
|
15
|
-
const exits = [];
|
|
16
|
-
const log = [];
|
|
17
|
-
let flushes = 0;
|
|
18
|
-
let holds = 0;
|
|
19
|
-
const heldAtExit = [];
|
|
20
|
-
const stamp = (what) => {
|
|
21
|
-
log.push(options.clock === void 0 ? what : `${options.clock.now()} ${what}`);
|
|
22
|
-
};
|
|
23
|
-
const send = (name, message) => {
|
|
24
|
-
for (const handler of [...handlers.get(name) ?? []]) handler(message);
|
|
25
|
-
};
|
|
26
|
-
return {
|
|
27
|
-
on(trigger, handler) {
|
|
28
|
-
const set = handlers.get(trigger) ?? /* @__PURE__ */ new Set();
|
|
29
|
-
set.add(handler);
|
|
30
|
-
handlers.set(trigger, set);
|
|
31
|
-
return () => {
|
|
32
|
-
set.delete(handler);
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
onUncaught(handler) {
|
|
36
|
-
const own = (error, origin) => handler(error, origin);
|
|
37
|
-
uncaughtHandlers.add(own);
|
|
38
|
-
return () => {
|
|
39
|
-
uncaughtHandlers.delete(own);
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
async flush() {
|
|
43
|
-
stamp("flush");
|
|
44
|
-
await options.flush?.();
|
|
45
|
-
flushes += 1;
|
|
46
|
-
stamp("flushed");
|
|
47
|
-
},
|
|
48
|
-
hold() {
|
|
49
|
-
holds += 1;
|
|
50
|
-
let held = true;
|
|
51
|
-
return () => {
|
|
52
|
-
if (!held) return;
|
|
53
|
-
held = false;
|
|
54
|
-
holds -= 1;
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
exit(code) {
|
|
58
|
-
stamp(`exit ${code}`);
|
|
59
|
-
heldAtExit.push(holds);
|
|
60
|
-
exits.push(code);
|
|
61
|
-
},
|
|
62
|
-
signal: (name) => send(name),
|
|
63
|
-
trigger: (name) => send(name),
|
|
64
|
-
message: (value) => send("ipc-message", value),
|
|
65
|
-
uncaught: (error, origin = "uncaughtException") => {
|
|
66
|
-
for (const handler of [...uncaughtHandlers]) handler(error, origin);
|
|
67
|
-
},
|
|
68
|
-
get exits() {
|
|
69
|
-
return [...exits];
|
|
70
|
-
},
|
|
71
|
-
get handlers() {
|
|
72
|
-
let count = uncaughtHandlers.size;
|
|
73
|
-
for (const set of handlers.values()) count += set.size;
|
|
74
|
-
return count;
|
|
75
|
-
},
|
|
76
|
-
get triggers() {
|
|
77
|
-
return [...handlers.keys()];
|
|
78
|
-
},
|
|
79
|
-
get log() {
|
|
80
|
-
return [...log];
|
|
81
|
-
},
|
|
82
|
-
get flushes() {
|
|
83
|
-
return flushes;
|
|
84
|
-
},
|
|
85
|
-
get holds() {
|
|
86
|
-
return holds;
|
|
87
|
-
},
|
|
88
|
-
get heldAtExit() {
|
|
89
|
-
return [...heldAtExit];
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* This function gives a seeded random number generator (mulberry32), with numbers in [0, 1). It is
|
|
95
|
-
* `mulberry32` of @mark1russell7/rigor-generators.
|
|
96
|
-
*/
|
|
97
|
-
const seeded = (seed) => mulberry32(seed);
|
|
98
|
-
// src/contract.ts
|
|
99
|
-
const ms = (amount) => valueIn(amount, "ms");
|
|
100
|
-
/** The part of a verdict that the contract compares: what a caller and the platform see. */
|
|
101
|
-
const visible = (verdict) => ({
|
|
102
|
-
ready: verdict.ready,
|
|
103
|
-
alive: verdict.alive,
|
|
104
|
-
controllers: verdict.controllers,
|
|
105
|
-
dependencies: verdict.dependencies
|
|
106
|
-
});
|
|
107
|
-
const same = (expected, actual) => JSON.stringify(expected) === JSON.stringify(actual);
|
|
108
|
-
const failure = (what, expected, actual) => /* @__PURE__ */ new Error(`${what}: expected ${JSON.stringify(expected)}, but the verdict was ${JSON.stringify(actual)}`);
|
|
109
|
-
/**
|
|
110
|
-
* This function generates the contract test of a declaration. `declare` gives a new builder with
|
|
111
|
-
* the declaration and the function of each check, each time. The checks must pass at rest. The
|
|
112
|
-
* cases are:
|
|
113
|
-
* - The service at rest: each controller and each dependency is ready, and the service is alive.
|
|
114
|
-
* - Each dependency unavailable: its polls fail at once (the force-fail list). The dependency and
|
|
115
|
-
* each controller that needs it become not ready, and the other controllers stay ready. Liveness
|
|
116
|
-
* stays, unless a liveness check exercises the dependency.
|
|
117
|
-
* - Each dependency degraded: each call of its checks takes the latency longer. Nothing can fail.
|
|
118
|
-
* - Each dependency recovers: after it is unavailable, the service is again at rest.
|
|
119
|
-
* - A negative control: a client that the declaration does not name fails, and nothing changes.
|
|
120
|
-
*
|
|
121
|
-
* A dependency that no check exercises is a finding: the service cannot see it fail.
|
|
122
|
-
*/
|
|
123
|
-
const contractCases = (declare, options = {}) => {
|
|
124
|
-
const degradeBy = options.degradeBy ?? 100;
|
|
125
|
-
const seed = options.seed ?? 1;
|
|
126
|
-
const description = declare().describe();
|
|
127
|
-
const service = description.name;
|
|
128
|
-
const gating = description.checks.filter((check) => check.gates !== null);
|
|
129
|
-
const timingOf = (check) => description.policies[check.gates];
|
|
130
|
-
const failMax = (check) => ms(failSpan(timingOf(check), check.poll, "error").max);
|
|
131
|
-
const recoverMax = (check) => ms(recoverSpan(timingOf(check), check.poll).max);
|
|
132
|
-
const most = (values) => values.reduce((a, b) => Math.max(a, b), 0);
|
|
133
|
-
const settleTime = most(gating.filter((check) => check.gates === "readiness").map(recoverMax)) + 1;
|
|
134
|
-
const quietTime = most(gating.map(failMax)) + 1;
|
|
135
|
-
/** This function starts the declaration on a fake clock, and moves it to rest. */
|
|
136
|
-
const boot = async (extra = () => ({})) => {
|
|
137
|
-
const clock = fakeClock();
|
|
138
|
-
const starting = declare().start({
|
|
139
|
-
clock,
|
|
140
|
-
random: seeded(seed),
|
|
141
|
-
...extra(clock)
|
|
142
|
-
});
|
|
143
|
-
let started = false;
|
|
144
|
-
starting.then(() => started = true, () => started = true);
|
|
145
|
-
for (let step = 0; step < 1e3 && !started; step += 1) await clock.advance(10);
|
|
146
|
-
const health = await starting;
|
|
147
|
-
await clock.advance(settleTime);
|
|
148
|
-
return {
|
|
149
|
-
health,
|
|
150
|
-
clock,
|
|
151
|
-
rest: visible(health.verdict())
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
const stop = (health) => health.stop();
|
|
155
|
-
const cases = [{
|
|
156
|
-
name: `${service}: at rest, each controller and each dependency is ready, and the service is alive`,
|
|
157
|
-
async run() {
|
|
158
|
-
const { health, rest } = await boot();
|
|
159
|
-
try {
|
|
160
|
-
const expected = {
|
|
161
|
-
ready: true,
|
|
162
|
-
alive: true,
|
|
163
|
-
controllers: Object.fromEntries(description.controllers.map((each) => [each.name, true])),
|
|
164
|
-
dependencies: Object.fromEntries(description.dependencies.map((each) => [each.name, true]))
|
|
165
|
-
};
|
|
166
|
-
if (!same(expected, rest)) throw failure("at rest", expected, rest);
|
|
167
|
-
} finally {
|
|
168
|
-
stop(health);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}];
|
|
172
|
-
for (const dependency of description.dependencies) {
|
|
173
|
-
const on = gating.filter((check) => check.dependency === dependency.name);
|
|
174
|
-
const readiness = on.filter((check) => check.gates === "readiness");
|
|
175
|
-
const liveness = on.filter((check) => check.gates === "liveness");
|
|
176
|
-
const unavailable = (rest) => ({
|
|
177
|
-
ready: readiness.length === 0 ? rest.ready : false,
|
|
178
|
-
alive: liveness.length === 0 ? rest.alive : false,
|
|
179
|
-
controllers: Object.fromEntries(description.controllers.map((each) => [each.name, each.requires.includes(dependency.name) && readiness.length > 0 ? false : rest.controllers[each.name]])),
|
|
180
|
-
dependencies: {
|
|
181
|
-
...rest.dependencies,
|
|
182
|
-
[dependency.name]: readiness.length === 0
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
cases.push({
|
|
186
|
-
name: `${service}: ${dependency.name} unavailable`,
|
|
187
|
-
async run() {
|
|
188
|
-
if (on.length === 0) throw new Error(`no check that gates a policy exercises ${dependency.name}: the service cannot see it fail`);
|
|
189
|
-
const { health, clock, rest } = await boot();
|
|
190
|
-
try {
|
|
191
|
-
health.forceFail(dependency.name, true);
|
|
192
|
-
await clock.advance(most(on.map(failMax)) + 1);
|
|
193
|
-
const now = visible(health.verdict());
|
|
194
|
-
const expected = unavailable(rest);
|
|
195
|
-
if (!same(expected, now)) throw failure(`${dependency.name} unavailable`, expected, now);
|
|
196
|
-
} finally {
|
|
197
|
-
stop(health);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
cases.push({
|
|
202
|
-
name: `${service}: ${dependency.name} degraded by ${degradeBy} ms, and nothing fails`,
|
|
203
|
-
async run() {
|
|
204
|
-
const tight = on.filter((check) => ms(check.poll.timeout) <= degradeBy);
|
|
205
|
-
if (tight.length > 0) throw new Error(`${tight.map((check) => `${check.name} times out in ${ms(check.poll.timeout)} ms`).join(", ")}: a latency of ${degradeBy} ms fails it`);
|
|
206
|
-
const { health, clock, rest } = await boot((at) => ({ wrapCheck: (check, run) => check.dependency !== dependency.name ? run : (signal) => new Promise((resolve) => at.after(degradeBy, () => resolve(run(signal)))) }));
|
|
207
|
-
try {
|
|
208
|
-
await clock.advance(quietTime + most(on.map((check) => ms(check.poll.interval))));
|
|
209
|
-
const now = visible(health.verdict());
|
|
210
|
-
if (!same(rest, now)) throw failure(`${dependency.name} degraded`, rest, now);
|
|
211
|
-
} finally {
|
|
212
|
-
stop(health);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
cases.push({
|
|
217
|
-
name: `${service}: ${dependency.name} recovers`,
|
|
218
|
-
async run() {
|
|
219
|
-
if (on.length === 0) throw new Error(`no check that gates a policy exercises ${dependency.name}: the service cannot see it recover`);
|
|
220
|
-
const { health, clock, rest } = await boot();
|
|
221
|
-
try {
|
|
222
|
-
health.forceFail(dependency.name, true);
|
|
223
|
-
await clock.advance(most(on.map(failMax)) + 1);
|
|
224
|
-
health.forceFail(dependency.name, false);
|
|
225
|
-
await clock.advance(most(on.map(recoverMax)) + 1);
|
|
226
|
-
const now = visible(health.verdict());
|
|
227
|
-
if (!same(rest, now)) throw failure(`${dependency.name} recovered`, rest, now);
|
|
228
|
-
} finally {
|
|
229
|
-
stop(health);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
const never = `${service}.client-never-registered`;
|
|
235
|
-
cases.push({
|
|
236
|
-
name: `${service}: a client never registered fails, and nothing changes (the negative control)`,
|
|
237
|
-
async run() {
|
|
238
|
-
if (description.dependencies.some((each) => each.name === never)) throw new Error(`the declaration has a dependency named ${never}`);
|
|
239
|
-
const { health, clock, rest } = await boot();
|
|
240
|
-
try {
|
|
241
|
-
health.forceFail(never, true);
|
|
242
|
-
await clock.advance(quietTime);
|
|
243
|
-
const now = visible(health.verdict());
|
|
244
|
-
if (!same(rest, now)) throw failure("the negative control", rest, now);
|
|
245
|
-
} finally {
|
|
246
|
-
stop(health);
|
|
247
|
-
}
|
|
248
|
-
let refused = false;
|
|
249
|
-
try {
|
|
250
|
-
declare().check({
|
|
251
|
-
name: `${never}.check`,
|
|
252
|
-
dependency: never,
|
|
253
|
-
step: "round-trip",
|
|
254
|
-
ownConnection: true,
|
|
255
|
-
gates: null,
|
|
256
|
-
poll: gating[0]?.poll ?? {
|
|
257
|
-
interval: {
|
|
258
|
-
value: 1,
|
|
259
|
-
unit: "s"
|
|
260
|
-
},
|
|
261
|
-
jitter: 0,
|
|
262
|
-
timeout: {
|
|
263
|
-
value: .5,
|
|
264
|
-
unit: "s"
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}).describe();
|
|
268
|
-
} catch {
|
|
269
|
-
refused = true;
|
|
270
|
-
}
|
|
271
|
-
if (!refused) throw new Error(`the declaration accepted a check on ${never}, which is not a dependency`);
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
return cases;
|
|
275
|
-
};
|
|
276
|
-
// src/http/fake-server.ts
|
|
277
|
-
/** This function makes a pushed source, a stream of a work for the tests of a stream. */
|
|
278
|
-
const pushedSource = () => {
|
|
279
|
-
const queue = [];
|
|
280
|
-
let wake = null;
|
|
281
|
-
let failure = null;
|
|
282
|
-
let returned = false;
|
|
283
|
-
const poke = () => {
|
|
284
|
-
wake?.();
|
|
285
|
-
wake = null;
|
|
286
|
-
};
|
|
287
|
-
return {
|
|
288
|
-
iterable: { [Symbol.asyncIterator]: () => ({
|
|
289
|
-
async next() {
|
|
290
|
-
for (;;) {
|
|
291
|
-
if (failure !== null) throw failure;
|
|
292
|
-
if (returned) return {
|
|
293
|
-
value: void 0,
|
|
294
|
-
done: true
|
|
295
|
-
};
|
|
296
|
-
const step = queue.shift();
|
|
297
|
-
if (step !== void 0) return step;
|
|
298
|
-
await new Promise((resolve) => wake = resolve);
|
|
299
|
-
}
|
|
300
|
-
},
|
|
301
|
-
async return() {
|
|
302
|
-
returned = true;
|
|
303
|
-
poke();
|
|
304
|
-
return {
|
|
305
|
-
value: void 0,
|
|
306
|
-
done: true
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
}) },
|
|
310
|
-
push: (value) => {
|
|
311
|
-
queue.push({
|
|
312
|
-
value,
|
|
313
|
-
done: false
|
|
314
|
-
});
|
|
315
|
-
poke();
|
|
316
|
-
},
|
|
317
|
-
finish: () => {
|
|
318
|
-
queue.push({
|
|
319
|
-
value: void 0,
|
|
320
|
-
done: true
|
|
321
|
-
});
|
|
322
|
-
poke();
|
|
323
|
-
},
|
|
324
|
-
fail: (error) => {
|
|
325
|
-
failure = error;
|
|
326
|
-
poke();
|
|
327
|
-
},
|
|
328
|
-
get returned() {
|
|
329
|
-
return returned;
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
};
|
|
333
|
-
// src/conformance.ts
|
|
334
|
-
/**
|
|
335
|
-
* This function gives a detached lifecycle: a lifecycle with no service, for the start of a
|
|
336
|
-
* transport in a test. Its state is `running`, it keeps each connection, and nothing is in flight. Each request
|
|
337
|
-
* and each use of its health throws, because no service declares a route.
|
|
338
|
-
*/
|
|
339
|
-
const detachedLifecycle = () => {
|
|
340
|
-
const none = () => {
|
|
341
|
-
throw new Error("a detached lifecycle has no service: give the transport the lifecycle of a service");
|
|
342
|
-
};
|
|
343
|
-
return {
|
|
344
|
-
health: {
|
|
345
|
-
verdict: none,
|
|
346
|
-
probe: none,
|
|
347
|
-
metrics: none,
|
|
348
|
-
subscribe: none,
|
|
349
|
-
forceFail: none,
|
|
350
|
-
drain: none,
|
|
351
|
-
stop: none
|
|
352
|
-
},
|
|
353
|
-
state: "running",
|
|
354
|
-
exitCode: null,
|
|
355
|
-
errors: [],
|
|
356
|
-
started: Promise.resolve(),
|
|
357
|
-
done: new Promise(() => {}),
|
|
358
|
-
signal: new AbortController().signal,
|
|
359
|
-
shutdown: none,
|
|
360
|
-
request: none,
|
|
361
|
-
inFlight: () => 0,
|
|
362
|
-
keepAlive: () => true
|
|
363
|
-
};
|
|
364
|
-
};
|
|
365
|
-
/** These names are the controller and the route of each call of the stream cases. */
|
|
366
|
-
const CALLS = {
|
|
367
|
-
controller: "conformance",
|
|
368
|
-
route: "call"
|
|
369
|
-
};
|
|
370
|
-
/**
|
|
371
|
-
* This function gives a lifecycle with request tracking for the stream cases, and its tracker. The
|
|
372
|
-
* kit uses the tracker for the stages of the shutdown, as the lifecycle of a service does. Its
|
|
373
|
-
* requests are not idempotent, and it admits each request until the stop of its intake.
|
|
374
|
-
*/
|
|
375
|
-
const trackedLifecycle = (clock) => {
|
|
376
|
-
const requests = tracker([{
|
|
377
|
-
name: CALLS.controller,
|
|
378
|
-
requires: [],
|
|
379
|
-
routes: { [CALLS.route]: { idempotent: false } }
|
|
380
|
-
}], clock, () => null);
|
|
381
|
-
const life = {
|
|
382
|
-
...detachedLifecycle(),
|
|
383
|
-
request: (controller, route, work, options) => ownStream(requests.request(controller, route, work, options), life),
|
|
384
|
-
inFlight: (controller) => requests.inFlight(controller)
|
|
385
|
-
};
|
|
386
|
-
return {
|
|
387
|
-
life,
|
|
388
|
-
requests
|
|
389
|
-
};
|
|
390
|
-
};
|
|
391
|
-
const realNow = () => performance.now();
|
|
392
|
-
const alive = platformClock();
|
|
393
|
-
const turn = () => delay(alive, 0);
|
|
394
|
-
/** This function waits on the real clock, until the test is true or the bound ends. It gives the test at the end. */
|
|
395
|
-
const within = async (bound, test) => {
|
|
396
|
-
const end = realNow() + bound;
|
|
397
|
-
for (;;) {
|
|
398
|
-
if (test()) return true;
|
|
399
|
-
if (realNow() > end) return test();
|
|
400
|
-
await turn();
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
/** This function lets the events that are ready reach the transport, with no move of the clock of the case. */
|
|
404
|
-
const quiet = async () => {
|
|
405
|
-
for (let at = 0; at < 8; at += 1) await turn();
|
|
406
|
-
};
|
|
407
|
-
/** This function uses a method of the transport, and gives a throw of the method as a rejection. */
|
|
408
|
-
const attempt = (call) => {
|
|
409
|
-
try {
|
|
410
|
-
return Promise.resolve(call());
|
|
411
|
-
} catch (error) {
|
|
412
|
-
return Promise.reject(error);
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
const track = (promise) => {
|
|
416
|
-
const state = {
|
|
417
|
-
settled: false,
|
|
418
|
-
error: void 0,
|
|
419
|
-
failed: false
|
|
420
|
-
};
|
|
421
|
-
promise.then(() => {
|
|
422
|
-
state.settled = true;
|
|
423
|
-
}, (error) => {
|
|
424
|
-
state.settled = true;
|
|
425
|
-
state.failed = true;
|
|
426
|
-
state.error = error;
|
|
427
|
-
});
|
|
428
|
-
return state;
|
|
429
|
-
};
|
|
430
|
-
/**
|
|
431
|
-
* This function generates the conformance cases of a transport (S6 A9). `make` gives a new subject
|
|
432
|
-
* for each case. Each case throws on a failure, and its message names the part of the contract.
|
|
433
|
-
* - The start: nothing is in flight, and the transport takes work.
|
|
434
|
-
* - The count: it follows each work from its events, with no move of the clock.
|
|
435
|
-
* - `stopIntake` refuses new work, keeps the work in flight, and a second stop has no effect.
|
|
436
|
-
* - `drain` ends at once with no work, ends with the last work, and holds to its deadline and not
|
|
437
|
-
* past it. It gives the cooperative abort to the work, and it does not throw.
|
|
438
|
-
* - `close` ends the work in flight in its bound, and a second close has no effect.
|
|
439
|
-
* - The stages in their sequence, as the lifecycle does them.
|
|
440
|
-
*
|
|
441
|
-
* The option `streams` adds the cases of the streams (S6 D4). Each request is a stream, and a
|
|
442
|
-
* unary call is a stream of one item. The kit gives the transport a lifecycle with request
|
|
443
|
-
* tracking. It also does the stages of the shutdown on the tracker, as the lifecycle does them.
|
|
444
|
-
* - A unary call gives one value, and its end comes as the status of the answer.
|
|
445
|
-
* - A stream stays in flight until its end, not until its first item.
|
|
446
|
-
* - A failure after the first item ends the stream with an error line in the body, not a status.
|
|
447
|
-
* A failure before the first item gets a status.
|
|
448
|
-
* - `drain` waits for an open stream. The cooperative abort ends the stream, and its caller gets the end.
|
|
449
|
-
* - At the deadline of the drain, the cut ends an open stream, and its caller gets the end.
|
|
450
|
-
*/
|
|
451
|
-
const transportConformance = (make, options = {}) => {
|
|
452
|
-
const name = options.name ?? "transport";
|
|
453
|
-
const fake = (options.clock ?? "fake") === "fake";
|
|
454
|
-
const cap = options.cap ?? 1e3;
|
|
455
|
-
const closeBound = options.closeBound ?? 1e3;
|
|
456
|
-
const slack = options.slack ?? 100;
|
|
457
|
-
const cooperative = options.cooperative ?? true;
|
|
458
|
-
const holds = options.holds ?? 3;
|
|
459
|
-
const timeOf = () => {
|
|
460
|
-
if (!fake) return {
|
|
461
|
-
clock: realClock,
|
|
462
|
-
pass: (ms) => delay(alive, ms)
|
|
463
|
-
};
|
|
464
|
-
const clock = fakeClock();
|
|
465
|
-
return {
|
|
466
|
-
clock,
|
|
467
|
-
pass: (ms) => clock.advance(ms)
|
|
468
|
-
};
|
|
469
|
-
};
|
|
470
|
-
const check = (ok, what) => {
|
|
471
|
-
if (!ok) throw new Error(`${name}: ${what}`);
|
|
472
|
-
};
|
|
473
|
-
const each = (title, body) => ({
|
|
474
|
-
name: `${name}: ${title}`,
|
|
475
|
-
async run() {
|
|
476
|
-
const time = timeOf();
|
|
477
|
-
const subject = await make(time.clock);
|
|
478
|
-
try {
|
|
479
|
-
await subject.impl.start(new AbortController().signal, subject.life ?? detachedLifecycle());
|
|
480
|
-
await body(subject, time, title);
|
|
481
|
-
} finally {
|
|
482
|
-
try {
|
|
483
|
-
await subject.impl.close();
|
|
484
|
-
} finally {
|
|
485
|
-
await subject.dispose?.();
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
const count = (subject, expected, what) => within(slack, () => subject.impl.inFlight() === expected).then((ok) => check(ok, `${what}: inFlight() gives ${subject.impl.inFlight()}, not ${expected}`));
|
|
491
|
-
const closes = async (subject, title) => {
|
|
492
|
-
const began = realNow();
|
|
493
|
-
const closed = track(attempt(() => subject.impl.close()));
|
|
494
|
-
const inBound = await within(closeBound, () => closed.settled);
|
|
495
|
-
const took = realNow() - began;
|
|
496
|
-
options.record?.({
|
|
497
|
-
case: title,
|
|
498
|
-
what: "close",
|
|
499
|
-
expected: closeBound,
|
|
500
|
-
measured: took
|
|
501
|
-
});
|
|
502
|
-
check(inBound, `close did not end in its bound of ${closeBound} ms`);
|
|
503
|
-
check(!closed.failed, `close threw: ${String(closed.error)}`);
|
|
504
|
-
};
|
|
505
|
-
const cases = [
|
|
506
|
-
each("nothing is in flight after the start, and it takes new work", async (subject) => {
|
|
507
|
-
check(subject.impl.inFlight() === 0, `inFlight() gives ${subject.impl.inFlight()} after the start, not 0`);
|
|
508
|
-
check(await subject.offer(), "the transport refused new work after its start");
|
|
509
|
-
await count(subject, 0, "the work ended");
|
|
510
|
-
}),
|
|
511
|
-
each("the count follows each work in flight from its events, with no move of the clock", async (subject) => {
|
|
512
|
-
const held = [];
|
|
513
|
-
for (let at = 1; at <= holds; at += 1) {
|
|
514
|
-
held.push(await subject.hold());
|
|
515
|
-
await count(subject, at, `${at} works are in flight`);
|
|
516
|
-
}
|
|
517
|
-
for (let at = holds - 1; at >= 0; at -= 1) {
|
|
518
|
-
await held[at].release();
|
|
519
|
-
await count(subject, at, `${at} works are in flight after a release`);
|
|
520
|
-
}
|
|
521
|
-
}),
|
|
522
|
-
each("stopIntake refuses new work, keeps the work in flight, and a second stop has no effect", async (subject) => {
|
|
523
|
-
const work = await subject.hold();
|
|
524
|
-
await subject.impl.stopIntake();
|
|
525
|
-
check(!await subject.offer(), "the transport took new work after stopIntake");
|
|
526
|
-
await count(subject, 1, "stopIntake cut the work in flight");
|
|
527
|
-
await subject.impl.stopIntake();
|
|
528
|
-
check(!await subject.offer(), "the transport took new work after a second stopIntake");
|
|
529
|
-
await work.release();
|
|
530
|
-
await count(subject, 0, "the work in flight ended after stopIntake");
|
|
531
|
-
}),
|
|
532
|
-
each("drain ends at once when nothing is in flight", async (subject, time) => {
|
|
533
|
-
await subject.impl.stopIntake();
|
|
534
|
-
const drained = track(attempt(() => subject.impl.drain(time.clock.now() + cap, new AbortController().signal)));
|
|
535
|
-
check(await within(slack, () => drained.settled), "drain did not end with nothing in flight");
|
|
536
|
-
check(!drained.failed, `drain threw: ${String(drained.error)}`);
|
|
537
|
-
}),
|
|
538
|
-
each("drain ends when the last work ends, before its deadline", async (subject, time) => {
|
|
539
|
-
const work = await subject.hold();
|
|
540
|
-
await subject.impl.stopIntake();
|
|
541
|
-
const deadline = time.clock.now() + cap;
|
|
542
|
-
const drained = track(attempt(() => subject.impl.drain(deadline, new AbortController().signal)));
|
|
543
|
-
await time.pass(cap / 4);
|
|
544
|
-
await quiet();
|
|
545
|
-
check(!drained.settled, "drain ended while work was in flight, before its deadline");
|
|
546
|
-
await work.release();
|
|
547
|
-
check(await within(slack, () => drained.settled), "drain did not end when the last work ended");
|
|
548
|
-
check(!drained.failed, `drain threw: ${String(drained.error)}`);
|
|
549
|
-
check(time.clock.now() < deadline, "drain waited until its deadline after the last work ended");
|
|
550
|
-
}),
|
|
551
|
-
each("drain holds to its deadline and not past it, and does not throw", async (subject, time, title) => {
|
|
552
|
-
await subject.hold();
|
|
553
|
-
await subject.impl.stopIntake();
|
|
554
|
-
const began = realNow();
|
|
555
|
-
const deadline = time.clock.now() + cap;
|
|
556
|
-
const drained = track(attempt(() => subject.impl.drain(deadline, new AbortController().signal)));
|
|
557
|
-
if (fake) {
|
|
558
|
-
await time.pass(cap - 1);
|
|
559
|
-
await quiet();
|
|
560
|
-
check(!drained.settled, "drain ended before its deadline, with work in flight");
|
|
561
|
-
await time.pass(1);
|
|
562
|
-
check(await within(slack, () => drained.settled), "drain did not end at its deadline");
|
|
563
|
-
} else {
|
|
564
|
-
const ended = await within(cap + slack, () => drained.settled);
|
|
565
|
-
const took = realNow() - began;
|
|
566
|
-
options.record?.({
|
|
567
|
-
case: title,
|
|
568
|
-
what: "drain to its deadline",
|
|
569
|
-
expected: cap,
|
|
570
|
-
measured: took
|
|
571
|
-
});
|
|
572
|
-
check(ended, `drain did not end in ${cap + slack} ms, with a deadline at ${cap} ms`);
|
|
573
|
-
check(took >= cap - slack, `drain ended after ${Math.round(took)} ms, before its deadline at ${cap} ms`);
|
|
574
|
-
}
|
|
575
|
-
check(!drained.failed, `drain threw at its deadline: ${String(drained.error)}`);
|
|
576
|
-
}),
|
|
577
|
-
...cooperative ? [each("drain gives the cooperative abort to the work in flight", async (subject, time) => {
|
|
578
|
-
const work = await subject.hold();
|
|
579
|
-
await subject.impl.stopIntake();
|
|
580
|
-
const abort = new AbortController();
|
|
581
|
-
const drained = track(attempt(() => subject.impl.drain(time.clock.now() + cap, abort.signal)));
|
|
582
|
-
await time.pass(cap / 2);
|
|
583
|
-
await quiet();
|
|
584
|
-
check(!work.aborted, "the work got an abort before the signal of the drain aborted");
|
|
585
|
-
abort.abort(/* @__PURE__ */ new Error("the cooperative abort of the conformance kit"));
|
|
586
|
-
check(await within(slack, () => work.aborted), "the work did not get the cooperative abort");
|
|
587
|
-
await time.pass(cap / 2);
|
|
588
|
-
check(await within(slack, () => drained.settled), "drain did not end at its deadline after the cooperative abort");
|
|
589
|
-
check(!drained.failed, `drain threw after the cooperative abort: ${String(drained.error)}`);
|
|
590
|
-
})] : [],
|
|
591
|
-
each("drain with an aborted signal and a deadline in the past ends at once", async (subject, time) => {
|
|
592
|
-
const work = await subject.hold();
|
|
593
|
-
await subject.impl.stopIntake();
|
|
594
|
-
const abort = new AbortController();
|
|
595
|
-
abort.abort(/* @__PURE__ */ new Error("the cooperative abort of the conformance kit"));
|
|
596
|
-
const drained = track(attempt(() => subject.impl.drain(time.clock.now() - 1, abort.signal)));
|
|
597
|
-
check(await within(slack, () => drained.settled), "drain did not end at once with its deadline in the past");
|
|
598
|
-
check(!drained.failed, `drain threw: ${String(drained.error)}`);
|
|
599
|
-
if (cooperative) check(await within(slack, () => work.aborted), "the work did not get an abort that came before the drain");
|
|
600
|
-
}),
|
|
601
|
-
each("close ends the work in flight, in its bound", async (subject, _time, title) => {
|
|
602
|
-
for (let at = 0; at < holds; at += 1) await subject.hold();
|
|
603
|
-
await count(subject, holds, "the works are in flight before the close");
|
|
604
|
-
await closes(subject, title);
|
|
605
|
-
await count(subject, 0, "close left work in flight");
|
|
606
|
-
}),
|
|
607
|
-
each("close is idempotent: a second close has no effect", async (subject, _time, title) => {
|
|
608
|
-
await subject.hold();
|
|
609
|
-
const first = track(attempt(() => subject.impl.close()));
|
|
610
|
-
const second = track(attempt(() => subject.impl.close()));
|
|
611
|
-
check(await within(closeBound, () => first.settled && second.settled), "two closes did not end in the bound");
|
|
612
|
-
check(!first.failed && !second.failed, `a close threw: ${String(first.error ?? second.error)}`);
|
|
613
|
-
await closes(subject, title);
|
|
614
|
-
await count(subject, 0, "the closes left work in flight");
|
|
615
|
-
}),
|
|
616
|
-
each("close right after the start ends in its bound", async (subject, _time, title) => {
|
|
617
|
-
await closes(subject, title);
|
|
618
|
-
check(subject.impl.inFlight() === 0, "inFlight() is not 0 after a close with no work");
|
|
619
|
-
}),
|
|
620
|
-
each("the stages in their sequence: stop intake, drain with its cooperative abort, close", async (subject, time, title) => {
|
|
621
|
-
const short = await subject.hold();
|
|
622
|
-
const long = await subject.hold();
|
|
623
|
-
await subject.impl.stopIntake();
|
|
624
|
-
check(!await subject.offer(), "the transport took new work after stopIntake");
|
|
625
|
-
const abort = new AbortController();
|
|
626
|
-
const drained = track(attempt(() => subject.impl.drain(time.clock.now() + cap, abort.signal)));
|
|
627
|
-
await short.release();
|
|
628
|
-
await count(subject, 1, "one work ended in the drain");
|
|
629
|
-
await time.pass(cap / 2);
|
|
630
|
-
abort.abort(/* @__PURE__ */ new Error("the cooperative abort of the conformance kit"));
|
|
631
|
-
if (cooperative) check(await within(slack, () => long.aborted), "the long work did not get the cooperative abort");
|
|
632
|
-
await time.pass(cap / 2);
|
|
633
|
-
check(await within(slack, () => drained.settled), "drain did not end at its deadline");
|
|
634
|
-
await closes(subject, title);
|
|
635
|
-
await count(subject, 0, "close left work in flight");
|
|
636
|
-
})
|
|
637
|
-
];
|
|
638
|
-
if (!(options.streams ?? false)) return cases;
|
|
639
|
-
const eachStream = (title, body) => ({
|
|
640
|
-
name: `${name}: ${title}`,
|
|
641
|
-
async run() {
|
|
642
|
-
const time = timeOf();
|
|
643
|
-
const subject = await make(time.clock);
|
|
644
|
-
const { life, requests } = trackedLifecycle(time.clock);
|
|
645
|
-
try {
|
|
646
|
-
await subject.impl.start(new AbortController().signal, life);
|
|
647
|
-
check(subject.call !== void 0, "the option streams needs a subject that gives call()");
|
|
648
|
-
await body(subject, time, requests);
|
|
649
|
-
} finally {
|
|
650
|
-
requests.stopIntake();
|
|
651
|
-
requests.cooperativeAbort();
|
|
652
|
-
try {
|
|
653
|
-
await subject.impl.close();
|
|
654
|
-
} finally {
|
|
655
|
-
await subject.dispose?.();
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
});
|
|
660
|
-
const call = (subject, given) => Promise.resolve(subject.call(given));
|
|
661
|
-
const openStream = async (subject) => {
|
|
662
|
-
const source = pushedSource();
|
|
663
|
-
let started = false;
|
|
664
|
-
let signal = null;
|
|
665
|
-
const view = await call(subject, {
|
|
666
|
-
...CALLS,
|
|
667
|
-
stream: true,
|
|
668
|
-
work: (given) => {
|
|
669
|
-
started = true;
|
|
670
|
-
signal = given;
|
|
671
|
-
return source.iterable;
|
|
672
|
-
}
|
|
673
|
-
});
|
|
674
|
-
check(await within(slack, () => started), "the work of a stream call did not start");
|
|
675
|
-
return {
|
|
676
|
-
view,
|
|
677
|
-
push: (value) => source.push(value),
|
|
678
|
-
finish: () => source.finish(),
|
|
679
|
-
fail: (error) => source.fail(error),
|
|
680
|
-
get aborted() {
|
|
681
|
-
return signal?.aborted === true;
|
|
682
|
-
}
|
|
683
|
-
};
|
|
684
|
-
};
|
|
685
|
-
const pushes = async (fed, value, what) => {
|
|
686
|
-
const before = fed.view.items.length;
|
|
687
|
-
fed.push(value);
|
|
688
|
-
check(await within(slack, () => fed.view.items.length > before), `${what}: the caller did not get the item ${value}`);
|
|
689
|
-
};
|
|
690
|
-
const ends = async (view, kind, inBand, what) => {
|
|
691
|
-
check(await within(slack, () => view.end !== null), `${what}: the caller got no end`);
|
|
692
|
-
const end = view.end;
|
|
693
|
-
const where = (body) => body ? "in the body" : "as a status";
|
|
694
|
-
check(end.kind === kind && end.inBand === inBand, `${what}: the caller got the end ${end.kind} ${where(end.inBand)}, not ${kind} ${where(inBand)}`);
|
|
695
|
-
};
|
|
696
|
-
/** This function stops the intake of the tracker and of the transport, as the stage `stop intake` does. */
|
|
697
|
-
const stopBoth = async (subject, requests) => {
|
|
698
|
-
requests.stopIntake();
|
|
699
|
-
await subject.impl.stopIntake();
|
|
700
|
-
};
|
|
701
|
-
/**
|
|
702
|
-
* This function starts the drain of the transport and of the tracker, as the stage `drain` does.
|
|
703
|
-
* The abort of `signal` is also the cooperative abort of the tracker. It tracks the drain of the transport.
|
|
704
|
-
*/
|
|
705
|
-
const drainBoth = (subject, requests, deadline, signal) => {
|
|
706
|
-
if (signal.aborted) requests.cooperativeAbort();
|
|
707
|
-
else signal.addEventListener("abort", () => requests.cooperativeAbort(), { once: true });
|
|
708
|
-
requests.drain(deadline);
|
|
709
|
-
return track(attempt(() => subject.impl.drain(deadline, signal)));
|
|
710
|
-
};
|
|
711
|
-
const failure = () => /* @__PURE__ */ new Error("the failure of the conformance kit");
|
|
712
|
-
const streamCases = [
|
|
713
|
-
eachStream("a unary call is a stream of one item: one value, and its end as the status", async (subject) => {
|
|
714
|
-
let started = false;
|
|
715
|
-
let give = () => {};
|
|
716
|
-
const view = await call(subject, {
|
|
717
|
-
...CALLS,
|
|
718
|
-
stream: false,
|
|
719
|
-
work: () => {
|
|
720
|
-
started = true;
|
|
721
|
-
return new Promise((resolve) => {
|
|
722
|
-
give = resolve;
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
});
|
|
726
|
-
check(await within(slack, () => started), "the work of a unary call did not start");
|
|
727
|
-
await count(subject, 1, "a unary call is in flight");
|
|
728
|
-
give(7);
|
|
729
|
-
await ends(view, "done", false, "a unary call");
|
|
730
|
-
check(view.items.length === 1 && view.items[0] === 7, `a unary call gave the items ${JSON.stringify(view.items)}, not [7]`);
|
|
731
|
-
await count(subject, 0, "a unary call ended");
|
|
732
|
-
}),
|
|
733
|
-
eachStream("a stream stays in flight until its end, not until its first item", async (subject) => {
|
|
734
|
-
const fed = await openStream(subject);
|
|
735
|
-
await count(subject, 1, "a stream is open");
|
|
736
|
-
for (const value of [1, 2]) {
|
|
737
|
-
await pushes(fed, value, "an open stream");
|
|
738
|
-
await count(subject, 1, `a stream is open after its item ${value}`);
|
|
739
|
-
}
|
|
740
|
-
check(fed.view.end === null, "the caller got an end before the end of the stream");
|
|
741
|
-
fed.finish();
|
|
742
|
-
await ends(fed.view, "done", true, "a stream that ended");
|
|
743
|
-
check(JSON.stringify(fed.view.items) === "[1,2]", `a stream gave the items ${JSON.stringify(fed.view.items)}, not [1,2]`);
|
|
744
|
-
await count(subject, 0, "a stream ended");
|
|
745
|
-
}),
|
|
746
|
-
eachStream("a failure after the first item ends the stream with an error line, not a status", async (subject) => {
|
|
747
|
-
const fed = await openStream(subject);
|
|
748
|
-
await pushes(fed, 1, "a stream before its failure");
|
|
749
|
-
fed.fail(failure());
|
|
750
|
-
await ends(fed.view, "failed", true, "a stream that failed after its first item");
|
|
751
|
-
await count(subject, 0, "a stream failed");
|
|
752
|
-
}),
|
|
753
|
-
eachStream("a failure before the first item gets a status, not an error line", async (subject) => {
|
|
754
|
-
const fed = await openStream(subject);
|
|
755
|
-
fed.fail(failure());
|
|
756
|
-
await ends(fed.view, "failed", false, "a stream that failed before its first item");
|
|
757
|
-
check(fed.view.items.length === 0, `a stream that failed before its first item gave ${fed.view.items.length} items`);
|
|
758
|
-
await count(subject, 0, "a stream failed");
|
|
759
|
-
}),
|
|
760
|
-
eachStream("drain waits for an open stream, and the cooperative abort ends the stream with its end", async (subject, time, requests) => {
|
|
761
|
-
const fed = await openStream(subject);
|
|
762
|
-
await pushes(fed, 1, "a stream before the drain");
|
|
763
|
-
await stopBoth(subject, requests);
|
|
764
|
-
const abort = new AbortController();
|
|
765
|
-
const deadline = time.clock.now() + cap;
|
|
766
|
-
const drained = drainBoth(subject, requests, deadline, abort.signal);
|
|
767
|
-
await time.pass(cap / 4);
|
|
768
|
-
await quiet();
|
|
769
|
-
check(!drained.settled, "drain ended while a stream was open, before its deadline");
|
|
770
|
-
check(fed.view.end === null, "the caller got an end before the cooperative abort");
|
|
771
|
-
await count(subject, 1, "a stream is open in the drain");
|
|
772
|
-
abort.abort(/* @__PURE__ */ new Error("the cooperative abort of the conformance kit"));
|
|
773
|
-
check(await within(slack, () => fed.aborted), "the work of the stream did not get the cooperative abort");
|
|
774
|
-
await ends(fed.view, "cut", true, "a stream after the cooperative abort");
|
|
775
|
-
check(await within(slack, () => drained.settled), "drain did not end when the stream ended");
|
|
776
|
-
check(!drained.failed, `drain threw: ${String(drained.error)}`);
|
|
777
|
-
check(time.clock.now() < deadline, "drain waited until its deadline after the stream ended");
|
|
778
|
-
await count(subject, 0, "the cooperative abort left a stream in flight");
|
|
779
|
-
}),
|
|
780
|
-
eachStream("drain cuts an open stream at its deadline, and the caller gets the end of the cut", async (subject, time, requests) => {
|
|
781
|
-
const fed = await openStream(subject);
|
|
782
|
-
await pushes(fed, 1, "a stream before the drain");
|
|
783
|
-
await stopBoth(subject, requests);
|
|
784
|
-
const drained = drainBoth(subject, requests, time.clock.now() + cap, new AbortController().signal);
|
|
785
|
-
await time.pass(cap);
|
|
786
|
-
await ends(fed.view, "cut", true, "a stream at the deadline of the drain");
|
|
787
|
-
check(await within(slack, () => drained.settled), "drain did not end after the cut of the stream");
|
|
788
|
-
check(!drained.failed, `drain threw at its deadline: ${String(drained.error)}`);
|
|
789
|
-
await count(subject, 0, "the cut left a stream in flight");
|
|
790
|
-
})
|
|
791
|
-
];
|
|
792
|
-
return [...cases, ...streamCases];
|
|
793
|
-
};
|
|
794
|
-
// src/host/fakes.ts
|
|
795
|
-
const encoder = new TextEncoder();
|
|
796
|
-
const decoder = new TextDecoder();
|
|
797
|
-
const bytesOf = (data) => typeof data === "string" ? encoder.encode(data) : data;
|
|
798
|
-
/** This function makes a fake host. Give its `ports` to the host functions in a test. */
|
|
799
|
-
const fakeHost = (options = {}) => {
|
|
800
|
-
const clock = fakeClock();
|
|
801
|
-
const wallStart = options.wallStart ?? 0xe8d4a51000;
|
|
802
|
-
const wall = () => wallStart + clock.now();
|
|
803
|
-
const self = options.self ?? {
|
|
804
|
-
pid: 100,
|
|
805
|
-
startedAt: wallStart
|
|
806
|
-
};
|
|
807
|
-
const files = new Map(Object.entries(options.files ?? {}));
|
|
808
|
-
const commands = [];
|
|
809
|
-
const signals = [];
|
|
810
|
-
const children = [];
|
|
811
|
-
const processes = /* @__PURE__ */ new Map([[self.pid, self.startedAt]]);
|
|
812
|
-
const live = /* @__PURE__ */ new Map();
|
|
813
|
-
let nextPid = 1e3;
|
|
814
|
-
const check = (operation, path) => {
|
|
815
|
-
if (host.failFiles?.(operation, path) === true) throw new Error(`the fake ${operation} of ${path} failed`);
|
|
816
|
-
};
|
|
817
|
-
const politeStop = (pid) => {
|
|
818
|
-
const child = live.get(pid);
|
|
819
|
-
if (host.polite && child !== void 0) queueMicrotask(() => child.exit(0));
|
|
820
|
-
};
|
|
821
|
-
const hardStop = (pid, signal) => {
|
|
822
|
-
const child = live.get(pid);
|
|
823
|
-
if (child !== void 0) queueMicrotask(() => child.exit(null, signal));
|
|
824
|
-
else processes.delete(pid);
|
|
825
|
-
};
|
|
826
|
-
const spawn = (request) => {
|
|
827
|
-
const pid = host.failSpawn?.(request) === true ? null : nextPid++;
|
|
828
|
-
const outputs = [];
|
|
829
|
-
const exits = [];
|
|
830
|
-
const sent = [];
|
|
831
|
-
let end = null;
|
|
832
|
-
const child = {
|
|
833
|
-
request,
|
|
834
|
-
pid,
|
|
835
|
-
ipc: request.ipc,
|
|
836
|
-
sent,
|
|
837
|
-
get ended() {
|
|
838
|
-
return end !== null;
|
|
839
|
-
},
|
|
840
|
-
onOutput(handler) {
|
|
841
|
-
outputs.push(handler);
|
|
842
|
-
},
|
|
843
|
-
onExit(handler) {
|
|
844
|
-
exits.push(handler);
|
|
845
|
-
if (end !== null) handler(end.code, end.signal);
|
|
846
|
-
},
|
|
847
|
-
send(message) {
|
|
848
|
-
if (!request.ipc || end !== null) return false;
|
|
849
|
-
sent.push(message);
|
|
850
|
-
if (pid !== null) politeStop(pid);
|
|
851
|
-
return true;
|
|
852
|
-
},
|
|
853
|
-
exit(code, signal = null) {
|
|
854
|
-
if (end !== null) return;
|
|
855
|
-
end = {
|
|
856
|
-
code,
|
|
857
|
-
signal
|
|
858
|
-
};
|
|
859
|
-
if (pid !== null) {
|
|
860
|
-
processes.delete(pid);
|
|
861
|
-
live.delete(pid);
|
|
862
|
-
}
|
|
863
|
-
for (const handler of exits) handler(code, signal);
|
|
864
|
-
},
|
|
865
|
-
output(stream, chunk) {
|
|
866
|
-
for (const handler of outputs) handler(stream, chunk);
|
|
867
|
-
}
|
|
868
|
-
};
|
|
869
|
-
children.push(child);
|
|
870
|
-
if (pid === null) queueMicrotask(() => child.exit(null));
|
|
871
|
-
else {
|
|
872
|
-
processes.set(pid, wall());
|
|
873
|
-
live.set(pid, child);
|
|
874
|
-
}
|
|
875
|
-
return child;
|
|
876
|
-
};
|
|
877
|
-
const signal = (pid, sig, group) => {
|
|
878
|
-
if (!processes.has(pid)) return false;
|
|
879
|
-
signals.push({
|
|
880
|
-
pid,
|
|
881
|
-
signal: sig,
|
|
882
|
-
group
|
|
883
|
-
});
|
|
884
|
-
if (sig === "SIGKILL") hardStop(pid, "SIGKILL");
|
|
885
|
-
else politeStop(pid);
|
|
886
|
-
return true;
|
|
887
|
-
};
|
|
888
|
-
const defaultAnswer = (command) => {
|
|
889
|
-
if (command.file !== "taskkill") return {
|
|
890
|
-
code: 0,
|
|
891
|
-
out: ""
|
|
892
|
-
};
|
|
893
|
-
const at = command.args.indexOf("/PID");
|
|
894
|
-
const pid = Number(command.args[at + 1]);
|
|
895
|
-
if (at < 0 || !processes.has(pid)) return {
|
|
896
|
-
code: 128,
|
|
897
|
-
out: `ERROR: The process "${command.args[at + 1] ?? ""}" not found.`
|
|
898
|
-
};
|
|
899
|
-
if (command.args.includes("/F")) {
|
|
900
|
-
hardStop(pid, null);
|
|
901
|
-
return {
|
|
902
|
-
code: 0,
|
|
903
|
-
out: `SUCCESS: The process with PID ${pid} has been terminated.`
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
if (host.polite && live.has(pid)) {
|
|
907
|
-
politeStop(pid);
|
|
908
|
-
return {
|
|
909
|
-
code: 0,
|
|
910
|
-
out: `SUCCESS: Sent termination signal to the process with PID ${pid}.`
|
|
911
|
-
};
|
|
912
|
-
}
|
|
913
|
-
return {
|
|
914
|
-
code: 1,
|
|
915
|
-
out: `ERROR: The process with PID ${pid} could not be terminated.`
|
|
916
|
-
};
|
|
917
|
-
};
|
|
918
|
-
const ports = {
|
|
919
|
-
platform: options.platform ?? "linux",
|
|
920
|
-
commands: { async run(file, args, commandOptions) {
|
|
921
|
-
const command = {
|
|
922
|
-
file,
|
|
923
|
-
args: [...args],
|
|
924
|
-
options: commandOptions
|
|
925
|
-
};
|
|
926
|
-
commands.push(command);
|
|
927
|
-
return options.answer?.(command) ?? defaultAnswer(command);
|
|
928
|
-
} },
|
|
929
|
-
files: {
|
|
930
|
-
async read(path) {
|
|
931
|
-
check("read", path);
|
|
932
|
-
const data = files.get(path);
|
|
933
|
-
return data === void 0 ? null : typeof data === "string" ? data : decoder.decode(data);
|
|
934
|
-
},
|
|
935
|
-
async write(path, data) {
|
|
936
|
-
check("write", path);
|
|
937
|
-
files.set(path, data);
|
|
938
|
-
},
|
|
939
|
-
async create(path, data) {
|
|
940
|
-
check("create", path);
|
|
941
|
-
if (files.has(path)) return false;
|
|
942
|
-
files.set(path, data);
|
|
943
|
-
return true;
|
|
944
|
-
},
|
|
945
|
-
async append(path, data) {
|
|
946
|
-
check("append", path);
|
|
947
|
-
const before = files.get(path);
|
|
948
|
-
if (before === void 0) files.set(path, data);
|
|
949
|
-
else if (typeof before === "string" && typeof data === "string") files.set(path, before + data);
|
|
950
|
-
else {
|
|
951
|
-
const head = bytesOf(before);
|
|
952
|
-
const tail = bytesOf(data);
|
|
953
|
-
const joined = new Uint8Array(head.length + tail.length);
|
|
954
|
-
joined.set(head, 0);
|
|
955
|
-
joined.set(tail, head.length);
|
|
956
|
-
files.set(path, joined);
|
|
957
|
-
}
|
|
958
|
-
},
|
|
959
|
-
async size(path) {
|
|
960
|
-
check("size", path);
|
|
961
|
-
const data = files.get(path);
|
|
962
|
-
return data === void 0 ? null : bytesOf(data).length;
|
|
963
|
-
},
|
|
964
|
-
async rename(from, to) {
|
|
965
|
-
check("rename", from);
|
|
966
|
-
const data = files.get(from);
|
|
967
|
-
if (data === void 0) throw new Error(`the fake file ${from} does not exist`);
|
|
968
|
-
files.delete(from);
|
|
969
|
-
files.set(to, data);
|
|
970
|
-
},
|
|
971
|
-
async remove(path) {
|
|
972
|
-
check("remove", path);
|
|
973
|
-
files.delete(path);
|
|
974
|
-
}
|
|
975
|
-
},
|
|
976
|
-
processes: {
|
|
977
|
-
alive: (pid) => processes.has(pid),
|
|
978
|
-
startOf: async (pid) => processes.get(pid) ?? null,
|
|
979
|
-
signal: (pid, sig) => signal(pid, sig, false),
|
|
980
|
-
signalGroup: (pid, sig) => ports.platform !== "win32" && live.has(pid) && signal(pid, sig, true),
|
|
981
|
-
spawn
|
|
982
|
-
},
|
|
983
|
-
net: {
|
|
984
|
-
httpStatus: async (url) => host.http.get(url) ?? null,
|
|
985
|
-
httpText: async (url, _timeout, limit) => {
|
|
986
|
-
const status = host.http.get(url) ?? null;
|
|
987
|
-
if (status === null) return null;
|
|
988
|
-
const bytes = encoder.encode(host.bodies.get(url) ?? "");
|
|
989
|
-
return {
|
|
990
|
-
status,
|
|
991
|
-
body: decoder.decode(bytes.subarray(0, limit)),
|
|
992
|
-
complete: bytes.length <= limit
|
|
993
|
-
};
|
|
994
|
-
},
|
|
995
|
-
tcpConnect: async (hostName, port) => host.tcp.has(`${hostName}:${port}`)
|
|
996
|
-
},
|
|
997
|
-
clock,
|
|
998
|
-
wall,
|
|
999
|
-
self,
|
|
1000
|
-
env: options.env ?? {},
|
|
1001
|
-
homeDir: options.homeDir ?? "/home/test",
|
|
1002
|
-
user: () => options.user ?? "test",
|
|
1003
|
-
...options.logger === void 0 ? {} : { logger: options.logger }
|
|
1004
|
-
};
|
|
1005
|
-
const host = {
|
|
1006
|
-
ports,
|
|
1007
|
-
clock,
|
|
1008
|
-
files,
|
|
1009
|
-
commands,
|
|
1010
|
-
signals,
|
|
1011
|
-
children,
|
|
1012
|
-
processes,
|
|
1013
|
-
http: /* @__PURE__ */ new Map(),
|
|
1014
|
-
bodies: /* @__PURE__ */ new Map(),
|
|
1015
|
-
tcp: /* @__PURE__ */ new Set(),
|
|
1016
|
-
polite: false,
|
|
1017
|
-
failFiles: null,
|
|
1018
|
-
failSpawn: null,
|
|
1019
|
-
text(path) {
|
|
1020
|
-
const data = files.get(path);
|
|
1021
|
-
return data === void 0 ? null : typeof data === "string" ? data : decoder.decode(data);
|
|
1022
|
-
},
|
|
1023
|
-
async settle() {
|
|
1024
|
-
for (let turn = 0; turn < 2e3; turn += 1) await Promise.resolve();
|
|
1025
|
-
}
|
|
1026
|
-
};
|
|
1027
|
-
return host;
|
|
1028
|
-
};
|
|
1029
6
|
// src/testing.ts
|
|
1030
7
|
/** This function makes a scripted check with a behavior at the start. */
|
|
1031
8
|
const scriptedCheck = (behavior = "ok") => {
|