@air-jam/devtools 0.9.3 → 1.0.0-beta.10
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 +60 -0
- package/dist/{chunk-VKMJO6VN.js → chunk-2O67AXCU.js} +150 -40
- package/dist/chunk-2O67AXCU.js.map +1 -0
- package/dist/chunk-AO3ZDXF6.js +142 -0
- package/dist/chunk-AO3ZDXF6.js.map +1 -0
- package/dist/chunk-ART5TEYT.js +472 -0
- package/dist/chunk-ART5TEYT.js.map +1 -0
- package/dist/chunk-ASC2CK2R.js +77 -0
- package/dist/chunk-ASC2CK2R.js.map +1 -0
- package/dist/chunk-E3UZZGAV.js +50 -0
- package/dist/chunk-E3UZZGAV.js.map +1 -0
- package/dist/chunk-EJTE7UKX.js +64 -0
- package/dist/chunk-EJTE7UKX.js.map +1 -0
- package/dist/chunk-ESFKNN75.js +110 -0
- package/dist/chunk-ESFKNN75.js.map +1 -0
- package/dist/chunk-EU7A6PXW.js +1339 -0
- package/dist/chunk-EU7A6PXW.js.map +1 -0
- package/dist/chunk-FN7E6EA7.js +549 -0
- package/dist/chunk-FN7E6EA7.js.map +1 -0
- package/dist/chunk-GDFAWHGA.js +190 -0
- package/dist/chunk-GDFAWHGA.js.map +1 -0
- package/dist/chunk-HZUGBH4Y.js +347 -0
- package/dist/chunk-HZUGBH4Y.js.map +1 -0
- package/dist/chunk-ITKAOEGX.js +93 -0
- package/dist/chunk-ITKAOEGX.js.map +1 -0
- package/dist/chunk-JBCUTWRI.js +897 -0
- package/dist/chunk-JBCUTWRI.js.map +1 -0
- package/dist/chunk-JSI5S4WP.js +1174 -0
- package/dist/chunk-JSI5S4WP.js.map +1 -0
- package/dist/chunk-L4D675BG.js +97 -0
- package/dist/chunk-L4D675BG.js.map +1 -0
- package/dist/{chunk-GUEZP773.js → chunk-LB3Y64P5.js} +206 -60
- package/dist/chunk-LB3Y64P5.js.map +1 -0
- package/dist/chunk-M6CJ7GQC.js +133 -0
- package/dist/chunk-M6CJ7GQC.js.map +1 -0
- package/dist/{chunk-CKFT2ZJE.js → chunk-MEIMOSZC.js} +53 -105
- package/dist/chunk-MEIMOSZC.js.map +1 -0
- package/dist/chunk-OM6SCJ7H.js +18 -0
- package/dist/chunk-OM6SCJ7H.js.map +1 -0
- package/dist/chunk-PKD4WVX5.js +63 -0
- package/dist/chunk-PKD4WVX5.js.map +1 -0
- package/dist/chunk-PMBLXGFM.js +3384 -0
- package/dist/chunk-PMBLXGFM.js.map +1 -0
- package/dist/chunk-PMNE5GIN.js +279 -0
- package/dist/chunk-PMNE5GIN.js.map +1 -0
- package/dist/chunk-QAWI64VR.js +148 -0
- package/dist/chunk-QAWI64VR.js.map +1 -0
- package/dist/chunk-QGADSPHZ.js +449 -0
- package/dist/chunk-QGADSPHZ.js.map +1 -0
- package/dist/chunk-SPYN66UV.js +338 -0
- package/dist/chunk-SPYN66UV.js.map +1 -0
- package/dist/context.d.ts +9 -3
- package/dist/context.js +2 -1
- package/dist/controller.d.ts +33 -7
- package/dist/controller.js +18 -8
- package/dist/dependencies.d.ts +44 -0
- package/dist/dependencies.js +10 -0
- package/dist/dev.d.ts +9 -3
- package/dist/dev.js +3 -4
- package/dist/game-builds.d.ts +200 -0
- package/dist/game-builds.js +16 -0
- package/dist/game-builds.js.map +1 -0
- package/dist/game-run-watch-CEd_SpAT.d.ts +84 -0
- package/dist/game-runs.d.ts +1452 -0
- package/dist/game-runs.js +76 -0
- package/dist/game-runs.js.map +1 -0
- package/dist/game-session-broker-CUvORfMd.d.ts +439 -0
- package/dist/game-session-broker.d.ts +4 -57
- package/dist/game-session-broker.js +33 -228
- package/dist/game-session-broker.js.map +1 -1
- package/dist/game-session.d.ts +3931 -10
- package/dist/game-session.js +186 -15
- package/dist/game-session.js.map +1 -1
- package/dist/game-settings.d.ts +16 -0
- package/dist/game-settings.js +237 -0
- package/dist/game-settings.js.map +1 -0
- package/dist/games.d.ts +11 -4
- package/dist/games.js +4 -2
- package/dist/harness/visual.d.ts +34 -151
- package/dist/harness/visual.js +6 -1
- package/dist/logs.d.ts +8 -2
- package/dist/logs.js +3 -4
- package/dist/logs.js.map +1 -1
- package/dist/managed-process-scope-BicYi_t9.d.ts +3 -0
- package/dist/mcp-config.js +2 -1
- package/dist/mcp-config.js.map +1 -1
- package/dist/platform-auth.d.ts +8 -111
- package/dist/platform-auth.js +9 -1
- package/dist/platform-game-analytics.d.ts +51 -0
- package/dist/platform-game-analytics.js +49 -0
- package/dist/platform-game-analytics.js.map +1 -0
- package/dist/platform-game-app-id.d.ts +46 -0
- package/dist/platform-game-app-id.js +93 -0
- package/dist/platform-game-app-id.js.map +1 -0
- package/dist/platform-game-media.d.ts +40 -2
- package/dist/platform-game-media.js +1 -1
- package/dist/platform-games.d.ts +24 -2
- package/dist/platform-games.js +16 -84
- package/dist/platform-games.js.map +1 -1
- package/dist/quality.d.ts +9 -3
- package/dist/quality.js +3 -4
- package/dist/quality.js.map +1 -1
- package/dist/release.d.ts +226 -16
- package/dist/release.js +18 -1331
- package/dist/release.js.map +1 -1
- package/dist/rooms-check.d.ts +90 -0
- package/dist/rooms-check.js +717 -0
- package/dist/rooms-check.js.map +1 -0
- package/dist/source-tree-contract.d.ts +16 -0
- package/dist/source-tree-contract.js +13 -0
- package/dist/source-tree-contract.js.map +1 -0
- package/dist/testing.d.ts +464 -0
- package/dist/testing.js +27 -0
- package/dist/testing.js.map +1 -0
- package/dist/tooling/describe-game.js +54 -0
- package/dist/tooling/describe-game.js.map +1 -0
- package/dist/tooling/game-session-broker.js +28 -0
- package/dist/tooling/game-session-broker.js.map +1 -0
- package/dist/tooling/hold-runtime-host.js +770 -68
- package/dist/tooling/hold-runtime-host.js.map +1 -1
- package/dist/tooling/list-visual-scenarios.js +18 -55
- package/dist/tooling/list-visual-scenarios.js.map +1 -1
- package/dist/tooling/process-scope-bootstrap.mjs +24 -0
- package/dist/tooling/process-scope-guard.d.ts +2 -0
- package/dist/tooling/process-scope-guard.js +388 -0
- package/dist/tooling/process-scope-guard.js.map +1 -0
- package/dist/tooling/process-scope-windows.ps1 +148 -0
- package/dist/tooling/rooms-check-device.d.ts +2 -0
- package/dist/tooling/rooms-check-device.js +498 -0
- package/dist/tooling/rooms-check-device.js.map +1 -0
- package/dist/tooling/run-headless-room.d.ts +2 -0
- package/dist/tooling/run-headless-room.js +288 -0
- package/dist/tooling/run-headless-room.js.map +1 -0
- package/dist/tooling/run-test-profile.d.ts +2 -0
- package/dist/tooling/run-test-profile.js +181 -0
- package/dist/tooling/run-test-profile.js.map +1 -0
- package/dist/tooling/run-visual-capture.js +70 -34
- package/dist/tooling/run-visual-capture.js.map +1 -1
- package/dist/tooling/seal-game-build.d.ts +2 -0
- package/dist/tooling/seal-game-build.js +120 -0
- package/dist/tooling/seal-game-build.js.map +1 -0
- package/dist/{types-C6NrHt88.d.ts → types-CdYrgrG_.d.ts} +337 -76
- package/dist/types-DyRD-ym1.d.ts +141 -0
- package/dist/visual.d.ts +9 -3
- package/dist/visual.js +24 -68
- package/dist/visual.js.map +1 -1
- package/package.json +51 -14
- package/src/bounded-response.ts +28 -0
- package/src/built-game-runtime.ts +152 -0
- package/src/context.ts +2 -13
- package/src/controller-protocol.ts +22 -0
- package/src/controller.ts +747 -597
- package/src/current-room-host.ts +166 -0
- package/src/decision-provider.ts +102 -0
- package/src/dependencies.ts +176 -0
- package/src/dependency-install-contract.ts +12 -0
- package/src/dev.ts +46 -50
- package/src/game-action-observation.ts +11 -1
- package/src/game-build-protocol.ts +72 -0
- package/src/game-build.ts +483 -0
- package/src/game-run-owner.ts +2358 -0
- package/src/game-run-protocol.ts +448 -0
- package/src/game-run-record.ts +92 -0
- package/src/game-run-replay.ts +95 -0
- package/src/game-run-watch.ts +155 -0
- package/src/game-session-broker.ts +689 -197
- package/src/game-session-operations.ts +61 -0
- package/src/game-session-protocol.ts +180 -0
- package/src/game-session-runtime.ts +861 -0
- package/src/game-session.ts +164 -417
- package/src/game-settings.ts +295 -0
- package/src/games.ts +88 -92
- package/src/harness/visual/browser.ts +100 -0
- package/src/harness/visual/controller-observation.ts +181 -0
- package/src/harness/visual/runner.ts +24 -21
- package/src/harness/visual/runtime-controller-observations.ts +151 -0
- package/src/harness/visual/scenario-contract.ts +1 -2
- package/src/harness/visual/scenario-helpers.ts +5 -1
- package/src/harness/visual/screencast.ts +155 -0
- package/src/harness/visual/session.ts +74 -69
- package/src/harness/visual/types.ts +8 -5
- package/src/headless-room-protocol.ts +112 -0
- package/src/headless-room.ts +222 -0
- package/src/helper-channel.ts +229 -0
- package/src/helper-scripts.ts +25 -5
- package/src/installed-dependencies.ts +74 -0
- package/src/managed-process-scope.ts +481 -0
- package/src/node-process-environment.ts +10 -0
- package/src/platform-auth.ts +194 -55
- package/src/platform-game-analytics.ts +50 -0
- package/src/platform-game-app-id.ts +99 -0
- package/src/platform-games.ts +13 -111
- package/src/policy-artifact-contract.ts +52 -0
- package/src/policy-artifacts.ts +134 -0
- package/src/process-scope-admission.ts +50 -0
- package/src/process-scope-protocol.ts +66 -0
- package/src/process-scope.ts +327 -0
- package/src/release.ts +28 -42
- package/src/rooms-check-fleet.ts +194 -0
- package/src/rooms-check-link.ts +138 -0
- package/src/rooms-check-protocol.ts +244 -0
- package/src/rooms-check.ts +797 -0
- package/src/runtime-owner-protocol.ts +106 -18
- package/src/source-tree-contract.ts +70 -0
- package/src/source-tree.ts +84 -0
- package/src/test-profile-process.ts +153 -0
- package/src/test-profile-protocol.ts +116 -0
- package/src/testing.ts +430 -0
- package/src/tooling/declaration-hook.ts +52 -0
- package/src/tooling/describe-game.ts +49 -0
- package/src/tooling/game-session-broker.ts +7 -0
- package/src/tooling/hold-runtime-host.ts +254 -42
- package/src/tooling/list-visual-scenarios.ts +19 -62
- package/src/tooling/load-game.ts +79 -0
- package/src/tooling/process-scope-bootstrap.mjs +24 -0
- package/src/tooling/process-scope-guard.ts +213 -0
- package/src/tooling/process-scope-windows.ps1 +148 -0
- package/src/tooling/rooms-check-device.ts +493 -0
- package/src/tooling/run-headless-room.ts +329 -0
- package/src/tooling/run-test-profile.ts +190 -0
- package/src/tooling/run-visual-capture.ts +37 -23
- package/src/tooling/runtime-owner-actions.ts +23 -0
- package/src/tooling/seal-game-build.ts +118 -0
- package/src/tooling/visual-pack.ts +10 -45
- package/src/types.ts +54 -77
- package/src/visual.ts +14 -22
- package/src/windows-process-scopes.ts +189 -0
- package/dist/agent.d.ts +0 -15
- package/dist/agent.js +0 -19
- package/dist/chunk-5YAARMW5.js +0 -36
- package/dist/chunk-5YAARMW5.js.map +0 -1
- package/dist/chunk-6WQODT37.js +0 -1019
- package/dist/chunk-6WQODT37.js.map +0 -1
- package/dist/chunk-CKFT2ZJE.js.map +0 -1
- package/dist/chunk-ER3Q2C4G.js +0 -358
- package/dist/chunk-ER3Q2C4G.js.map +0 -1
- package/dist/chunk-GUEZP773.js.map +0 -1
- package/dist/chunk-HIDNI56E.js +0 -33
- package/dist/chunk-HIDNI56E.js.map +0 -1
- package/dist/chunk-QKXS5D35.js +0 -43
- package/dist/chunk-QKXS5D35.js.map +0 -1
- package/dist/chunk-S4LSCEVE.js +0 -261
- package/dist/chunk-S4LSCEVE.js.map +0 -1
- package/dist/chunk-VKMJO6VN.js.map +0 -1
- package/dist/chunk-WFUR3MXY.js +0 -67
- package/dist/chunk-WFUR3MXY.js.map +0 -1
- package/dist/chunk-XEMR7KUE.js +0 -361
- package/dist/chunk-XEMR7KUE.js.map +0 -1
- package/dist/chunk-ZLPD7FY5.js +0 -191
- package/dist/chunk-ZLPD7FY5.js.map +0 -1
- package/dist/tooling/agent-contract.js +0 -193
- package/dist/tooling/agent-contract.js.map +0 -1
- package/dist/tooling/inspect-airjam-agent.js +0 -37
- package/dist/tooling/inspect-airjam-agent.js.map +0 -1
- package/src/agent.ts +0 -380
- package/src/tooling/agent-contract.ts +0 -232
- package/src/tooling/agent-declaration.ts +0 -36
- package/src/tooling/airjam-agent-inspection.ts +0 -45
- package/src/tooling/airjam-agent.ts +0 -118
- package/src/tooling/inspect-airjam-agent.ts +0 -20
- /package/dist/{agent.js.map → dependencies.js.map} +0 -0
- /package/dist/tooling/{agent-contract.d.ts → describe-game.d.ts} +0 -0
- /package/dist/tooling/{inspect-airjam-agent.d.ts → game-session-broker.d.ts} +0 -0
|
@@ -0,0 +1,797 @@
|
|
|
1
|
+
import { createRoomKey } from "@air-jam/sdk/room-session";
|
|
2
|
+
import { availableParallelism } from "node:os";
|
|
3
|
+
import {
|
|
4
|
+
ConnectionPacer,
|
|
5
|
+
Device,
|
|
6
|
+
Fleet,
|
|
7
|
+
isOpen,
|
|
8
|
+
ScenarioFailure,
|
|
9
|
+
} from "./rooms-check-fleet.js";
|
|
10
|
+
import {
|
|
11
|
+
DEFAULT_ROOMS_CHECK_SCENARIOS,
|
|
12
|
+
sharedNow,
|
|
13
|
+
summarizeLatency,
|
|
14
|
+
type LoadResult,
|
|
15
|
+
type RoomsCheckReport,
|
|
16
|
+
type RoomsCheckScenario,
|
|
17
|
+
type RoomsCheckScenarioResult,
|
|
18
|
+
} from "./rooms-check-protocol.js";
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
DEFAULT_ROOMS_CHECK_SCENARIOS,
|
|
22
|
+
describeLinkProblem,
|
|
23
|
+
ROOMS_CHECK_SCENARIOS,
|
|
24
|
+
type ConnectionProblem,
|
|
25
|
+
type LatencySummary,
|
|
26
|
+
type LinkProblem,
|
|
27
|
+
type RoomsCheckReport,
|
|
28
|
+
type RoomsCheckScenario,
|
|
29
|
+
type RoomsCheckScenarioResult,
|
|
30
|
+
} from "./rooms-check-protocol.js";
|
|
31
|
+
|
|
32
|
+
export interface RoomsCheckLoadOptions {
|
|
33
|
+
readonly rooms?: number;
|
|
34
|
+
readonly phonesPerRoom?: number;
|
|
35
|
+
readonly durationMs?: number;
|
|
36
|
+
/** Processes the rooms are spread over; each runs whole rooms on one clock. */
|
|
37
|
+
readonly workers?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface RoomsCheckOptions {
|
|
41
|
+
/** The rooms origin, such as `wss://rooms.example.com` or `http://localhost:4000`. */
|
|
42
|
+
readonly url: string;
|
|
43
|
+
/** The page origin every connection names in its Origin header, for a gate that checks it. */
|
|
44
|
+
readonly origin?: string;
|
|
45
|
+
/**
|
|
46
|
+
* A shell command printing one host credential, run for every host that
|
|
47
|
+
* opens a room, since a hosted grant is spent once; a host resuming its
|
|
48
|
+
* room runs none.
|
|
49
|
+
*/
|
|
50
|
+
readonly hostCredentialCommand?: string;
|
|
51
|
+
/** At most this many connection opens in any minute, across every device; unpaced when omitted. */
|
|
52
|
+
readonly connectionsPerMinute?: number;
|
|
53
|
+
readonly scenarios?: readonly RoomsCheckScenario[];
|
|
54
|
+
/** A lock shorter than any server's liveness window, which must not cost the seat. */
|
|
55
|
+
readonly briefFreezeMs?: number;
|
|
56
|
+
/** How long a phone's network stalls while its player keeps pressing. */
|
|
57
|
+
readonly stallMs?: number;
|
|
58
|
+
/** How long the background-host room sits idle. */
|
|
59
|
+
readonly idleMs?: number;
|
|
60
|
+
readonly crowdDurationMs?: number;
|
|
61
|
+
readonly load?: RoomsCheckLoadOptions;
|
|
62
|
+
readonly onResult?: (result: RoomsCheckScenarioResult) => void;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const PRESS_COUNTER_SIZE = 128;
|
|
66
|
+
const OPEN_DEADLINE_MS = 15_000;
|
|
67
|
+
/** Long enough for any connection to get its grant, however slowly the check paces opens. */
|
|
68
|
+
const GRANT_DEADLINE_MS = 30 * 60_000;
|
|
69
|
+
/** Bytes of TLS, WebSocket and TCP/IP framing around each message, as the hosting plan measured. */
|
|
70
|
+
const WIRE_FRAMING_BYTES = 78;
|
|
71
|
+
const HOUR_MS = 3_600_000;
|
|
72
|
+
|
|
73
|
+
interface Phone {
|
|
74
|
+
readonly device: Device;
|
|
75
|
+
readonly key: string;
|
|
76
|
+
readonly seat: string;
|
|
77
|
+
readonly instance: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface OpenRoom {
|
|
81
|
+
readonly host: Device;
|
|
82
|
+
readonly hostKey: string;
|
|
83
|
+
readonly code: string;
|
|
84
|
+
readonly instance: string;
|
|
85
|
+
readonly hostGraceMs: number;
|
|
86
|
+
readonly openMs: number;
|
|
87
|
+
readonly phones: Phone[];
|
|
88
|
+
readonly joinMs: number[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** When the device's first connection began opening, after its process started and its grant came. */
|
|
92
|
+
const dialed = (device: Device) =>
|
|
93
|
+
device.until(
|
|
94
|
+
(event) => (event.type === "dialing" ? event.at : undefined),
|
|
95
|
+
"dialing",
|
|
96
|
+
GRANT_DEADLINE_MS,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
/** The device's first open status, counted from when it dialed; a session the room ends for good fails it at once. */
|
|
100
|
+
const firstOpen = async (device: Device, what: string) => {
|
|
101
|
+
const dialedAt = await dialed(device);
|
|
102
|
+
const outcome = await device.until(
|
|
103
|
+
(event) =>
|
|
104
|
+
event.type === "status" &&
|
|
105
|
+
(event.status.phase === "open" || event.status.phase === "closed")
|
|
106
|
+
? event
|
|
107
|
+
: undefined,
|
|
108
|
+
what,
|
|
109
|
+
OPEN_DEADLINE_MS,
|
|
110
|
+
);
|
|
111
|
+
if (outcome.status.phase === "closed")
|
|
112
|
+
throw new ScenarioFailure(
|
|
113
|
+
`${device.name}: ${what} ended with the room closing it as ${outcome.status.reason}.`,
|
|
114
|
+
);
|
|
115
|
+
return { opened: outcome, openMs: outcome.at - dialedAt };
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const field = <Value>(value: Value | undefined, what: string): Value => {
|
|
119
|
+
if (value === undefined)
|
|
120
|
+
throw new ScenarioFailure(`The room did not report its ${what}.`);
|
|
121
|
+
return value;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const joinPhone = async (
|
|
125
|
+
fleet: Fleet,
|
|
126
|
+
name: string,
|
|
127
|
+
room: { code: string },
|
|
128
|
+
options: { key?: string; instance?: string; inputsPerSecond: number },
|
|
129
|
+
): Promise<Phone & { joinMs: number }> => {
|
|
130
|
+
const device = fleet.device(name);
|
|
131
|
+
const key = options.key ?? createRoomKey();
|
|
132
|
+
device.send({
|
|
133
|
+
type: "phone",
|
|
134
|
+
link: fleet.link,
|
|
135
|
+
key,
|
|
136
|
+
code: room.code,
|
|
137
|
+
instance: options.instance,
|
|
138
|
+
inputsPerSecond: options.inputsPerSecond,
|
|
139
|
+
});
|
|
140
|
+
const { opened, openMs } = await firstOpen(device, "joining");
|
|
141
|
+
return {
|
|
142
|
+
device,
|
|
143
|
+
key,
|
|
144
|
+
seat: field(opened.seat, "seat"),
|
|
145
|
+
instance: field(opened.instance, "instance"),
|
|
146
|
+
joinMs: openMs,
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const openRoom = async (
|
|
151
|
+
fleet: Fleet,
|
|
152
|
+
options: {
|
|
153
|
+
phones: number;
|
|
154
|
+
inputsPerSecond?: number;
|
|
155
|
+
statesPerSecond?: number;
|
|
156
|
+
hostHeartbeat?: boolean;
|
|
157
|
+
},
|
|
158
|
+
): Promise<OpenRoom> => {
|
|
159
|
+
const host = fleet.device("host");
|
|
160
|
+
const hostKey = createRoomKey();
|
|
161
|
+
host.send({
|
|
162
|
+
type: "host",
|
|
163
|
+
link: fleet.link,
|
|
164
|
+
credentialCommand: fleet.hostCredentialCommand,
|
|
165
|
+
key: hostKey,
|
|
166
|
+
seats: Math.max(options.phones, 2),
|
|
167
|
+
statesPerSecond: options.statesPerSecond ?? 0,
|
|
168
|
+
heartbeat: options.hostHeartbeat ?? true,
|
|
169
|
+
});
|
|
170
|
+
const { opened, openMs } = await firstOpen(host, "opening the room");
|
|
171
|
+
const code = field(opened.code, "code");
|
|
172
|
+
const joined = await Promise.all(
|
|
173
|
+
Array.from({ length: options.phones }, (_, index) =>
|
|
174
|
+
joinPhone(
|
|
175
|
+
fleet,
|
|
176
|
+
`phone ${index + 1}`,
|
|
177
|
+
{ code },
|
|
178
|
+
{
|
|
179
|
+
inputsPerSecond: options.inputsPerSecond ?? 30,
|
|
180
|
+
},
|
|
181
|
+
),
|
|
182
|
+
),
|
|
183
|
+
);
|
|
184
|
+
return {
|
|
185
|
+
host,
|
|
186
|
+
hostKey,
|
|
187
|
+
code,
|
|
188
|
+
instance: field(opened.instance, "instance"),
|
|
189
|
+
hostGraceMs: field(opened.hostGraceMs, "host grace"),
|
|
190
|
+
openMs,
|
|
191
|
+
phones: joined,
|
|
192
|
+
joinMs: joined.map((phone) => phone.joinMs),
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const wait = (milliseconds: number) =>
|
|
197
|
+
new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
198
|
+
|
|
199
|
+
const sameCount = (left: number, right: number) =>
|
|
200
|
+
left % PRESS_COUNTER_SIZE === right % PRESS_COUNTER_SIZE;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Tap-to-host times for presses made between `from` and `to`. A host counts
|
|
204
|
+
* presses from the first state it saw, so counts are matched within the
|
|
205
|
+
* counter's wrap; a press is lost when no host saw it within a second.
|
|
206
|
+
*/
|
|
207
|
+
const measureInput = (
|
|
208
|
+
host: Device,
|
|
209
|
+
phones: readonly Phone[],
|
|
210
|
+
from: number,
|
|
211
|
+
to: number,
|
|
212
|
+
) => {
|
|
213
|
+
const latencies: number[] = [];
|
|
214
|
+
let pressed = 0;
|
|
215
|
+
let lost = 0;
|
|
216
|
+
for (const phone of phones) {
|
|
217
|
+
const received = host
|
|
218
|
+
.since("received", from)
|
|
219
|
+
.filter((event) => event.seat === phone.seat);
|
|
220
|
+
for (const press of phone.device.since("pressed", from, to)) {
|
|
221
|
+
pressed += 1;
|
|
222
|
+
const arrival = received.find(
|
|
223
|
+
(event) =>
|
|
224
|
+
event.at >= press.at &&
|
|
225
|
+
event.at - press.at < 1_000 &&
|
|
226
|
+
sameCount(event.presses, press.presses),
|
|
227
|
+
);
|
|
228
|
+
if (arrival) latencies.push(arrival.at - press.at);
|
|
229
|
+
else lost += 1;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return { pressed, lost, latency: summarizeLatency(latencies) };
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const measureState = (host: Device, phones: readonly Phone[], from: number) => {
|
|
236
|
+
const published = new Map(
|
|
237
|
+
host.since("published", from).map((event) => [event.tick, event.at]),
|
|
238
|
+
);
|
|
239
|
+
return summarizeLatency(
|
|
240
|
+
phones.flatMap((phone) =>
|
|
241
|
+
phone.device.since("state", from).flatMap((event) => {
|
|
242
|
+
const at = published.get(event.tick);
|
|
243
|
+
return at === undefined ? [] : [event.at - at];
|
|
244
|
+
}),
|
|
245
|
+
),
|
|
246
|
+
);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Fails unless every phone saw the match facts of the last tick the host
|
|
251
|
+
* published before `to`, as each player's screen must.
|
|
252
|
+
*/
|
|
253
|
+
const requireState = (
|
|
254
|
+
host: Device,
|
|
255
|
+
phones: readonly Phone[],
|
|
256
|
+
from: number,
|
|
257
|
+
to: number,
|
|
258
|
+
) => {
|
|
259
|
+
const settled = host
|
|
260
|
+
.since("published", from)
|
|
261
|
+
.filter((event) => event.at <= to)
|
|
262
|
+
.at(-1);
|
|
263
|
+
if (!settled) throw new ScenarioFailure("The host published no state.");
|
|
264
|
+
const behind = phones.filter(
|
|
265
|
+
(phone) =>
|
|
266
|
+
!phone.device
|
|
267
|
+
.since("state", from)
|
|
268
|
+
.some((event) => event.tick >= settled.tick),
|
|
269
|
+
).length;
|
|
270
|
+
if (behind > 0)
|
|
271
|
+
throw new ScenarioFailure(
|
|
272
|
+
`${behind} of ${phones.length} phones never saw the host's state.`,
|
|
273
|
+
);
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const firstInputAfter = (host: Device, seat: string | null, after: number) =>
|
|
277
|
+
host.until(
|
|
278
|
+
(event) =>
|
|
279
|
+
event.type === "received" && (seat === null || event.seat === seat)
|
|
280
|
+
? event.at
|
|
281
|
+
: undefined,
|
|
282
|
+
"an input arriving",
|
|
283
|
+
OPEN_DEADLINE_MS,
|
|
284
|
+
after,
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
const seatDropped = (host: Device, seat: string, from: number) =>
|
|
288
|
+
host
|
|
289
|
+
.since("seats", from)
|
|
290
|
+
.some((event) =>
|
|
291
|
+
event.seats.some((view) => view.id === seat && !view.connected),
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
type ScenarioContext = {
|
|
295
|
+
readonly fleet: Fleet;
|
|
296
|
+
readonly options: Required<
|
|
297
|
+
Pick<
|
|
298
|
+
RoomsCheckOptions,
|
|
299
|
+
"briefFreezeMs" | "stallMs" | "idleMs" | "crowdDurationMs"
|
|
300
|
+
>
|
|
301
|
+
> & {
|
|
302
|
+
readonly load: Required<RoomsCheckLoadOptions>;
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
type Scenario = (context: ScenarioContext) => Promise<Record<string, unknown>>;
|
|
307
|
+
|
|
308
|
+
const scenarios: Record<RoomsCheckScenario, Scenario> = {
|
|
309
|
+
/** The smallest room: a host and one phone, input one way and state the other. */
|
|
310
|
+
join: async ({ fleet }) => {
|
|
311
|
+
const room = await openRoom(fleet, { phones: 1, statesPerSecond: 20 });
|
|
312
|
+
const from = sharedNow();
|
|
313
|
+
await wait(2_000);
|
|
314
|
+
const to = sharedNow() - 500;
|
|
315
|
+
const input = measureInput(room.host, room.phones, from, to);
|
|
316
|
+
if (input.pressed === 0 || input.lost > 0)
|
|
317
|
+
throw new ScenarioFailure(
|
|
318
|
+
`${input.lost} of ${input.pressed} presses never reached the host.`,
|
|
319
|
+
);
|
|
320
|
+
requireState(room.host, room.phones, from, to);
|
|
321
|
+
return {
|
|
322
|
+
roomOpenMs: room.openMs,
|
|
323
|
+
phoneJoinMs: room.joinMs[0],
|
|
324
|
+
input: input.latency,
|
|
325
|
+
state: measureState(room.host, room.phones, from),
|
|
326
|
+
};
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
/** A phone locked for a moment keeps its seat and its link. */
|
|
330
|
+
"phone-brief-freeze": async ({ fleet, options }) => {
|
|
331
|
+
const room = await openRoom(fleet, { phones: 1 });
|
|
332
|
+
const [phone] = room.phones;
|
|
333
|
+
if (!phone) throw new ScenarioFailure("No phone joined.");
|
|
334
|
+
const frozenAt = sharedNow();
|
|
335
|
+
phone.device.freeze();
|
|
336
|
+
await wait(options.briefFreezeMs);
|
|
337
|
+
const thawedAt = sharedNow();
|
|
338
|
+
phone.device.thaw();
|
|
339
|
+
const arrived = await firstInputAfter(room.host, phone.seat, thawedAt);
|
|
340
|
+
if (seatDropped(room.host, phone.seat, frozenAt))
|
|
341
|
+
throw new ScenarioFailure(
|
|
342
|
+
`The host saw the seat drop during a ${options.briefFreezeMs} ms lock.`,
|
|
343
|
+
);
|
|
344
|
+
return {
|
|
345
|
+
freezeMs: options.briefFreezeMs,
|
|
346
|
+
thawToInputMs: arrived - thawedAt,
|
|
347
|
+
};
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
/** A phone locked past the server's liveness window gets its seat back on waking. */
|
|
351
|
+
"phone-long-freeze": async ({ fleet }) => {
|
|
352
|
+
const room = await openRoom(fleet, { phones: 1 });
|
|
353
|
+
const [phone] = room.phones;
|
|
354
|
+
if (!phone) throw new ScenarioFailure("No phone joined.");
|
|
355
|
+
const frozenAt = sharedNow();
|
|
356
|
+
phone.device.freeze();
|
|
357
|
+
const droppedAt = await room.host.until(
|
|
358
|
+
(event) =>
|
|
359
|
+
event.type === "seats" &&
|
|
360
|
+
event.seats.some((view) => view.id === phone.seat && !view.connected)
|
|
361
|
+
? event.at
|
|
362
|
+
: undefined,
|
|
363
|
+
"the server noticing the silent phone",
|
|
364
|
+
120_000,
|
|
365
|
+
frozenAt,
|
|
366
|
+
);
|
|
367
|
+
const thawedAt = sharedNow();
|
|
368
|
+
phone.device.thaw();
|
|
369
|
+
const reopened = await phone.device.until(
|
|
370
|
+
(event) => (isOpen(event) ? event : undefined),
|
|
371
|
+
"rejoining",
|
|
372
|
+
OPEN_DEADLINE_MS,
|
|
373
|
+
thawedAt,
|
|
374
|
+
);
|
|
375
|
+
if (reopened.seat !== phone.seat)
|
|
376
|
+
throw new ScenarioFailure(
|
|
377
|
+
`The phone came back as ${reopened.seat}, not ${phone.seat}.`,
|
|
378
|
+
);
|
|
379
|
+
const arrived = await firstInputAfter(room.host, phone.seat, thawedAt);
|
|
380
|
+
return {
|
|
381
|
+
silenceNoticedMs: droppedAt - frozenAt,
|
|
382
|
+
thawToRejoinMs: reopened.at - thawedAt,
|
|
383
|
+
thawToInputMs: arrived - thawedAt,
|
|
384
|
+
};
|
|
385
|
+
},
|
|
386
|
+
|
|
387
|
+
/** Wi-Fi to cellular: a new link with the key takes the seat at once; the dead one stays out. */
|
|
388
|
+
"network-switch": async ({ fleet }) => {
|
|
389
|
+
const room = await openRoom(fleet, { phones: 1 });
|
|
390
|
+
const [wifi] = room.phones;
|
|
391
|
+
if (!wifi) throw new ScenarioFailure("No phone joined.");
|
|
392
|
+
wifi.device.freeze();
|
|
393
|
+
const cellular = await joinPhone(fleet, "phone on cellular", room, {
|
|
394
|
+
key: wifi.key,
|
|
395
|
+
instance: wifi.instance,
|
|
396
|
+
inputsPerSecond: 30,
|
|
397
|
+
});
|
|
398
|
+
if (cellular.seat !== wifi.seat)
|
|
399
|
+
throw new ScenarioFailure(
|
|
400
|
+
`The new link took ${cellular.seat}, not ${wifi.seat}.`,
|
|
401
|
+
);
|
|
402
|
+
const takenAt = sharedNow();
|
|
403
|
+
wifi.device.thaw();
|
|
404
|
+
await wifi.device.until(
|
|
405
|
+
(event) =>
|
|
406
|
+
event.type === "status" &&
|
|
407
|
+
event.status.phase === "closed" &&
|
|
408
|
+
event.status.reason === "replaced"
|
|
409
|
+
? true
|
|
410
|
+
: undefined,
|
|
411
|
+
"the old link stopping as replaced",
|
|
412
|
+
OPEN_DEADLINE_MS,
|
|
413
|
+
takenAt,
|
|
414
|
+
);
|
|
415
|
+
await wait(2_000);
|
|
416
|
+
if (seatDropped(room.host, wifi.seat, takenAt))
|
|
417
|
+
throw new ScenarioFailure("The seat changed hands back and forth.");
|
|
418
|
+
await firstInputAfter(room.host, wifi.seat, sharedNow() - 1_000);
|
|
419
|
+
return { takeoverMs: cellular.joinMs };
|
|
420
|
+
},
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* A phone's network stalls while its player keeps pressing; when it
|
|
424
|
+
* returns, the backlog arrives in one burst. The phone keeps its link and
|
|
425
|
+
* seat, and its input flows again.
|
|
426
|
+
*/
|
|
427
|
+
"network-stall": async ({ fleet, options }) => {
|
|
428
|
+
const room = await openRoom(fleet, { phones: 1, inputsPerSecond: 60 });
|
|
429
|
+
const [phone] = room.phones;
|
|
430
|
+
if (!phone) throw new ScenarioFailure("No phone joined.");
|
|
431
|
+
const stalledAt = sharedNow();
|
|
432
|
+
phone.device.send({ type: "network", stalled: true });
|
|
433
|
+
await wait(options.stallMs);
|
|
434
|
+
const resumedAt = sharedNow();
|
|
435
|
+
phone.device.send({ type: "network", stalled: false });
|
|
436
|
+
const arrived = await firstInputAfter(room.host, phone.seat, resumedAt);
|
|
437
|
+
await wait(3_000);
|
|
438
|
+
const lostLink = phone.device
|
|
439
|
+
.since("status", stalledAt)
|
|
440
|
+
.find((event) => event.status.phase !== "open");
|
|
441
|
+
if (lostLink)
|
|
442
|
+
throw new ScenarioFailure(
|
|
443
|
+
`The phone went ${lostLink.status.phase}${lostLink.status.reason ? ` (${lostLink.status.reason})` : ""} after a ${options.stallMs} ms stall.`,
|
|
444
|
+
);
|
|
445
|
+
if (seatDropped(room.host, phone.seat, stalledAt))
|
|
446
|
+
throw new ScenarioFailure("The host saw the seat drop during the stall.");
|
|
447
|
+
const input = measureInput(
|
|
448
|
+
room.host,
|
|
449
|
+
[phone],
|
|
450
|
+
resumedAt + 1_500,
|
|
451
|
+
sharedNow() - 500,
|
|
452
|
+
);
|
|
453
|
+
if (input.pressed === 0 || input.lost > 0)
|
|
454
|
+
throw new ScenarioFailure(
|
|
455
|
+
`${input.lost} of ${input.pressed} presses after the stall never reached the host.`,
|
|
456
|
+
);
|
|
457
|
+
return {
|
|
458
|
+
stallMs: options.stallMs,
|
|
459
|
+
resumeToInputMs: arrived - resumedAt,
|
|
460
|
+
inputAfter: input.latency,
|
|
461
|
+
};
|
|
462
|
+
},
|
|
463
|
+
|
|
464
|
+
/** Two tabs join with one key at once: one seat, and the older tab stops. */
|
|
465
|
+
"duplicate-join": async ({ fleet }) => {
|
|
466
|
+
const room = await openRoom(fleet, { phones: 0 });
|
|
467
|
+
const key = createRoomKey();
|
|
468
|
+
const tabs = ["tab 1", "tab 2"].map((name) => {
|
|
469
|
+
const device = fleet.device(name);
|
|
470
|
+
device.send({
|
|
471
|
+
type: "phone",
|
|
472
|
+
link: fleet.link,
|
|
473
|
+
key,
|
|
474
|
+
code: room.code,
|
|
475
|
+
inputsPerSecond: 0,
|
|
476
|
+
});
|
|
477
|
+
return device;
|
|
478
|
+
});
|
|
479
|
+
await Promise.all(tabs.map(dialed));
|
|
480
|
+
const outcomes = await Promise.all(
|
|
481
|
+
tabs.map((tab) =>
|
|
482
|
+
tab
|
|
483
|
+
.until(
|
|
484
|
+
(event) =>
|
|
485
|
+
event.type === "status" && event.status.phase === "closed"
|
|
486
|
+
? (event.status.reason ?? "closed")
|
|
487
|
+
: undefined,
|
|
488
|
+
"one tab replacing the other",
|
|
489
|
+
3_000,
|
|
490
|
+
)
|
|
491
|
+
.catch(() => "open"),
|
|
492
|
+
),
|
|
493
|
+
);
|
|
494
|
+
const seats = room.host.since("seats").at(-1)?.seats ?? [];
|
|
495
|
+
if (
|
|
496
|
+
outcomes.filter((outcome) => outcome === "open").length !== 1 ||
|
|
497
|
+
!outcomes.includes("replaced")
|
|
498
|
+
)
|
|
499
|
+
throw new ScenarioFailure(`The tabs ended ${outcomes.join(" and ")}.`);
|
|
500
|
+
if (seats.length !== 1 || !seats[0]?.connected)
|
|
501
|
+
throw new ScenarioFailure(`The host saw ${seats.length} seats.`);
|
|
502
|
+
return { seats: seats.length };
|
|
503
|
+
},
|
|
504
|
+
|
|
505
|
+
/** A host that reloads within its grace gets its room, seats and input back. */
|
|
506
|
+
"host-reload": async ({ fleet }) => {
|
|
507
|
+
const room = await openRoom(fleet, { phones: 2 });
|
|
508
|
+
const killedAt = sharedNow();
|
|
509
|
+
room.host.kill();
|
|
510
|
+
await Promise.all(
|
|
511
|
+
room.phones.map((phone) =>
|
|
512
|
+
phone.device.until(
|
|
513
|
+
(event) =>
|
|
514
|
+
event.type === "host" && !event.present ? true : undefined,
|
|
515
|
+
"seeing the screen go away",
|
|
516
|
+
OPEN_DEADLINE_MS,
|
|
517
|
+
killedAt,
|
|
518
|
+
),
|
|
519
|
+
),
|
|
520
|
+
);
|
|
521
|
+
const reloaded = fleet.device("reloaded host");
|
|
522
|
+
reloaded.send({
|
|
523
|
+
type: "host",
|
|
524
|
+
link: fleet.link,
|
|
525
|
+
credentialCommand: fleet.hostCredentialCommand,
|
|
526
|
+
key: room.hostKey,
|
|
527
|
+
code: room.code,
|
|
528
|
+
instance: room.instance,
|
|
529
|
+
seats: 2,
|
|
530
|
+
statesPerSecond: 0,
|
|
531
|
+
heartbeat: true,
|
|
532
|
+
});
|
|
533
|
+
const { opened } = await firstOpen(reloaded, "reclaiming the room");
|
|
534
|
+
if (opened.code !== room.code)
|
|
535
|
+
throw new ScenarioFailure(`The host came back to ${opened.code}.`);
|
|
536
|
+
const seats = await reloaded.until(
|
|
537
|
+
(event) => (event.type === "seats" ? event.seats : undefined),
|
|
538
|
+
"seeing the seats",
|
|
539
|
+
OPEN_DEADLINE_MS,
|
|
540
|
+
);
|
|
541
|
+
if (seats.length !== 2)
|
|
542
|
+
throw new ScenarioFailure(
|
|
543
|
+
`The reloaded host found ${seats.length} seats.`,
|
|
544
|
+
);
|
|
545
|
+
const arrived = await firstInputAfter(reloaded, null, opened.at);
|
|
546
|
+
return {
|
|
547
|
+
killToReclaimMs: opened.at - killedAt,
|
|
548
|
+
killToInputMs: arrived - killedAt,
|
|
549
|
+
};
|
|
550
|
+
},
|
|
551
|
+
|
|
552
|
+
/** A host gone past its grace ends the room, and its phones stop for good. */
|
|
553
|
+
"host-gone": async ({ fleet }) => {
|
|
554
|
+
const room = await openRoom(fleet, { phones: 1 });
|
|
555
|
+
const [phone] = room.phones;
|
|
556
|
+
if (!phone) throw new ScenarioFailure("No phone joined.");
|
|
557
|
+
const killedAt = sharedNow();
|
|
558
|
+
room.host.kill();
|
|
559
|
+
const closedAt = await phone.device.until(
|
|
560
|
+
(event) =>
|
|
561
|
+
event.type === "status" &&
|
|
562
|
+
event.status.phase === "closed" &&
|
|
563
|
+
event.status.reason === "closed"
|
|
564
|
+
? event.at
|
|
565
|
+
: undefined,
|
|
566
|
+
"the room closing",
|
|
567
|
+
room.hostGraceMs + OPEN_DEADLINE_MS,
|
|
568
|
+
killedAt,
|
|
569
|
+
);
|
|
570
|
+
return {
|
|
571
|
+
hostGraceMs: room.hostGraceMs,
|
|
572
|
+
killToClosedMs: closedAt - killedAt,
|
|
573
|
+
};
|
|
574
|
+
},
|
|
575
|
+
|
|
576
|
+
/** A hidden host tab sends no pings of its own; the server's keep it, idle or not. */
|
|
577
|
+
"background-host": async ({ fleet, options }) => {
|
|
578
|
+
const room = await openRoom(fleet, {
|
|
579
|
+
phones: 1,
|
|
580
|
+
inputsPerSecond: 0,
|
|
581
|
+
hostHeartbeat: false,
|
|
582
|
+
});
|
|
583
|
+
const [phone] = room.phones;
|
|
584
|
+
if (!phone) throw new ScenarioFailure("No phone joined.");
|
|
585
|
+
const idleFrom = sharedNow();
|
|
586
|
+
await wait(options.idleMs);
|
|
587
|
+
const tappedAt = sharedNow();
|
|
588
|
+
phone.device.send({ type: "press" });
|
|
589
|
+
const arrived = await firstInputAfter(room.host, phone.seat, tappedAt);
|
|
590
|
+
const away = phone.device
|
|
591
|
+
.since("host", idleFrom)
|
|
592
|
+
.some((event) => !event.present);
|
|
593
|
+
if (away) throw new ScenarioFailure("The idle host was dropped.");
|
|
594
|
+
return { idleMs: options.idleMs, tapToHostMs: arrived - tappedAt };
|
|
595
|
+
},
|
|
596
|
+
|
|
597
|
+
/** Sixteen phones at 30 Hz and a host publishing at 20 Hz. */
|
|
598
|
+
crowd: async ({ fleet, options }) => {
|
|
599
|
+
const room = await openRoom(fleet, { phones: 16, statesPerSecond: 20 });
|
|
600
|
+
const from = sharedNow();
|
|
601
|
+
await wait(options.crowdDurationMs);
|
|
602
|
+
const to = sharedNow() - 500;
|
|
603
|
+
const input = measureInput(room.host, room.phones, from, to);
|
|
604
|
+
if (input.lost > 0)
|
|
605
|
+
throw new ScenarioFailure(
|
|
606
|
+
`${input.lost} of ${input.pressed} presses never reached the host.`,
|
|
607
|
+
);
|
|
608
|
+
requireState(room.host, room.phones, from, to);
|
|
609
|
+
return {
|
|
610
|
+
phoneJoinMs: summarizeLatency(room.joinMs),
|
|
611
|
+
input: input.latency,
|
|
612
|
+
state: measureState(room.host, room.phones, from),
|
|
613
|
+
};
|
|
614
|
+
},
|
|
615
|
+
|
|
616
|
+
/** Many rooms at once: the numbers a hosting decision needs. */
|
|
617
|
+
load: async ({ fleet, options }) => {
|
|
618
|
+
const { rooms, phonesPerRoom, durationMs, workers } = options.load;
|
|
619
|
+
const shares = Array.from(
|
|
620
|
+
{ length: workers },
|
|
621
|
+
(_, index) =>
|
|
622
|
+
Math.floor(rooms / workers) + (index < rooms % workers ? 1 : 0),
|
|
623
|
+
).filter((share) => share > 0);
|
|
624
|
+
const results = await Promise.all(
|
|
625
|
+
shares.map((share, index) => {
|
|
626
|
+
const worker = fleet.device(`load worker ${index + 1}`);
|
|
627
|
+
worker.send({
|
|
628
|
+
type: "load",
|
|
629
|
+
link: fleet.link,
|
|
630
|
+
credentialCommand: fleet.hostCredentialCommand,
|
|
631
|
+
rooms: share,
|
|
632
|
+
phonesPerRoom,
|
|
633
|
+
inputsPerSecond: 30,
|
|
634
|
+
statesPerSecond: 20,
|
|
635
|
+
durationMs,
|
|
636
|
+
});
|
|
637
|
+
return worker.until(
|
|
638
|
+
(event) =>
|
|
639
|
+
event.type === "load" || event.type === "failed"
|
|
640
|
+
? event
|
|
641
|
+
: undefined,
|
|
642
|
+
"finishing its rooms",
|
|
643
|
+
GRANT_DEADLINE_MS + durationMs,
|
|
644
|
+
);
|
|
645
|
+
}),
|
|
646
|
+
);
|
|
647
|
+
return summarizeLoad(
|
|
648
|
+
results.map((event) => {
|
|
649
|
+
if (event.type === "failed") throw new ScenarioFailure(event.message);
|
|
650
|
+
return event.result;
|
|
651
|
+
}),
|
|
652
|
+
{ rooms, phonesPerRoom, durationMs },
|
|
653
|
+
);
|
|
654
|
+
},
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
const summarizeLoad = (
|
|
658
|
+
results: readonly LoadResult[],
|
|
659
|
+
{
|
|
660
|
+
rooms,
|
|
661
|
+
phonesPerRoom,
|
|
662
|
+
durationMs,
|
|
663
|
+
}: { rooms: number; phonesPerRoom: number; durationMs: number },
|
|
664
|
+
) => {
|
|
665
|
+
const total = <Key extends keyof LoadResult>(key: Key) =>
|
|
666
|
+
results.reduce((sum, result) => sum + (result[key] as number), 0);
|
|
667
|
+
const all = (
|
|
668
|
+
key: "roomOpenMs" | "phoneJoinMs" | "inputLatencyMs" | "stateLatencyMs",
|
|
669
|
+
) => results.flatMap((result) => result[key]);
|
|
670
|
+
const traffic = results.reduce(
|
|
671
|
+
(sum, result) => ({
|
|
672
|
+
messagesIn: sum.messagesIn + result.traffic.messagesIn,
|
|
673
|
+
bytesIn: sum.bytesIn + result.traffic.bytesIn,
|
|
674
|
+
messagesOut: sum.messagesOut + result.traffic.messagesOut,
|
|
675
|
+
bytesOut: sum.bytesOut + result.traffic.bytesOut,
|
|
676
|
+
}),
|
|
677
|
+
{ messagesIn: 0, bytesIn: 0, messagesOut: 0, bytesOut: 0 },
|
|
678
|
+
);
|
|
679
|
+
const roomHours = (total("roomsOpened") * durationMs) / HOUR_MS;
|
|
680
|
+
const perRoomHour = (value: number) =>
|
|
681
|
+
roomHours === 0 ? null : Math.round(value / roomHours);
|
|
682
|
+
const roomsOpened = total("roomsOpened");
|
|
683
|
+
const phonesJoined = total("phonesJoined");
|
|
684
|
+
const pressesLost = total("pressesLost");
|
|
685
|
+
const phonesWithoutState = total("phonesWithoutState");
|
|
686
|
+
if (
|
|
687
|
+
roomsOpened < rooms ||
|
|
688
|
+
phonesJoined < rooms * phonesPerRoom ||
|
|
689
|
+
pressesLost > 0 ||
|
|
690
|
+
phonesWithoutState > 0
|
|
691
|
+
)
|
|
692
|
+
throw new ScenarioFailure(
|
|
693
|
+
`${roomsOpened} of ${rooms} rooms opened, ${phonesJoined} of ${rooms * phonesPerRoom} phones joined, ${pressesLost} presses lost, ${phonesWithoutState} phones without the host's state.`,
|
|
694
|
+
);
|
|
695
|
+
return {
|
|
696
|
+
rooms: roomsOpened,
|
|
697
|
+
phones: phonesJoined,
|
|
698
|
+
durationMs,
|
|
699
|
+
roomOpen: summarizeLatency(all("roomOpenMs")),
|
|
700
|
+
phoneJoin: summarizeLatency(all("phoneJoinMs")),
|
|
701
|
+
input: summarizeLatency(all("inputLatencyMs")),
|
|
702
|
+
pressesSent: total("pressesSent"),
|
|
703
|
+
pressesLost,
|
|
704
|
+
state: summarizeLatency(all("stateLatencyMs")),
|
|
705
|
+
perRoomHour: {
|
|
706
|
+
messagesIn: perRoomHour(traffic.messagesIn),
|
|
707
|
+
messagesOut: perRoomHour(traffic.messagesOut),
|
|
708
|
+
payloadBytesOut: perRoomHour(traffic.bytesOut),
|
|
709
|
+
wireBytesOutWithTls: perRoomHour(
|
|
710
|
+
traffic.bytesOut + WIRE_FRAMING_BYTES * traffic.messagesOut,
|
|
711
|
+
),
|
|
712
|
+
},
|
|
713
|
+
clientCpuMs: Math.round(total("cpuMs")),
|
|
714
|
+
};
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Runs the hosting plan's edge cases against a rooms address, with the host
|
|
719
|
+
* and each phone as separate processes that are frozen, killed and replaced
|
|
720
|
+
* as locked phones, closed tabs and network switches would be, and the load
|
|
721
|
+
* scenario when asked for. The target is only a URL, so any room server can
|
|
722
|
+
* be checked the same way.
|
|
723
|
+
*/
|
|
724
|
+
export const runRoomsCheck = async (
|
|
725
|
+
options: RoomsCheckOptions,
|
|
726
|
+
): Promise<RoomsCheckReport> => {
|
|
727
|
+
const pacer =
|
|
728
|
+
options.connectionsPerMinute === undefined
|
|
729
|
+
? null
|
|
730
|
+
: new ConnectionPacer(options.connectionsPerMinute);
|
|
731
|
+
const target = {
|
|
732
|
+
link: { url: options.url, origin: options.origin },
|
|
733
|
+
hostCredentialCommand: options.hostCredentialCommand,
|
|
734
|
+
};
|
|
735
|
+
const resolved: ScenarioContext["options"] = {
|
|
736
|
+
briefFreezeMs: options.briefFreezeMs ?? 5_000,
|
|
737
|
+
stallMs: options.stallMs ?? 10_000,
|
|
738
|
+
idleMs: options.idleMs ?? 60_000,
|
|
739
|
+
crowdDurationMs: options.crowdDurationMs ?? 10_000,
|
|
740
|
+
load: {
|
|
741
|
+
rooms: options.load?.rooms ?? 100,
|
|
742
|
+
phonesPerRoom: options.load?.phonesPerRoom ?? 4,
|
|
743
|
+
durationMs: options.load?.durationMs ?? 60_000,
|
|
744
|
+
workers:
|
|
745
|
+
options.load?.workers ??
|
|
746
|
+
Math.max(1, Math.min(8, Math.floor(availableParallelism() / 2))),
|
|
747
|
+
},
|
|
748
|
+
};
|
|
749
|
+
const results: RoomsCheckScenarioResult[] = [];
|
|
750
|
+
for (const scenario of options.scenarios ?? DEFAULT_ROOMS_CHECK_SCENARIOS) {
|
|
751
|
+
const fleet = new Fleet(target, pacer);
|
|
752
|
+
const startedAt = sharedNow();
|
|
753
|
+
let result: RoomsCheckScenarioResult;
|
|
754
|
+
try {
|
|
755
|
+
const measurements = await scenarios[scenario]({
|
|
756
|
+
fleet,
|
|
757
|
+
options: resolved,
|
|
758
|
+
});
|
|
759
|
+
result = {
|
|
760
|
+
scenario,
|
|
761
|
+
passed: true,
|
|
762
|
+
durationMs: Math.round(sharedNow() - startedAt),
|
|
763
|
+
measurements: roundAll(measurements),
|
|
764
|
+
connectionProblems: fleet.problems(startedAt),
|
|
765
|
+
};
|
|
766
|
+
} catch (error) {
|
|
767
|
+
if (!(error instanceof ScenarioFailure)) throw error;
|
|
768
|
+
result = {
|
|
769
|
+
scenario,
|
|
770
|
+
passed: false,
|
|
771
|
+
failure: error.message,
|
|
772
|
+
durationMs: Math.round(sharedNow() - startedAt),
|
|
773
|
+
measurements: {},
|
|
774
|
+
connectionProblems: fleet.problems(startedAt),
|
|
775
|
+
};
|
|
776
|
+
} finally {
|
|
777
|
+
fleet.close();
|
|
778
|
+
}
|
|
779
|
+
results.push(result);
|
|
780
|
+
options.onResult?.(result);
|
|
781
|
+
}
|
|
782
|
+
return {
|
|
783
|
+
url: options.url,
|
|
784
|
+
passed: results.every((result) => result.passed),
|
|
785
|
+
scenarios: results,
|
|
786
|
+
};
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
const roundAll = (
|
|
790
|
+
measurements: Record<string, unknown>,
|
|
791
|
+
): Record<string, unknown> =>
|
|
792
|
+
Object.fromEntries(
|
|
793
|
+
Object.entries(measurements).map(([key, value]) => [
|
|
794
|
+
key,
|
|
795
|
+
typeof value === "number" ? Math.round(value * 100) / 100 : value,
|
|
796
|
+
]),
|
|
797
|
+
);
|