@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
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
import { platformClock, realClock } from "./clock.js";
|
|
2
|
+
import { ownStream } from "./drains.js";
|
|
3
|
+
import { fakeClock } from "./fakes.js";
|
|
4
|
+
import { pushedSource } from "./http/fake-server.js";
|
|
5
|
+
import { tracker } from "./requests.js";
|
|
6
|
+
import { delay } from "@mark1russell7/algebra/clock";
|
|
7
|
+
// src/conformance.ts
|
|
8
|
+
/**
|
|
9
|
+
* This function gives a detached lifecycle: a lifecycle with no service, for the start of a
|
|
10
|
+
* transport in a test. Its state is `running`, it keeps each connection, and nothing is in flight. Each request
|
|
11
|
+
* and each use of its health throws, because no service declares a route.
|
|
12
|
+
*/
|
|
13
|
+
const detachedLifecycle = () => {
|
|
14
|
+
const none = () => {
|
|
15
|
+
throw new Error("a detached lifecycle has no service: give the transport the lifecycle of a service");
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
health: {
|
|
19
|
+
verdict: none,
|
|
20
|
+
probe: none,
|
|
21
|
+
metrics: none,
|
|
22
|
+
subscribe: none,
|
|
23
|
+
forceFail: none,
|
|
24
|
+
drain: none,
|
|
25
|
+
stop: none
|
|
26
|
+
},
|
|
27
|
+
state: "running",
|
|
28
|
+
exitCode: null,
|
|
29
|
+
errors: [],
|
|
30
|
+
started: Promise.resolve(),
|
|
31
|
+
done: new Promise(() => {}),
|
|
32
|
+
signal: new AbortController().signal,
|
|
33
|
+
shutdown: none,
|
|
34
|
+
request: none,
|
|
35
|
+
inFlight: () => 0,
|
|
36
|
+
keepAlive: () => true
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
/** These names are the controller and the route of each call of the stream cases. */
|
|
40
|
+
const CALLS = {
|
|
41
|
+
controller: "conformance",
|
|
42
|
+
route: "call"
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* This function gives a lifecycle with request tracking for the stream cases, and its tracker. The
|
|
46
|
+
* kit uses the tracker for the stages of the shutdown, as the lifecycle of a service does. Its
|
|
47
|
+
* requests are not idempotent, and it admits each request until the stop of its intake.
|
|
48
|
+
*/
|
|
49
|
+
const trackedLifecycle = (clock) => {
|
|
50
|
+
const requests = tracker([{
|
|
51
|
+
name: CALLS.controller,
|
|
52
|
+
requires: [],
|
|
53
|
+
routes: { [CALLS.route]: { idempotent: false } }
|
|
54
|
+
}], clock, () => null);
|
|
55
|
+
const life = {
|
|
56
|
+
...detachedLifecycle(),
|
|
57
|
+
request: (controller, route, work, options) => ownStream(requests.request(controller, route, work, options), life),
|
|
58
|
+
inFlight: (controller) => requests.inFlight(controller)
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
life,
|
|
62
|
+
requests
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
const realNow = () => performance.now();
|
|
66
|
+
const alive = platformClock();
|
|
67
|
+
const turn = () => delay(alive, 0);
|
|
68
|
+
/** This function waits on the real clock, until the test is true or the bound ends. It gives the test at the end. */
|
|
69
|
+
const within = async (bound, test) => {
|
|
70
|
+
const end = realNow() + bound;
|
|
71
|
+
for (;;) {
|
|
72
|
+
if (test()) return true;
|
|
73
|
+
if (realNow() > end) return test();
|
|
74
|
+
await turn();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
/** This function lets the events that are ready reach the transport, with no move of the clock of the case. */
|
|
78
|
+
const quiet = async () => {
|
|
79
|
+
for (let at = 0; at < 8; at += 1) await turn();
|
|
80
|
+
};
|
|
81
|
+
/** This function uses a method of the transport, and gives a throw of the method as a rejection. */
|
|
82
|
+
const attempt = (call) => {
|
|
83
|
+
try {
|
|
84
|
+
return Promise.resolve(call());
|
|
85
|
+
} catch (error) {
|
|
86
|
+
return Promise.reject(error);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const track = (promise) => {
|
|
90
|
+
const state = {
|
|
91
|
+
settled: false,
|
|
92
|
+
error: void 0,
|
|
93
|
+
failed: false
|
|
94
|
+
};
|
|
95
|
+
promise.then(() => {
|
|
96
|
+
state.settled = true;
|
|
97
|
+
}, (error) => {
|
|
98
|
+
state.settled = true;
|
|
99
|
+
state.failed = true;
|
|
100
|
+
state.error = error;
|
|
101
|
+
});
|
|
102
|
+
return state;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* This function generates the conformance cases of a transport (S6 A9). `make` gives a new subject
|
|
106
|
+
* for each case. Each case throws on a failure, and its message names the part of the contract.
|
|
107
|
+
* - The start: nothing is in flight, and the transport takes work.
|
|
108
|
+
* - The count: it follows each work from its events, with no move of the clock.
|
|
109
|
+
* - `stopIntake` refuses new work, keeps the work in flight, and a second stop has no effect.
|
|
110
|
+
* - `drain` ends at once with no work, ends with the last work, and holds to its deadline and not
|
|
111
|
+
* past it. It gives the cooperative abort to the work, and it does not throw.
|
|
112
|
+
* - `close` ends the work in flight in its bound, and a second close has no effect.
|
|
113
|
+
* - The stages in their sequence, as the lifecycle does them.
|
|
114
|
+
*
|
|
115
|
+
* The option `streams` adds the cases of the streams (S6 D4). Each request is a stream, and a
|
|
116
|
+
* unary call is a stream of one item. The kit gives the transport a lifecycle with request
|
|
117
|
+
* tracking. It also does the stages of the shutdown on the tracker, as the lifecycle does them.
|
|
118
|
+
* - A unary call gives one value, and its end comes as the status of the answer.
|
|
119
|
+
* - A stream stays in flight until its end, not until its first item.
|
|
120
|
+
* - A failure after the first item ends the stream with an error line in the body, not a status.
|
|
121
|
+
* A failure before the first item gets a status.
|
|
122
|
+
* - `drain` waits for an open stream. The cooperative abort ends the stream, and its caller gets the end.
|
|
123
|
+
* - At the deadline of the drain, the cut ends an open stream, and its caller gets the end.
|
|
124
|
+
*/
|
|
125
|
+
const transportConformance = (make, options = {}) => {
|
|
126
|
+
const name = options.name ?? "transport";
|
|
127
|
+
const fake = (options.clock ?? "fake") === "fake";
|
|
128
|
+
const cap = options.cap ?? 1e3;
|
|
129
|
+
const closeBound = options.closeBound ?? 1e3;
|
|
130
|
+
const slack = options.slack ?? 100;
|
|
131
|
+
const cooperative = options.cooperative ?? true;
|
|
132
|
+
const holds = options.holds ?? 3;
|
|
133
|
+
const timeOf = () => {
|
|
134
|
+
if (!fake) return {
|
|
135
|
+
clock: realClock,
|
|
136
|
+
pass: (ms) => delay(alive, ms)
|
|
137
|
+
};
|
|
138
|
+
const clock = fakeClock();
|
|
139
|
+
return {
|
|
140
|
+
clock,
|
|
141
|
+
pass: (ms) => clock.advance(ms)
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
const check = (ok, what) => {
|
|
145
|
+
if (!ok) throw new Error(`${name}: ${what}`);
|
|
146
|
+
};
|
|
147
|
+
const each = (title, body) => ({
|
|
148
|
+
name: `${name}: ${title}`,
|
|
149
|
+
async run() {
|
|
150
|
+
const time = timeOf();
|
|
151
|
+
const subject = await make(time.clock);
|
|
152
|
+
try {
|
|
153
|
+
await subject.impl.start(new AbortController().signal, subject.life ?? detachedLifecycle());
|
|
154
|
+
await body(subject, time, title);
|
|
155
|
+
} finally {
|
|
156
|
+
try {
|
|
157
|
+
await subject.impl.close();
|
|
158
|
+
} finally {
|
|
159
|
+
await subject.dispose?.();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
const count = (subject, expected, what) => within(slack, () => subject.impl.inFlight() === expected).then((ok) => check(ok, `${what}: inFlight() gives ${subject.impl.inFlight()}, not ${expected}`));
|
|
165
|
+
const closes = async (subject, title) => {
|
|
166
|
+
const began = realNow();
|
|
167
|
+
const closed = track(attempt(() => subject.impl.close()));
|
|
168
|
+
const inBound = await within(closeBound, () => closed.settled);
|
|
169
|
+
const took = realNow() - began;
|
|
170
|
+
options.record?.({
|
|
171
|
+
case: title,
|
|
172
|
+
what: "close",
|
|
173
|
+
expected: closeBound,
|
|
174
|
+
measured: took
|
|
175
|
+
});
|
|
176
|
+
check(inBound, `close did not end in its bound of ${closeBound} ms`);
|
|
177
|
+
check(!closed.failed, `close threw: ${String(closed.error)}`);
|
|
178
|
+
};
|
|
179
|
+
const cases = [
|
|
180
|
+
each("nothing is in flight after the start, and it takes new work", async (subject) => {
|
|
181
|
+
check(subject.impl.inFlight() === 0, `inFlight() gives ${subject.impl.inFlight()} after the start, not 0`);
|
|
182
|
+
check(await subject.offer(), "the transport refused new work after its start");
|
|
183
|
+
await count(subject, 0, "the work ended");
|
|
184
|
+
}),
|
|
185
|
+
each("the count follows each work in flight from its events, with no move of the clock", async (subject) => {
|
|
186
|
+
const held = [];
|
|
187
|
+
for (let at = 1; at <= holds; at += 1) {
|
|
188
|
+
held.push(await subject.hold());
|
|
189
|
+
await count(subject, at, `${at} works are in flight`);
|
|
190
|
+
}
|
|
191
|
+
for (let at = holds - 1; at >= 0; at -= 1) {
|
|
192
|
+
await held[at].release();
|
|
193
|
+
await count(subject, at, `${at} works are in flight after a release`);
|
|
194
|
+
}
|
|
195
|
+
}),
|
|
196
|
+
each("stopIntake refuses new work, keeps the work in flight, and a second stop has no effect", async (subject) => {
|
|
197
|
+
const work = await subject.hold();
|
|
198
|
+
await subject.impl.stopIntake();
|
|
199
|
+
check(!await subject.offer(), "the transport took new work after stopIntake");
|
|
200
|
+
await count(subject, 1, "stopIntake cut the work in flight");
|
|
201
|
+
await subject.impl.stopIntake();
|
|
202
|
+
check(!await subject.offer(), "the transport took new work after a second stopIntake");
|
|
203
|
+
await work.release();
|
|
204
|
+
await count(subject, 0, "the work in flight ended after stopIntake");
|
|
205
|
+
}),
|
|
206
|
+
each("drain ends at once when nothing is in flight", async (subject, time) => {
|
|
207
|
+
await subject.impl.stopIntake();
|
|
208
|
+
const drained = track(attempt(() => subject.impl.drain(time.clock.now() + cap, new AbortController().signal)));
|
|
209
|
+
check(await within(slack, () => drained.settled), "drain did not end with nothing in flight");
|
|
210
|
+
check(!drained.failed, `drain threw: ${String(drained.error)}`);
|
|
211
|
+
}),
|
|
212
|
+
each("drain ends when the last work ends, before its deadline", async (subject, time) => {
|
|
213
|
+
const work = await subject.hold();
|
|
214
|
+
await subject.impl.stopIntake();
|
|
215
|
+
const deadline = time.clock.now() + cap;
|
|
216
|
+
const drained = track(attempt(() => subject.impl.drain(deadline, new AbortController().signal)));
|
|
217
|
+
await time.pass(cap / 4);
|
|
218
|
+
await quiet();
|
|
219
|
+
check(!drained.settled, "drain ended while work was in flight, before its deadline");
|
|
220
|
+
await work.release();
|
|
221
|
+
check(await within(slack, () => drained.settled), "drain did not end when the last work ended");
|
|
222
|
+
check(!drained.failed, `drain threw: ${String(drained.error)}`);
|
|
223
|
+
check(time.clock.now() < deadline, "drain waited until its deadline after the last work ended");
|
|
224
|
+
}),
|
|
225
|
+
each("drain holds to its deadline and not past it, and does not throw", async (subject, time, title) => {
|
|
226
|
+
await subject.hold();
|
|
227
|
+
await subject.impl.stopIntake();
|
|
228
|
+
const began = realNow();
|
|
229
|
+
const deadline = time.clock.now() + cap;
|
|
230
|
+
const drained = track(attempt(() => subject.impl.drain(deadline, new AbortController().signal)));
|
|
231
|
+
if (fake) {
|
|
232
|
+
await time.pass(cap - 1);
|
|
233
|
+
await quiet();
|
|
234
|
+
check(!drained.settled, "drain ended before its deadline, with work in flight");
|
|
235
|
+
await time.pass(1);
|
|
236
|
+
check(await within(slack, () => drained.settled), "drain did not end at its deadline");
|
|
237
|
+
} else {
|
|
238
|
+
const ended = await within(cap + slack, () => drained.settled);
|
|
239
|
+
const took = realNow() - began;
|
|
240
|
+
options.record?.({
|
|
241
|
+
case: title,
|
|
242
|
+
what: "drain to its deadline",
|
|
243
|
+
expected: cap,
|
|
244
|
+
measured: took
|
|
245
|
+
});
|
|
246
|
+
check(ended, `drain did not end in ${cap + slack} ms, with a deadline at ${cap} ms`);
|
|
247
|
+
check(took >= cap - slack, `drain ended after ${Math.round(took)} ms, before its deadline at ${cap} ms`);
|
|
248
|
+
}
|
|
249
|
+
check(!drained.failed, `drain threw at its deadline: ${String(drained.error)}`);
|
|
250
|
+
}),
|
|
251
|
+
...cooperative ? [each("drain gives the cooperative abort to the work in flight", async (subject, time) => {
|
|
252
|
+
const work = await subject.hold();
|
|
253
|
+
await subject.impl.stopIntake();
|
|
254
|
+
const abort = new AbortController();
|
|
255
|
+
const drained = track(attempt(() => subject.impl.drain(time.clock.now() + cap, abort.signal)));
|
|
256
|
+
await time.pass(cap / 2);
|
|
257
|
+
await quiet();
|
|
258
|
+
check(!work.aborted, "the work got an abort before the signal of the drain aborted");
|
|
259
|
+
abort.abort(/* @__PURE__ */ new Error("the cooperative abort of the conformance kit"));
|
|
260
|
+
check(await within(slack, () => work.aborted), "the work did not get the cooperative abort");
|
|
261
|
+
await time.pass(cap / 2);
|
|
262
|
+
check(await within(slack, () => drained.settled), "drain did not end at its deadline after the cooperative abort");
|
|
263
|
+
check(!drained.failed, `drain threw after the cooperative abort: ${String(drained.error)}`);
|
|
264
|
+
})] : [],
|
|
265
|
+
each("drain with an aborted signal and a deadline in the past ends at once", async (subject, time) => {
|
|
266
|
+
const work = await subject.hold();
|
|
267
|
+
await subject.impl.stopIntake();
|
|
268
|
+
const abort = new AbortController();
|
|
269
|
+
abort.abort(/* @__PURE__ */ new Error("the cooperative abort of the conformance kit"));
|
|
270
|
+
const drained = track(attempt(() => subject.impl.drain(time.clock.now() - 1, abort.signal)));
|
|
271
|
+
check(await within(slack, () => drained.settled), "drain did not end at once with its deadline in the past");
|
|
272
|
+
check(!drained.failed, `drain threw: ${String(drained.error)}`);
|
|
273
|
+
if (cooperative) check(await within(slack, () => work.aborted), "the work did not get an abort that came before the drain");
|
|
274
|
+
}),
|
|
275
|
+
each("close ends the work in flight, in its bound", async (subject, _time, title) => {
|
|
276
|
+
for (let at = 0; at < holds; at += 1) await subject.hold();
|
|
277
|
+
await count(subject, holds, "the works are in flight before the close");
|
|
278
|
+
await closes(subject, title);
|
|
279
|
+
await count(subject, 0, "close left work in flight");
|
|
280
|
+
}),
|
|
281
|
+
each("close is idempotent: a second close has no effect", async (subject, _time, title) => {
|
|
282
|
+
await subject.hold();
|
|
283
|
+
const first = track(attempt(() => subject.impl.close()));
|
|
284
|
+
const second = track(attempt(() => subject.impl.close()));
|
|
285
|
+
check(await within(closeBound, () => first.settled && second.settled), "two closes did not end in the bound");
|
|
286
|
+
check(!first.failed && !second.failed, `a close threw: ${String(first.error ?? second.error)}`);
|
|
287
|
+
await closes(subject, title);
|
|
288
|
+
await count(subject, 0, "the closes left work in flight");
|
|
289
|
+
}),
|
|
290
|
+
each("close right after the start ends in its bound", async (subject, _time, title) => {
|
|
291
|
+
await closes(subject, title);
|
|
292
|
+
check(subject.impl.inFlight() === 0, "inFlight() is not 0 after a close with no work");
|
|
293
|
+
}),
|
|
294
|
+
each("the stages in their sequence: stop intake, drain with its cooperative abort, close", async (subject, time, title) => {
|
|
295
|
+
const short = await subject.hold();
|
|
296
|
+
const long = await subject.hold();
|
|
297
|
+
await subject.impl.stopIntake();
|
|
298
|
+
check(!await subject.offer(), "the transport took new work after stopIntake");
|
|
299
|
+
const abort = new AbortController();
|
|
300
|
+
const drained = track(attempt(() => subject.impl.drain(time.clock.now() + cap, abort.signal)));
|
|
301
|
+
await short.release();
|
|
302
|
+
await count(subject, 1, "one work ended in the drain");
|
|
303
|
+
await time.pass(cap / 2);
|
|
304
|
+
abort.abort(/* @__PURE__ */ new Error("the cooperative abort of the conformance kit"));
|
|
305
|
+
if (cooperative) check(await within(slack, () => long.aborted), "the long work did not get the cooperative abort");
|
|
306
|
+
await time.pass(cap / 2);
|
|
307
|
+
check(await within(slack, () => drained.settled), "drain did not end at its deadline");
|
|
308
|
+
await closes(subject, title);
|
|
309
|
+
await count(subject, 0, "close left work in flight");
|
|
310
|
+
})
|
|
311
|
+
];
|
|
312
|
+
if (!(options.streams ?? false)) return cases;
|
|
313
|
+
const eachStream = (title, body) => ({
|
|
314
|
+
name: `${name}: ${title}`,
|
|
315
|
+
async run() {
|
|
316
|
+
const time = timeOf();
|
|
317
|
+
const subject = await make(time.clock);
|
|
318
|
+
const { life, requests } = trackedLifecycle(time.clock);
|
|
319
|
+
try {
|
|
320
|
+
await subject.impl.start(new AbortController().signal, life);
|
|
321
|
+
check(subject.call !== void 0, "the option streams needs a subject that gives call()");
|
|
322
|
+
await body(subject, time, requests);
|
|
323
|
+
} finally {
|
|
324
|
+
requests.stopIntake();
|
|
325
|
+
requests.cooperativeAbort();
|
|
326
|
+
try {
|
|
327
|
+
await subject.impl.close();
|
|
328
|
+
} finally {
|
|
329
|
+
await subject.dispose?.();
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
const call = (subject, given) => Promise.resolve(subject.call(given));
|
|
335
|
+
const openStream = async (subject) => {
|
|
336
|
+
const source = pushedSource();
|
|
337
|
+
let started = false;
|
|
338
|
+
let signal = null;
|
|
339
|
+
const view = await call(subject, {
|
|
340
|
+
...CALLS,
|
|
341
|
+
stream: true,
|
|
342
|
+
work: (given) => {
|
|
343
|
+
started = true;
|
|
344
|
+
signal = given;
|
|
345
|
+
return source.iterable;
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
check(await within(slack, () => started), "the work of a stream call did not start");
|
|
349
|
+
return {
|
|
350
|
+
view,
|
|
351
|
+
push: (value) => source.push(value),
|
|
352
|
+
finish: () => source.finish(),
|
|
353
|
+
fail: (error) => source.fail(error),
|
|
354
|
+
get aborted() {
|
|
355
|
+
return signal?.aborted === true;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
const pushes = async (fed, value, what) => {
|
|
360
|
+
const before = fed.view.items.length;
|
|
361
|
+
fed.push(value);
|
|
362
|
+
check(await within(slack, () => fed.view.items.length > before), `${what}: the caller did not get the item ${value}`);
|
|
363
|
+
};
|
|
364
|
+
const ends = async (view, kind, inBand, what) => {
|
|
365
|
+
check(await within(slack, () => view.end !== null), `${what}: the caller got no end`);
|
|
366
|
+
const end = view.end;
|
|
367
|
+
const where = (body) => body ? "in the body" : "as a status";
|
|
368
|
+
check(end.kind === kind && end.inBand === inBand, `${what}: the caller got the end ${end.kind} ${where(end.inBand)}, not ${kind} ${where(inBand)}`);
|
|
369
|
+
};
|
|
370
|
+
/** This function stops the intake of the tracker and of the transport, as the stage `stop intake` does. */
|
|
371
|
+
const stopBoth = async (subject, requests) => {
|
|
372
|
+
requests.stopIntake();
|
|
373
|
+
await subject.impl.stopIntake();
|
|
374
|
+
};
|
|
375
|
+
/**
|
|
376
|
+
* This function starts the drain of the transport and of the tracker, as the stage `drain` does.
|
|
377
|
+
* The abort of `signal` is also the cooperative abort of the tracker. It tracks the drain of the transport.
|
|
378
|
+
*/
|
|
379
|
+
const drainBoth = (subject, requests, deadline, signal) => {
|
|
380
|
+
if (signal.aborted) requests.cooperativeAbort();
|
|
381
|
+
else signal.addEventListener("abort", () => requests.cooperativeAbort(), { once: true });
|
|
382
|
+
requests.drain(deadline);
|
|
383
|
+
return track(attempt(() => subject.impl.drain(deadline, signal)));
|
|
384
|
+
};
|
|
385
|
+
const failure = () => /* @__PURE__ */ new Error("the failure of the conformance kit");
|
|
386
|
+
const streamCases = [
|
|
387
|
+
eachStream("a unary call is a stream of one item: one value, and its end as the status", async (subject) => {
|
|
388
|
+
let started = false;
|
|
389
|
+
let give = () => {};
|
|
390
|
+
const view = await call(subject, {
|
|
391
|
+
...CALLS,
|
|
392
|
+
stream: false,
|
|
393
|
+
work: () => {
|
|
394
|
+
started = true;
|
|
395
|
+
return new Promise((resolve) => {
|
|
396
|
+
give = resolve;
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
check(await within(slack, () => started), "the work of a unary call did not start");
|
|
401
|
+
await count(subject, 1, "a unary call is in flight");
|
|
402
|
+
give(7);
|
|
403
|
+
await ends(view, "done", false, "a unary call");
|
|
404
|
+
check(view.items.length === 1 && view.items[0] === 7, `a unary call gave the items ${JSON.stringify(view.items)}, not [7]`);
|
|
405
|
+
await count(subject, 0, "a unary call ended");
|
|
406
|
+
}),
|
|
407
|
+
eachStream("a stream stays in flight until its end, not until its first item", async (subject) => {
|
|
408
|
+
const fed = await openStream(subject);
|
|
409
|
+
await count(subject, 1, "a stream is open");
|
|
410
|
+
for (const value of [1, 2]) {
|
|
411
|
+
await pushes(fed, value, "an open stream");
|
|
412
|
+
await count(subject, 1, `a stream is open after its item ${value}`);
|
|
413
|
+
}
|
|
414
|
+
check(fed.view.end === null, "the caller got an end before the end of the stream");
|
|
415
|
+
fed.finish();
|
|
416
|
+
await ends(fed.view, "done", true, "a stream that ended");
|
|
417
|
+
check(JSON.stringify(fed.view.items) === "[1,2]", `a stream gave the items ${JSON.stringify(fed.view.items)}, not [1,2]`);
|
|
418
|
+
await count(subject, 0, "a stream ended");
|
|
419
|
+
}),
|
|
420
|
+
eachStream("a failure after the first item ends the stream with an error line, not a status", async (subject) => {
|
|
421
|
+
const fed = await openStream(subject);
|
|
422
|
+
await pushes(fed, 1, "a stream before its failure");
|
|
423
|
+
fed.fail(failure());
|
|
424
|
+
await ends(fed.view, "failed", true, "a stream that failed after its first item");
|
|
425
|
+
await count(subject, 0, "a stream failed");
|
|
426
|
+
}),
|
|
427
|
+
eachStream("a failure before the first item gets a status, not an error line", async (subject) => {
|
|
428
|
+
const fed = await openStream(subject);
|
|
429
|
+
fed.fail(failure());
|
|
430
|
+
await ends(fed.view, "failed", false, "a stream that failed before its first item");
|
|
431
|
+
check(fed.view.items.length === 0, `a stream that failed before its first item gave ${fed.view.items.length} items`);
|
|
432
|
+
await count(subject, 0, "a stream failed");
|
|
433
|
+
}),
|
|
434
|
+
eachStream("drain waits for an open stream, and the cooperative abort ends the stream with its end", async (subject, time, requests) => {
|
|
435
|
+
const fed = await openStream(subject);
|
|
436
|
+
await pushes(fed, 1, "a stream before the drain");
|
|
437
|
+
await stopBoth(subject, requests);
|
|
438
|
+
const abort = new AbortController();
|
|
439
|
+
const deadline = time.clock.now() + cap;
|
|
440
|
+
const drained = drainBoth(subject, requests, deadline, abort.signal);
|
|
441
|
+
await time.pass(cap / 4);
|
|
442
|
+
await quiet();
|
|
443
|
+
check(!drained.settled, "drain ended while a stream was open, before its deadline");
|
|
444
|
+
check(fed.view.end === null, "the caller got an end before the cooperative abort");
|
|
445
|
+
await count(subject, 1, "a stream is open in the drain");
|
|
446
|
+
abort.abort(/* @__PURE__ */ new Error("the cooperative abort of the conformance kit"));
|
|
447
|
+
check(await within(slack, () => fed.aborted), "the work of the stream did not get the cooperative abort");
|
|
448
|
+
await ends(fed.view, "cut", true, "a stream after the cooperative abort");
|
|
449
|
+
check(await within(slack, () => drained.settled), "drain did not end when the stream ended");
|
|
450
|
+
check(!drained.failed, `drain threw: ${String(drained.error)}`);
|
|
451
|
+
check(time.clock.now() < deadline, "drain waited until its deadline after the stream ended");
|
|
452
|
+
await count(subject, 0, "the cooperative abort left a stream in flight");
|
|
453
|
+
}),
|
|
454
|
+
eachStream("drain cuts an open stream at its deadline, and the caller gets the end of the cut", async (subject, time, requests) => {
|
|
455
|
+
const fed = await openStream(subject);
|
|
456
|
+
await pushes(fed, 1, "a stream before the drain");
|
|
457
|
+
await stopBoth(subject, requests);
|
|
458
|
+
const drained = drainBoth(subject, requests, time.clock.now() + cap, new AbortController().signal);
|
|
459
|
+
await time.pass(cap);
|
|
460
|
+
await ends(fed.view, "cut", true, "a stream at the deadline of the drain");
|
|
461
|
+
check(await within(slack, () => drained.settled), "drain did not end after the cut of the stream");
|
|
462
|
+
check(!drained.failed, `drain threw at its deadline: ${String(drained.error)}`);
|
|
463
|
+
await count(subject, 0, "the cut left a stream in flight");
|
|
464
|
+
})
|
|
465
|
+
];
|
|
466
|
+
return [...cases, ...streamCases];
|
|
467
|
+
};
|
|
468
|
+
export { detachedLifecycle, transportConformance };
|
|
469
|
+
|
|
470
|
+
//# sourceMappingURL=conformance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conformance.js","names":[],"sources":["../src/conformance.ts"],"sourcesContent":["import { delay } from \"@mark1russell7/algebra/clock\";\nimport type { Clock } from \"./clock.ts\";\nimport { platformClock, realClock } from \"./clock.ts\";\nimport type { ContractCase } from \"./contract.ts\";\nimport { ownStream } from \"./drains.ts\";\nimport { fakeClock } from \"./fakes.ts\";\nimport type { Health } from \"./health.ts\";\nimport { pushedSource } from \"./http/fake-server.ts\";\nimport type { Lifecycle, TransportImpl } from \"./lifecycle.ts\";\nimport type { RequestEnd, RequestFn, Tracker } from \"./requests.ts\";\nimport { tracker } from \"./requests.ts\";\n\n/** A held work is one unit of work that stays in flight until the test releases it. */\nexport interface HeldWork {\n /** This method lets the work end. Its promise ends when the caller of the work has its answer, or its error. */\n release(): Promise<void>;\n /** This flag tells if the work got the cooperative abort of the drain. */\n readonly aborted: boolean;\n}\n\n/**\n * A transport subject is a transport and the client side of its work. The kit offers work through\n * it, holds work in flight through it, and reads the count of the transport.\n */\nexport interface TransportSubject {\n readonly impl: TransportImpl;\n /** This lifecycle goes to `start()`. Without it, the kit gives a detached lifecycle. */\n readonly life?: Lifecycle | undefined;\n /** This method offers one unit of new work. It gives true when the transport took it, and false when it refused it. */\n offer(): Promise<boolean>;\n /** This method starts one unit of work that stays in flight until its release. The promise ends when the transport has it. */\n hold(): Promise<HeldWork>;\n /**\n * This method sends one call through the transport, for the stream cases (option `streams`). The\n * handler of the call gives `call.work` to `life.request(call.controller, call.route, ...)` of the\n * lifecycle of the start, and writes its stream to the caller. It gives what the caller sees.\n */\n call?(call: StreamCall): CallerView | Promise<CallerView>;\n /** This method frees what the subject holds outside the transport: its clients and their sockets. */\n dispose?(): Promise<void> | void;\n}\n\n/** A stream call is one request of the stream cases. The kit gives its work, and the subject sends it. */\nexport interface StreamCall {\n /** This name is the controller of the request in the lifecycle of the kit. */\n readonly controller: string;\n /** This name is the route of the request in the lifecycle of the kit. */\n readonly route: string;\n /** This function is the work of the request: one value, or a stream of values. */\n readonly work: RequestFn<unknown>;\n /** True tells that the answer is a stream of items. False tells that the answer is unary: one status and one value. */\n readonly stream: boolean;\n}\n\n/** A seen end is the end of a call, as its caller read it. */\nexport interface SeenEnd {\n readonly kind: RequestEnd[\"kind\"];\n /**\n * True tells that the end came in the body of the answer, after its status, for example as the\n * last line of a stream. False tells that the end came as the status of the answer.\n */\n readonly inBand: boolean;\n}\n\n/** A caller view is what the caller of a call has read so far. The kit reads it again until it changes. */\nexport interface CallerView {\n /** These values are the items that the caller read, in their sequence. */\n readonly items: readonly unknown[];\n /** This end is the end that the caller read, or null while the call is open. */\n readonly end: SeenEnd | null;\n}\n\n/**\n * This function gives a detached lifecycle: a lifecycle with no service, for the start of a\n * transport in a test. Its state is `running`, it keeps each connection, and nothing is in flight. Each request\n * and each use of its health throws, because no service declares a route.\n */\nexport const detachedLifecycle = (): Lifecycle => {\n const none = (): never => {\n throw new Error(\"a detached lifecycle has no service: give the transport the lifecycle of a service\");\n };\n const health = { verdict: none, probe: none, metrics: none, subscribe: none, forceFail: none, drain: none, stop: none } as Health;\n return {\n health,\n state: \"running\",\n exitCode: null,\n errors: [],\n started: Promise.resolve(),\n done: new Promise<number>(() => {}),\n signal: new AbortController().signal,\n shutdown: none,\n request: none,\n inFlight: () => 0,\n keepAlive: () => true,\n };\n};\n\n/** These names are the controller and the route of each call of the stream cases. */\nconst CALLS = { controller: \"conformance\", route: \"call\" } as const;\n\n/**\n * This function gives a lifecycle with request tracking for the stream cases, and its tracker. The\n * kit uses the tracker for the stages of the shutdown, as the lifecycle of a service does. Its\n * requests are not idempotent, and it admits each request until the stop of its intake.\n */\nconst trackedLifecycle = (clock: Clock): { readonly life: Lifecycle; readonly requests: Tracker } => {\n const requests = tracker([{ name: CALLS.controller, requires: [], routes: { [CALLS.route]: { idempotent: false } } }], clock, () => null);\n const life: Lifecycle = {\n ...detachedLifecycle(),\n // the lifecycle owns each stream that it makes, thus the drain of the transport waits for the end of its cut\n request: (controller, route, work, options) => ownStream(requests.request(controller, route, work, options), life),\n inFlight: (controller) => requests.inFlight(controller),\n };\n return { life, requests };\n};\n\n/** A subject factory makes a new subject for each case, on the clock of the case. */\nexport type SubjectFactory = (clock: Clock) => TransportSubject | Promise<TransportSubject>;\n\n/** A conformance record is one measurement of a case, for the raw records of a run in CI. */\nexport interface ConformanceRecord {\n readonly case: string;\n readonly what: string;\n /** This time is the limit of the contract, in milliseconds. */\n readonly expected: number;\n /** This time is what the case measured, in milliseconds of the real clock. */\n readonly measured: number;\n}\n\n/** These options tune the conformance kit. */\nexport interface ConformanceOptions {\n /** This name goes before the name of each case. */\n readonly name?: string | undefined;\n /** This clock moves the cases: `fake` gives exact and fast cases, and `real` measures the timing. The default is `fake`. */\n readonly clock?: \"fake\" | \"real\" | undefined;\n /** This time is the cap of each drain of the cases, in milliseconds. The default is 1000. */\n readonly cap?: number | undefined;\n /** This time is the most that a close can take, in milliseconds of the real clock. The default is 1000. */\n readonly closeBound?: number | undefined;\n /** This time is the most that an event can take to reach the transport, in real milliseconds. The default is 100. */\n readonly slack?: number | undefined;\n /** False tells that the work of the transport cannot see the cooperative abort. The default is true. */\n readonly cooperative?: boolean | undefined;\n /** This count is the number of works that the count case holds. The default is 3. */\n readonly holds?: number | undefined;\n /**\n * True adds the stream cases (S6 D4). Then the subject gives `call`, and the kit gives the\n * transport a lifecycle with request tracking. The default is false.\n */\n readonly streams?: boolean | undefined;\n /** This function receives each measurement, for the raw records of a run. */\n readonly record?: ((record: ConformanceRecord) => void) | undefined;\n}\n\ninterface Time {\n readonly clock: Clock;\n pass(ms: number): Promise<void>;\n}\n\ninterface Tracked {\n readonly settled: boolean;\n readonly error: unknown;\n readonly failed: boolean;\n}\n\nconst realNow = (): number => performance.now();\n// The waits of the case keep the process alive, as a plain setTimeout does. A timer of realClock does not.\nconst alive = platformClock();\nconst turn = (): Promise<void> => delay(alive, 0);\n\n/** This function waits on the real clock, until the test is true or the bound ends. It gives the test at the end. */\nconst within = async (bound: number, test: () => boolean): Promise<boolean> => {\n const end = realNow() + bound;\n for (;;) {\n if (test()) return true;\n if (realNow() > end) return test();\n await turn();\n }\n};\n\n/** This function lets the events that are ready reach the transport, with no move of the clock of the case. */\nconst quiet = async (): Promise<void> => {\n for (let at = 0; at < 8; at += 1) await turn();\n};\n\n/** This function uses a method of the transport, and gives a throw of the method as a rejection. */\nconst attempt = (call: () => Promise<void> | void): Promise<void> => {\n try {\n return Promise.resolve(call());\n } catch (error) {\n return Promise.reject(error);\n }\n};\n\nconst track = (promise: Promise<unknown>): Tracked => {\n const state = { settled: false, error: undefined as unknown, failed: false };\n promise.then(\n () => {\n state.settled = true;\n },\n (error: unknown) => {\n state.settled = true;\n state.failed = true;\n state.error = error;\n },\n );\n return state;\n};\n\n/**\n * This function generates the conformance cases of a transport (S6 A9). `make` gives a new subject\n * for each case. Each case throws on a failure, and its message names the part of the contract.\n * - The start: nothing is in flight, and the transport takes work.\n * - The count: it follows each work from its events, with no move of the clock.\n * - `stopIntake` refuses new work, keeps the work in flight, and a second stop has no effect.\n * - `drain` ends at once with no work, ends with the last work, and holds to its deadline and not\n * past it. It gives the cooperative abort to the work, and it does not throw.\n * - `close` ends the work in flight in its bound, and a second close has no effect.\n * - The stages in their sequence, as the lifecycle does them.\n *\n * The option `streams` adds the cases of the streams (S6 D4). Each request is a stream, and a\n * unary call is a stream of one item. The kit gives the transport a lifecycle with request\n * tracking. It also does the stages of the shutdown on the tracker, as the lifecycle does them.\n * - A unary call gives one value, and its end comes as the status of the answer.\n * - A stream stays in flight until its end, not until its first item.\n * - A failure after the first item ends the stream with an error line in the body, not a status.\n * A failure before the first item gets a status.\n * - `drain` waits for an open stream. The cooperative abort ends the stream, and its caller gets the end.\n * - At the deadline of the drain, the cut ends an open stream, and its caller gets the end.\n */\nexport const transportConformance = (make: SubjectFactory, options: ConformanceOptions = {}): ContractCase[] => {\n const name = options.name ?? \"transport\";\n const fake = (options.clock ?? \"fake\") === \"fake\";\n const cap = options.cap ?? 1000;\n const closeBound = options.closeBound ?? 1000;\n const slack = options.slack ?? 100;\n const cooperative = options.cooperative ?? true;\n const holds = options.holds ?? 3;\n\n const timeOf = (): Time => {\n if (!fake) return { clock: realClock, pass: (ms: number) => delay(alive, ms) };\n const clock = fakeClock();\n return { clock, pass: (ms) => clock.advance(ms) };\n };\n\n const check = (ok: boolean, what: string): void => {\n if (!ok) throw new Error(`${name}: ${what}`);\n };\n\n const each = (title: string, body: (subject: TransportSubject, time: Time, title: string) => Promise<void>): ContractCase => ({\n name: `${name}: ${title}`,\n async run() {\n const time = timeOf();\n const subject = await make(time.clock);\n try {\n await subject.impl.start(new AbortController().signal, subject.life ?? detachedLifecycle());\n await body(subject, time, title);\n } finally {\n try {\n await subject.impl.close();\n } finally {\n await subject.dispose?.();\n }\n }\n },\n });\n\n const count = (subject: TransportSubject, expected: number, what: string): Promise<void> =>\n within(slack, () => subject.impl.inFlight() === expected).then((ok) =>\n check(ok, `${what}: inFlight() gives ${subject.impl.inFlight()}, not ${expected}`),\n );\n\n const closes = async (subject: TransportSubject, title: string): Promise<void> => {\n const began = realNow();\n const closed = track(attempt(() => subject.impl.close()));\n const inBound = await within(closeBound, () => closed.settled);\n const took = realNow() - began;\n options.record?.({ case: title, what: \"close\", expected: closeBound, measured: took });\n check(inBound, `close did not end in its bound of ${closeBound} ms`);\n check(!closed.failed, `close threw: ${String(closed.error)}`);\n };\n\n const cases: ContractCase[] = [\n each(\"nothing is in flight after the start, and it takes new work\", async (subject) => {\n check(subject.impl.inFlight() === 0, `inFlight() gives ${subject.impl.inFlight()} after the start, not 0`);\n check(await subject.offer(), \"the transport refused new work after its start\");\n await count(subject, 0, \"the work ended\");\n }),\n\n each(\"the count follows each work in flight from its events, with no move of the clock\", async (subject) => {\n const held: HeldWork[] = [];\n for (let at = 1; at <= holds; at += 1) {\n held.push(await subject.hold());\n await count(subject, at, `${at} works are in flight`);\n }\n for (let at = holds - 1; at >= 0; at -= 1) {\n await held[at]!.release();\n await count(subject, at, `${at} works are in flight after a release`);\n }\n }),\n\n each(\"stopIntake refuses new work, keeps the work in flight, and a second stop has no effect\", async (subject) => {\n const work = await subject.hold();\n await subject.impl.stopIntake();\n check(!(await subject.offer()), \"the transport took new work after stopIntake\");\n await count(subject, 1, \"stopIntake cut the work in flight\");\n await subject.impl.stopIntake();\n check(!(await subject.offer()), \"the transport took new work after a second stopIntake\");\n await work.release();\n await count(subject, 0, \"the work in flight ended after stopIntake\");\n }),\n\n each(\"drain ends at once when nothing is in flight\", async (subject, time) => {\n await subject.impl.stopIntake();\n const drained = track(attempt(() => subject.impl.drain(time.clock.now() + cap, new AbortController().signal)));\n check(await within(slack, () => drained.settled), \"drain did not end with nothing in flight\");\n check(!drained.failed, `drain threw: ${String(drained.error)}`);\n }),\n\n each(\"drain ends when the last work ends, before its deadline\", async (subject, time) => {\n const work = await subject.hold();\n await subject.impl.stopIntake();\n const deadline = time.clock.now() + cap;\n const drained = track(attempt(() => subject.impl.drain(deadline, new AbortController().signal)));\n await time.pass(cap / 4);\n await quiet();\n check(!drained.settled, \"drain ended while work was in flight, before its deadline\");\n await work.release();\n check(await within(slack, () => drained.settled), \"drain did not end when the last work ended\");\n check(!drained.failed, `drain threw: ${String(drained.error)}`);\n check(time.clock.now() < deadline, \"drain waited until its deadline after the last work ended\");\n }),\n\n each(\"drain holds to its deadline and not past it, and does not throw\", async (subject, time, title) => {\n await subject.hold();\n await subject.impl.stopIntake();\n const began = realNow();\n const deadline = time.clock.now() + cap;\n const drained = track(attempt(() => subject.impl.drain(deadline, new AbortController().signal)));\n if (fake) {\n await time.pass(cap - 1);\n await quiet();\n check(!drained.settled, \"drain ended before its deadline, with work in flight\");\n await time.pass(1);\n check(await within(slack, () => drained.settled), \"drain did not end at its deadline\");\n } else {\n const ended = await within(cap + slack, () => drained.settled);\n const took = realNow() - began;\n options.record?.({ case: title, what: \"drain to its deadline\", expected: cap, measured: took });\n check(ended, `drain did not end in ${cap + slack} ms, with a deadline at ${cap} ms`);\n check(took >= cap - slack, `drain ended after ${Math.round(took)} ms, before its deadline at ${cap} ms`);\n }\n check(!drained.failed, `drain threw at its deadline: ${String(drained.error)}`);\n }),\n\n ...(cooperative\n ? [\n each(\"drain gives the cooperative abort to the work in flight\", async (subject, time) => {\n const work = await subject.hold();\n await subject.impl.stopIntake();\n const abort = new AbortController();\n const drained = track(attempt(() => subject.impl.drain(time.clock.now() + cap, abort.signal)));\n await time.pass(cap / 2);\n await quiet();\n check(!work.aborted, \"the work got an abort before the signal of the drain aborted\");\n abort.abort(new Error(\"the cooperative abort of the conformance kit\"));\n check(await within(slack, () => work.aborted), \"the work did not get the cooperative abort\");\n await time.pass(cap / 2);\n check(await within(slack, () => drained.settled), \"drain did not end at its deadline after the cooperative abort\");\n check(!drained.failed, `drain threw after the cooperative abort: ${String(drained.error)}`);\n }),\n ]\n : []),\n\n each(\"drain with an aborted signal and a deadline in the past ends at once\", async (subject, time) => {\n const work = await subject.hold();\n await subject.impl.stopIntake();\n const abort = new AbortController();\n abort.abort(new Error(\"the cooperative abort of the conformance kit\"));\n const drained = track(attempt(() => subject.impl.drain(time.clock.now() - 1, abort.signal)));\n check(await within(slack, () => drained.settled), \"drain did not end at once with its deadline in the past\");\n check(!drained.failed, `drain threw: ${String(drained.error)}`);\n if (cooperative) check(await within(slack, () => work.aborted), \"the work did not get an abort that came before the drain\");\n }),\n\n each(\"close ends the work in flight, in its bound\", async (subject, _time, title) => {\n for (let at = 0; at < holds; at += 1) await subject.hold();\n await count(subject, holds, \"the works are in flight before the close\");\n await closes(subject, title);\n await count(subject, 0, \"close left work in flight\");\n }),\n\n each(\"close is idempotent: a second close has no effect\", async (subject, _time, title) => {\n await subject.hold();\n const first = track(attempt(() => subject.impl.close()));\n const second = track(attempt(() => subject.impl.close()));\n check(await within(closeBound, () => first.settled && second.settled), \"two closes did not end in the bound\");\n check(!first.failed && !second.failed, `a close threw: ${String(first.error ?? second.error)}`);\n await closes(subject, title);\n await count(subject, 0, \"the closes left work in flight\");\n }),\n\n each(\"close right after the start ends in its bound\", async (subject, _time, title) => {\n await closes(subject, title);\n check(subject.impl.inFlight() === 0, \"inFlight() is not 0 after a close with no work\");\n }),\n\n each(\"the stages in their sequence: stop intake, drain with its cooperative abort, close\", async (subject, time, title) => {\n const short = await subject.hold();\n const long = await subject.hold();\n await subject.impl.stopIntake();\n check(!(await subject.offer()), \"the transport took new work after stopIntake\");\n const abort = new AbortController();\n const drained = track(attempt(() => subject.impl.drain(time.clock.now() + cap, abort.signal)));\n await short.release();\n await count(subject, 1, \"one work ended in the drain\");\n await time.pass(cap / 2);\n abort.abort(new Error(\"the cooperative abort of the conformance kit\"));\n if (cooperative) check(await within(slack, () => long.aborted), \"the long work did not get the cooperative abort\");\n await time.pass(cap / 2);\n check(await within(slack, () => drained.settled), \"drain did not end at its deadline\");\n await closes(subject, title);\n await count(subject, 0, \"close left work in flight\");\n }),\n ];\n if (!(options.streams ?? false)) return cases;\n\n /** A fed stream is a stream call whose items, end and failure the case gives. */\n interface Fed {\n readonly view: CallerView;\n push(value: unknown): void;\n finish(): void;\n fail(error: Error): void;\n /** This flag tells if the work got the abort of its signal. */\n readonly aborted: boolean;\n }\n\n const eachStream = (\n title: string,\n body: (subject: TransportSubject, time: Time, requests: Tracker) => Promise<void>,\n ): ContractCase => ({\n name: `${name}: ${title}`,\n async run() {\n const time = timeOf();\n const subject = await make(time.clock);\n const { life, requests } = trackedLifecycle(time.clock);\n try {\n await subject.impl.start(new AbortController().signal, life);\n check(subject.call !== undefined, \"the option streams needs a subject that gives call()\");\n await body(subject, time, requests);\n } finally {\n // each work of the case ends, thus no stream stays open after the case\n requests.stopIntake();\n requests.cooperativeAbort();\n try {\n await subject.impl.close();\n } finally {\n await subject.dispose?.();\n }\n }\n },\n });\n\n const call = (subject: TransportSubject, given: StreamCall): Promise<CallerView> => Promise.resolve(subject.call!(given));\n\n const openStream = async (subject: TransportSubject): Promise<Fed> => {\n const source = pushedSource<unknown>();\n let started = false;\n let signal: AbortSignal | null = null;\n const view = await call(subject, {\n ...CALLS,\n stream: true,\n work: (given) => {\n started = true;\n signal = given;\n return source.iterable;\n },\n });\n check(await within(slack, () => started), \"the work of a stream call did not start\");\n return {\n view,\n push: (value) => source.push(value),\n finish: () => source.finish(),\n fail: (error) => source.fail(error),\n get aborted() {\n return (signal as AbortSignal | null)?.aborted === true;\n },\n };\n };\n\n const pushes = async (fed: Fed, value: number, what: string): Promise<void> => {\n const before = fed.view.items.length;\n fed.push(value);\n check(await within(slack, () => fed.view.items.length > before), `${what}: the caller did not get the item ${value}`);\n };\n\n const ends = async (view: CallerView, kind: RequestEnd[\"kind\"], inBand: boolean, what: string): Promise<void> => {\n check(await within(slack, () => view.end !== null), `${what}: the caller got no end`);\n const end = view.end!;\n const where = (body: boolean): string => (body ? \"in the body\" : \"as a status\");\n check(\n end.kind === kind && end.inBand === inBand,\n `${what}: the caller got the end ${end.kind} ${where(end.inBand)}, not ${kind} ${where(inBand)}`,\n );\n };\n\n /** This function stops the intake of the tracker and of the transport, as the stage `stop intake` does. */\n const stopBoth = async (subject: TransportSubject, requests: Tracker): Promise<void> => {\n requests.stopIntake();\n await subject.impl.stopIntake();\n };\n\n /**\n * This function starts the drain of the transport and of the tracker, as the stage `drain` does.\n * The abort of `signal` is also the cooperative abort of the tracker. It tracks the drain of the transport.\n */\n const drainBoth = (subject: TransportSubject, requests: Tracker, deadline: number, signal: AbortSignal): Tracked => {\n if (signal.aborted) requests.cooperativeAbort();\n else signal.addEventListener(\"abort\", () => requests.cooperativeAbort(), { once: true });\n void requests.drain(deadline);\n return track(attempt(() => subject.impl.drain(deadline, signal)));\n };\n\n const failure = (): Error => new Error(\"the failure of the conformance kit\");\n\n const streamCases: ContractCase[] = [\n eachStream(\"a unary call is a stream of one item: one value, and its end as the status\", async (subject) => {\n let started = false;\n let give: (value: unknown) => void = () => {};\n const view = await call(subject, {\n ...CALLS,\n stream: false,\n work: () => {\n started = true;\n return new Promise<unknown>((resolve) => {\n give = resolve;\n });\n },\n });\n check(await within(slack, () => started), \"the work of a unary call did not start\");\n await count(subject, 1, \"a unary call is in flight\");\n give(7);\n await ends(view, \"done\", false, \"a unary call\");\n check(view.items.length === 1 && view.items[0] === 7, `a unary call gave the items ${JSON.stringify(view.items)}, not [7]`);\n await count(subject, 0, \"a unary call ended\");\n }),\n\n eachStream(\"a stream stays in flight until its end, not until its first item\", async (subject) => {\n const fed = await openStream(subject);\n await count(subject, 1, \"a stream is open\");\n for (const value of [1, 2]) {\n await pushes(fed, value, \"an open stream\");\n await count(subject, 1, `a stream is open after its item ${value}`);\n }\n check(fed.view.end === null, \"the caller got an end before the end of the stream\");\n fed.finish();\n await ends(fed.view, \"done\", true, \"a stream that ended\");\n check(JSON.stringify(fed.view.items) === \"[1,2]\", `a stream gave the items ${JSON.stringify(fed.view.items)}, not [1,2]`);\n await count(subject, 0, \"a stream ended\");\n }),\n\n eachStream(\"a failure after the first item ends the stream with an error line, not a status\", async (subject) => {\n const fed = await openStream(subject);\n await pushes(fed, 1, \"a stream before its failure\");\n fed.fail(failure());\n await ends(fed.view, \"failed\", true, \"a stream that failed after its first item\");\n await count(subject, 0, \"a stream failed\");\n }),\n\n eachStream(\"a failure before the first item gets a status, not an error line\", async (subject) => {\n const fed = await openStream(subject);\n fed.fail(failure());\n await ends(fed.view, \"failed\", false, \"a stream that failed before its first item\");\n check(fed.view.items.length === 0, `a stream that failed before its first item gave ${fed.view.items.length} items`);\n await count(subject, 0, \"a stream failed\");\n }),\n\n eachStream(\"drain waits for an open stream, and the cooperative abort ends the stream with its end\", async (subject, time, requests) => {\n const fed = await openStream(subject);\n await pushes(fed, 1, \"a stream before the drain\");\n await stopBoth(subject, requests);\n const abort = new AbortController();\n const deadline = time.clock.now() + cap;\n const drained = drainBoth(subject, requests, deadline, abort.signal);\n await time.pass(cap / 4);\n await quiet();\n check(!drained.settled, \"drain ended while a stream was open, before its deadline\");\n check(fed.view.end === null, \"the caller got an end before the cooperative abort\");\n await count(subject, 1, \"a stream is open in the drain\");\n abort.abort(new Error(\"the cooperative abort of the conformance kit\"));\n check(await within(slack, () => fed.aborted), \"the work of the stream did not get the cooperative abort\");\n await ends(fed.view, \"cut\", true, \"a stream after the cooperative abort\");\n check(await within(slack, () => drained.settled), \"drain did not end when the stream ended\");\n check(!drained.failed, `drain threw: ${String(drained.error)}`);\n check(time.clock.now() < deadline, \"drain waited until its deadline after the stream ended\");\n await count(subject, 0, \"the cooperative abort left a stream in flight\");\n }),\n\n eachStream(\"drain cuts an open stream at its deadline, and the caller gets the end of the cut\", async (subject, time, requests) => {\n const fed = await openStream(subject);\n await pushes(fed, 1, \"a stream before the drain\");\n await stopBoth(subject, requests);\n const drained = drainBoth(subject, requests, time.clock.now() + cap, new AbortController().signal);\n await time.pass(cap);\n await ends(fed.view, \"cut\", true, \"a stream at the deadline of the drain\");\n check(await within(slack, () => drained.settled), \"drain did not end after the cut of the stream\");\n check(!drained.failed, `drain threw at its deadline: ${String(drained.error)}`);\n await count(subject, 0, \"the cut left a stream in flight\");\n }),\n ];\n return [...cases, ...streamCases];\n};\n"],"mappings":";;;;;;;;;;;;AA6EA,MAAa,0BAAqC;CAChD,MAAM,aAAoB;EACxB,MAAM,IAA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ACA,OAAO,CAAC,GAAG,OAAO,GAAG,WAAW;AAClC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ServiceBuilder } from "./builder.js";
|
|
2
|
+
/** A contract case is one generated case of the contract test of a declaration. It throws on a failure. */
|
|
3
|
+
export interface ContractCase {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
run(): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
/** These options tune the contract test. */
|
|
8
|
+
export interface ContractOptions {
|
|
9
|
+
/** This number is the latency that a degraded dependency adds to each check, in milliseconds. The default of the contract is 100. */
|
|
10
|
+
readonly degradeBy?: number | undefined;
|
|
11
|
+
/** This number is the seed of the jitter. */
|
|
12
|
+
readonly seed?: number | undefined;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* This function generates the contract test of a declaration. `declare` gives a new builder with
|
|
16
|
+
* the declaration and the function of each check, each time. The checks must pass at rest. The
|
|
17
|
+
* cases are:
|
|
18
|
+
* - The service at rest: each controller and each dependency is ready, and the service is alive.
|
|
19
|
+
* - Each dependency unavailable: its polls fail at once (the force-fail list). The dependency and
|
|
20
|
+
* each controller that needs it become not ready, and the other controllers stay ready. Liveness
|
|
21
|
+
* stays, unless a liveness check exercises the dependency.
|
|
22
|
+
* - Each dependency degraded: each call of its checks takes the latency longer. Nothing can fail.
|
|
23
|
+
* - Each dependency recovers: after it is unavailable, the service is again at rest.
|
|
24
|
+
* - A negative control: a client that the declaration does not name fails, and nothing changes.
|
|
25
|
+
*
|
|
26
|
+
* A dependency that no check exercises is a finding: the service cannot see it fail.
|
|
27
|
+
*/
|
|
28
|
+
export declare const contractCases: (declare: () => ServiceBuilder, options?: ContractOptions) => ContractCase[];
|