@smoothbricks/nx-plugin 0.7.18 → 0.7.19
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 +160 -99
- package/dist/.build-inputs.json +35 -29
- package/dist/built-output-packages.js +1 -1
- package/dist/cargo-closure-input.js +1 -1
- package/dist/cargo-source-hash.d.ts +3 -21
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +4 -91
- package/dist/cargo-toolchain-paths.d.ts +2 -2
- package/dist/cargo-toolchain-paths.js +2 -2
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +2 -1
- package/dist/executors/bounded-exec/admission-queue.d.ts +3 -1
- package/dist/executors/bounded-exec/admission-queue.d.ts.map +1 -1
- package/dist/executors/bounded-exec/admission-queue.js +9 -10
- package/dist/executors/bounded-exec/awake-clock.d.ts +5 -0
- package/dist/executors/bounded-exec/awake-clock.d.ts.map +1 -0
- package/dist/executors/bounded-exec/awake-clock.js +22 -0
- package/dist/executors/bounded-exec/bounds.d.ts +7 -5
- package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
- package/dist/executors/bounded-exec/bounds.js +14 -11
- package/dist/executors/bounded-exec/case-gate.d.ts +114 -0
- package/dist/executors/bounded-exec/case-gate.d.ts.map +1 -0
- package/dist/executors/bounded-exec/case-gate.js +342 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +1 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool-thread.js +2 -2
- package/dist/executors/bounded-exec/cpu-pool.d.ts +28 -1
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +102 -16
- package/dist/executors/bounded-exec/endpoint-life.d.ts +146 -0
- package/dist/executors/bounded-exec/endpoint-life.d.ts.map +1 -0
- package/dist/executors/bounded-exec/endpoint-life.js +228 -0
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +207 -69
- package/dist/executors/bounded-exec/gateway-lease.d.ts +1 -1
- package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
- package/dist/executors/bounded-exec/gateway-lease.js +8 -1
- package/dist/executors/bounded-exec/go-run-summary.d.ts +51 -0
- package/dist/executors/bounded-exec/go-run-summary.d.ts.map +1 -0
- package/dist/executors/bounded-exec/go-run-summary.js +98 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts +3 -3
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
- package/dist/executors/bounded-exec/hang-diagnostics.js +66 -48
- package/dist/executors/bounded-exec/lease-wait.d.ts +1 -0
- package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -1
- package/dist/executors/bounded-exec/lease-wait.js +1 -0
- package/dist/executors/bounded-exec/mbx-pool.d.ts +28 -7
- package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/mbx-pool.js +30 -9
- package/dist/executors/bounded-exec/mbx-reservations.d.ts +8 -5
- package/dist/executors/bounded-exec/mbx-reservations.d.ts.map +1 -1
- package/dist/executors/bounded-exec/mbx-reservations.js +187 -283
- package/dist/executors/bounded-exec/parent-grant.d.ts +2 -0
- package/dist/executors/bounded-exec/parent-grant.d.ts.map +1 -1
- package/dist/executors/bounded-exec/parent-grant.js +1 -0
- package/dist/executors/bounded-exec/pool-admission.d.ts +29 -3
- package/dist/executors/bounded-exec/pool-admission.d.ts.map +1 -1
- package/dist/executors/bounded-exec/pool-admission.js +47 -1
- package/dist/executors/bounded-exec/progress.d.ts +3 -0
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
- package/dist/executors/bounded-exec/progress.js +31 -1
- package/dist/executors/bounded-exec/reservation-connection.d.ts +90 -0
- package/dist/executors/bounded-exec/reservation-connection.d.ts.map +1 -0
- package/dist/executors/bounded-exec/reservation-connection.js +248 -0
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/run-cpu-pool.js +3 -0
- package/dist/executors/bounded-exec/runner-sizing.d.ts +9 -5
- package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
- package/dist/executors/bounded-exec/runner-sizing.js +13 -9
- package/dist/executors/bounded-exec/schema.d.ts +2 -2
- package/dist/executors/bounded-exec/suite-minimum.d.ts +21 -0
- package/dist/executors/bounded-exec/suite-minimum.d.ts.map +1 -0
- package/dist/executors/bounded-exec/suite-minimum.js +85 -0
- package/dist/executors/bounded-exec/test-result-writer.d.ts +2 -0
- package/dist/executors/bounded-exec/test-result-writer.d.ts.map +1 -1
- package/dist/executors/bounded-exec/test-result-writer.js +1 -0
- package/dist/executors/bounded-exec/test-results.d.ts +5 -0
- package/dist/executors/bounded-exec/test-results.d.ts.map +1 -1
- package/dist/executors/bounded-exec/test-results.js +2 -2
- package/dist/executors/bounded-exec/verdict.d.ts +26 -4
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +26 -5
- package/dist/executors/cargo-zigbuild/executor.d.ts +10 -8
- package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
- package/dist/executors/cargo-zigbuild/executor.js +32 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +105 -73
- package/dist/managed-files/ci-workflow.d.ts +4 -1
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +9 -14
- package/dist/managed-files/files.d.ts +3 -3
- package/dist/managed-files/files.js +3 -3
- package/dist/task-results.js +2 -1
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +135 -42
- package/executors.json +2 -0
- package/managed/raw/envrc +24 -0
- package/managed/raw/patches/nx@24.0.3.patch +1179 -133
- package/managed/raw/patches/ttsc@0.37.1.patch +1055 -0
- package/managed/raw/tooling/direnv/developer-links.ts +105 -11
- package/managed/raw/tooling/direnv/devenv.smoo.nix +20 -19
- package/package.json +67 -11
- package/runtime/nx-publish/.build-inputs.json +2 -2
- package/runtime/nx-publish/cache_adapter.js +293 -3
- package/runtime/nx-publish/nx_publish.js +36 -14
- package/src/built-output-packages.ts +1 -1
- package/src/cargo-closure-input.ts +1 -1
- package/src/cargo-source-hash.ts +16 -132
- package/src/cargo-toolchain-paths.ts +2 -2
- package/src/cargo-workspace.ts +1 -2
- package/src/executors/bounded-exec/admission-queue.ts +11 -10
- package/src/executors/bounded-exec/awake-clock.ts +20 -0
- package/src/executors/bounded-exec/bounds.ts +28 -15
- package/src/executors/bounded-exec/case-gate.ts +365 -0
- package/src/executors/bounded-exec/cpu-pool-thread.ts +3 -3
- package/src/executors/bounded-exec/cpu-pool.ts +139 -12
- package/src/executors/bounded-exec/endpoint-life.ts +279 -0
- package/src/executors/bounded-exec/executor.ts +280 -106
- package/src/executors/bounded-exec/gateway-lease.ts +6 -0
- package/src/executors/bounded-exec/go-run-summary.ts +137 -0
- package/src/executors/bounded-exec/hang-diagnostics.ts +70 -52
- package/src/executors/bounded-exec/lease-wait.ts +1 -0
- package/src/executors/bounded-exec/mbx-pool.ts +36 -9
- package/src/executors/bounded-exec/mbx-reservations.ts +213 -182
- package/src/executors/bounded-exec/parent-grant.ts +3 -0
- package/src/executors/bounded-exec/pool-admission.ts +59 -2
- package/src/executors/bounded-exec/progress.ts +37 -2
- package/src/executors/bounded-exec/reservation-connection.ts +221 -0
- package/src/executors/bounded-exec/run-cpu-pool.ts +2 -0
- package/src/executors/bounded-exec/runner-sizing.ts +13 -8
- package/src/executors/bounded-exec/schema.json +1 -1
- package/src/executors/bounded-exec/schema.ts +2 -2
- package/src/executors/bounded-exec/suite-minimum.ts +81 -0
- package/src/executors/bounded-exec/test-result-writer.ts +3 -0
- package/src/executors/bounded-exec/test-results.ts +5 -0
- package/src/executors/bounded-exec/verdict.ts +39 -6
- package/src/executors/cargo-zigbuild/executor.ts +30 -19
- package/src/index.ts +112 -78
- package/src/managed-files/ci-workflow.ts +13 -17
- package/src/managed-files/files.ts +3 -3
- package/src/workspace-config-policy.ts +161 -43
- package/test-timings.json +157 -147
- package/managed/raw/patches/ttsc@0.36.3.patch +0 -1660
|
@@ -34,7 +34,7 @@ function tokensFitting(ask, most, room) {
|
|
|
34
34
|
}
|
|
35
35
|
return Math.min(most, Math.floor((room * measured) / ask.memory));
|
|
36
36
|
}
|
|
37
|
-
export function admit(queue, available, memory, holding = NOTHING_HELD) {
|
|
37
|
+
export function admit(queue, available, memory, holding = NOTHING_HELD, lendable = true) {
|
|
38
38
|
const grants = [];
|
|
39
39
|
if (holding.alone) {
|
|
40
40
|
return { grants, waiting: queue.length === 0 ? null : 'alone' };
|
|
@@ -45,6 +45,9 @@ export function admit(queue, available, memory, holding = NOTHING_HELD) {
|
|
|
45
45
|
if (request.alone === true && holding.holders + grants.length > 0) {
|
|
46
46
|
return { grants, waiting: 'alone' };
|
|
47
47
|
}
|
|
48
|
+
if (request.lend === true && !lendable) {
|
|
49
|
+
return { grants, waiting: 'settle' };
|
|
50
|
+
}
|
|
48
51
|
const oversized = memory !== null && request.memory > memory.capacity;
|
|
49
52
|
const room = memory === null ? Number.POSITIVE_INFINITY : memory.capacity - held;
|
|
50
53
|
if (request.memory > room && !(oversized && held === 0)) {
|
|
@@ -65,3 +68,46 @@ export function admit(queue, available, memory, holding = NOTHING_HELD) {
|
|
|
65
68
|
}
|
|
66
69
|
return { grants, waiting: null };
|
|
67
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Where a request joins the queue (specs/cowshed/05_gateway.md, "Without mbx, every Nx run budgets itself"). A leaf the
|
|
73
|
+
* kernel killed, run again alone, has waited once already and goes ahead of the leaves that have not run. A leaf goes
|
|
74
|
+
* behind the leaves and ahead of every lent request: a case is lent only a token no leaf waits for. A lent request goes
|
|
75
|
+
* among the lent ones behind those whose leaves have as much work left or more, so a free token goes to the leaf that
|
|
76
|
+
* would otherwise end last, in arrival order among equals.
|
|
77
|
+
*/
|
|
78
|
+
export function place(queue, ask) {
|
|
79
|
+
const before = (found) => (found === -1 ? queue.length : found);
|
|
80
|
+
if (ask.alone === true) {
|
|
81
|
+
return before(queue.findIndex((waiting) => waiting.alone !== true));
|
|
82
|
+
}
|
|
83
|
+
if (ask.lend !== true) {
|
|
84
|
+
return before(queue.findIndex((waiting) => waiting.lend === true));
|
|
85
|
+
}
|
|
86
|
+
const left = ask.left ?? 0;
|
|
87
|
+
return before(queue.findIndex((waiting) => waiting.lend === true && (waiting.left ?? 0) < left));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The token-time a pool's tokens stood idle beside a starved hold: a leaf holding fewer tokens than it asked that
|
|
91
|
+
* cannot ask for more, or a case waiting for a lent token. The pool tells it the idle count and whether a hold is
|
|
92
|
+
* starved at each change, on its own clock; what is counted is the idle count over the time a starved hold stood.
|
|
93
|
+
*/
|
|
94
|
+
export class IdleBesideStarved {
|
|
95
|
+
#at;
|
|
96
|
+
#idle = 0;
|
|
97
|
+
#starved = false;
|
|
98
|
+
#tokenMs = 0;
|
|
99
|
+
constructor(now) {
|
|
100
|
+
this.#at = now;
|
|
101
|
+
}
|
|
102
|
+
/** From `now` on, `idle` tokens are free and a hold is `starved` or none is. */
|
|
103
|
+
observe(now, idle, starved) {
|
|
104
|
+
this.#tokenMs = this.tokenMs(now);
|
|
105
|
+
this.#at = now;
|
|
106
|
+
this.#idle = idle;
|
|
107
|
+
this.#starved = starved;
|
|
108
|
+
}
|
|
109
|
+
/** The token-milliseconds counted up to `now`. */
|
|
110
|
+
tokenMs(now) {
|
|
111
|
+
return this.#tokenMs + (this.#starved ? this.#idle * (now - this.#at) : 0);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { GoRunSummary } from './go-run-summary.js';
|
|
1
2
|
import type { NativeTestResult } from './test-result-writer.js';
|
|
2
3
|
/**
|
|
3
4
|
* What a run's output says about its forward motion: whether a test finished, and which tests the runner said
|
|
@@ -32,6 +33,8 @@ export interface RunProgress {
|
|
|
32
33
|
/** The tests the runner reported running and has not reported finished, in the order it first named them. */
|
|
33
34
|
inFlight(): string[];
|
|
34
35
|
error(): string | null;
|
|
36
|
+
/** The Go run so far, by its top-level tests; null for a command that runs no Go tests. */
|
|
37
|
+
goSummary(): GoRunSummary | null;
|
|
35
38
|
}
|
|
36
39
|
export type OutputStream = 'stdout' | 'stderr';
|
|
37
40
|
export declare function createRunProgress(command?: string, closed?: (result: NativeTestResult) => void): RunProgress;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/progress.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/progress.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGhE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,WAAW;IAC1B,gGAAgG;IAChG,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAC5D,6GAA6G;IAC7G,QAAQ,IAAI,MAAM,EAAE,CAAC;IACrB,KAAK,IAAI,MAAM,GAAG,IAAI,CAAC;IACvB,2FAA2F;IAC3F,SAAS,IAAI,YAAY,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,CAAC;AA6E/C,wBAAgB,iBAAiB,CAAC,OAAO,SAAK,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,GAAG,WAAW,CA4NxG;AAED,2FAA2F;AAC3F,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAuBtG;AACD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAmB1D"}
|
|
@@ -93,6 +93,10 @@ export function createRunProgress(command = '', closed) {
|
|
|
93
93
|
const running = new Set();
|
|
94
94
|
const packages = new Map();
|
|
95
95
|
const goOutput = new Map();
|
|
96
|
+
// A Go run prints no count: its events are summed here, by top-level test, for the summary its output ends with.
|
|
97
|
+
const goVerdicts = new Map();
|
|
98
|
+
const goPackages = new Set();
|
|
99
|
+
const goFailedPackages = [];
|
|
96
100
|
const decoders = {
|
|
97
101
|
stdout: new StringDecoder('utf8'),
|
|
98
102
|
stderr: new StringDecoder('utf8'),
|
|
@@ -117,6 +121,7 @@ export function createRunProgress(command = '', closed) {
|
|
|
117
121
|
switch (event.Action) {
|
|
118
122
|
case 'start':
|
|
119
123
|
packages.set(event.Package, new Set());
|
|
124
|
+
goPackages.add(event.Package);
|
|
120
125
|
return false;
|
|
121
126
|
case 'run':
|
|
122
127
|
packages.get(event.Package)?.add(event.Test);
|
|
@@ -125,11 +130,20 @@ export function createRunProgress(command = '', closed) {
|
|
|
125
130
|
case 'fail':
|
|
126
131
|
case 'skip':
|
|
127
132
|
case 'bench':
|
|
128
|
-
if (event.Test === undefined)
|
|
133
|
+
if (event.Test === undefined) {
|
|
129
134
|
packages.delete(event.Package);
|
|
135
|
+
goPackages.add(event.Package);
|
|
136
|
+
// A package that fails with no failed test of its own did not get to run them: a build, a TestMain.
|
|
137
|
+
if (event.Action === 'fail' &&
|
|
138
|
+
![...goVerdicts.values()].some((test) => test.package === event.Package && test.status === 'fail'))
|
|
139
|
+
goFailedPackages.push(event.Package);
|
|
140
|
+
}
|
|
130
141
|
else {
|
|
131
142
|
packages.get(event.Package)?.delete(event.Test);
|
|
132
143
|
const id = `${event.Package}::${event.Test}`;
|
|
144
|
+
// A subtest's verdict is its parent's, which Go reports after it: only the parent is counted.
|
|
145
|
+
if (event.Action !== 'bench' && !event.Test.includes('/'))
|
|
146
|
+
goVerdicts.set(id, { package: event.Package, test: event.Test, status: event.Action });
|
|
133
147
|
if (event.Action !== 'bench' && goResults)
|
|
134
148
|
closed?.({
|
|
135
149
|
id,
|
|
@@ -259,6 +273,22 @@ export function createRunProgress(command = '', closed) {
|
|
|
259
273
|
return progressed;
|
|
260
274
|
},
|
|
261
275
|
error: () => failure,
|
|
276
|
+
goSummary: () => {
|
|
277
|
+
if (!goResults)
|
|
278
|
+
return null;
|
|
279
|
+
const verdicts = [...goVerdicts.values()];
|
|
280
|
+
const count = (status) => verdicts.filter((test) => test.status === status).length;
|
|
281
|
+
return {
|
|
282
|
+
passed: count('pass'),
|
|
283
|
+
failed: count('fail'),
|
|
284
|
+
skipped: count('skip'),
|
|
285
|
+
packages: goPackages.size,
|
|
286
|
+
failedTests: verdicts
|
|
287
|
+
.filter((test) => test.status === 'fail')
|
|
288
|
+
.map((test) => ({ package: test.package, test: test.test })),
|
|
289
|
+
failedPackages: [...goFailedPackages],
|
|
290
|
+
};
|
|
291
|
+
},
|
|
262
292
|
inFlight: () => [
|
|
263
293
|
...running,
|
|
264
294
|
...[...packages].flatMap(([name, tests]) => tests.size === 0 ? [name] : [...tests].map((test) => `${name} ${test}`)),
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { MbxPriority } from './mbx-pool.js';
|
|
2
|
+
/**
|
|
3
|
+
* One process's connection to its run's mbx reservation endpoint (mbx-reservations.ts; specs/cowshed/05_gateway.md,
|
|
4
|
+
* "Parallelism inside a job"), as a state machine over what the process asks of it and what its socket says. Pure: no
|
|
5
|
+
* I/O and no clock. The shell maps its callers' requests and the socket's events into `ConnectionEvent`s and executes
|
|
6
|
+
* the `ConnectionEffect`s each step answers, in their order; it decides nothing.
|
|
7
|
+
*
|
|
8
|
+
* Every request is answered once: granted, refused by the pool, withdrawn by its own release, or failed by the
|
|
9
|
+
* connection's end, which also loses every grant still held. A grant lasts until its release or that end, and the
|
|
10
|
+
* endpoint is told of every release it can still hear. Nothing is written once the connection has ended.
|
|
11
|
+
*/
|
|
12
|
+
export interface Connection {
|
|
13
|
+
readonly endpoint: string;
|
|
14
|
+
/** What the socket said after its last whole line. */
|
|
15
|
+
readonly unread: string;
|
|
16
|
+
/** Each request neither released nor refused: waiting for its answer, or holding its grant. */
|
|
17
|
+
readonly entries: ReadonlyMap<number, 'waiting' | 'held'>;
|
|
18
|
+
/** Why the connection ended, which answers every later request; null while it serves. */
|
|
19
|
+
readonly closed: ReservationRefusal | null;
|
|
20
|
+
}
|
|
21
|
+
/** Why a reservation holds no cores: the endpoint asked, and the connect error's code when it could not be reached. */
|
|
22
|
+
export interface ReservationRefusal {
|
|
23
|
+
readonly endpoint: string;
|
|
24
|
+
/** The code of the error that ended the connection (`ENOENT`: the endpoint's socket is gone), else null. */
|
|
25
|
+
readonly errno: string | null;
|
|
26
|
+
readonly message: string;
|
|
27
|
+
}
|
|
28
|
+
/** What the shell observes: its callers' requests, each under an id of its own, and its socket's events. */
|
|
29
|
+
export type ConnectionEvent = {
|
|
30
|
+
readonly type: 'reserve';
|
|
31
|
+
readonly id: number;
|
|
32
|
+
readonly cpus: number;
|
|
33
|
+
readonly priority: MbxPriority;
|
|
34
|
+
/** The fewest cores the reservation starts on before mbx's aging bound; one is no minimum. */
|
|
35
|
+
readonly min: number;
|
|
36
|
+
/** The class mbx predicts the reservation by. */
|
|
37
|
+
readonly name?: string | undefined;
|
|
38
|
+
} | {
|
|
39
|
+
readonly type: 'release';
|
|
40
|
+
readonly id: number;
|
|
41
|
+
} | {
|
|
42
|
+
readonly type: 'data';
|
|
43
|
+
readonly text: string;
|
|
44
|
+
} | {
|
|
45
|
+
readonly type: 'error';
|
|
46
|
+
readonly message: string;
|
|
47
|
+
readonly code: string | null;
|
|
48
|
+
} | {
|
|
49
|
+
readonly type: 'close';
|
|
50
|
+
};
|
|
51
|
+
/** A request's answer: its cores, or why it has none. */
|
|
52
|
+
export type Answer = {
|
|
53
|
+
readonly ok: true;
|
|
54
|
+
readonly cpus: number;
|
|
55
|
+
} | {
|
|
56
|
+
readonly ok: false;
|
|
57
|
+
readonly refusal: ReservationRefusal;
|
|
58
|
+
};
|
|
59
|
+
export type ConnectionEffect =
|
|
60
|
+
/** Keep the process alive for the connection: a request waits or holds. */
|
|
61
|
+
{
|
|
62
|
+
readonly do: 'ref';
|
|
63
|
+
}
|
|
64
|
+
/** Nothing waits or holds: the connection no longer keeps the process alive. */
|
|
65
|
+
| {
|
|
66
|
+
readonly do: 'unref';
|
|
67
|
+
} | {
|
|
68
|
+
readonly do: 'write';
|
|
69
|
+
readonly line: string;
|
|
70
|
+
} | {
|
|
71
|
+
readonly do: 'answer';
|
|
72
|
+
readonly id: number;
|
|
73
|
+
readonly answer: Answer;
|
|
74
|
+
}
|
|
75
|
+
/** A grant its request was answered with is lost, and why. */
|
|
76
|
+
| {
|
|
77
|
+
readonly do: 'lose';
|
|
78
|
+
readonly id: number;
|
|
79
|
+
readonly why: string;
|
|
80
|
+
}
|
|
81
|
+
/** Forget the connection, so the next request opens another, and destroy its socket. */
|
|
82
|
+
| {
|
|
83
|
+
readonly do: 'hang-up';
|
|
84
|
+
};
|
|
85
|
+
export type ConnectionStep = readonly [Connection, readonly ConnectionEffect[]];
|
|
86
|
+
/** A connection just opened to `endpoint`. */
|
|
87
|
+
export declare function opened(endpoint: string): Connection;
|
|
88
|
+
/** The next state of `connection` at `event`, and what the shell does about it. */
|
|
89
|
+
export declare function connectionStep(connection: Connection, event: ConnectionEvent): ConnectionStep;
|
|
90
|
+
//# sourceMappingURL=reservation-connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reservation-connection.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/reservation-connection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,C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cAAc,CA6C7F"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import * as _isTypeUint32_1 from "typia/lib/internal/_isTypeUint32";
|
|
2
|
+
import * as _jsonStringifyNumber_1 from "typia/lib/internal/_jsonStringifyNumber";
|
|
3
|
+
import * as _jsonStringifyString_1 from "typia/lib/internal/_jsonStringifyString";
|
|
4
|
+
import * as _jsonStringifyTail_1 from "typia/lib/internal/_jsonStringifyTail";
|
|
5
|
+
import * as _throwTypeGuardError_1 from "typia/lib/internal/_throwTypeGuardError";
|
|
6
|
+
import * as _validateReport_1 from "typia/lib/internal/_validateReport";
|
|
7
|
+
import typia from 'typia';
|
|
8
|
+
const stringifyRequest = (() => {
|
|
9
|
+
const _ip0 = input => "number" === typeof input["id"] && _isTypeUint32_1._isTypeUint32(input["id"]);
|
|
10
|
+
const _so0 = input => `{${_jsonStringifyTail_1._jsonStringifyTail(`"type":${"\"" + input.type + "\""},"id":${String(_jsonStringifyNumber_1._jsonStringifyNumber(input.id))},"cpus":${String(_jsonStringifyNumber_1._jsonStringifyNumber(input.cpus))},"priority":${"\"" + input.priority + "\""},${undefined === input.min ? "" : `"min":${undefined !== input.min ? String(_jsonStringifyNumber_1._jsonStringifyNumber(input.min)) : undefined},`}${undefined === input.name ? "" : `"name":${undefined !== input.name ? _jsonStringifyString_1._jsonStringifyString(input.name) : undefined}`}`)}}`;
|
|
11
|
+
const _so1 = input => `{"type":${"\"" + input.type + "\""},"id":${String(_jsonStringifyNumber_1._jsonStringifyNumber(input.id))}}`;
|
|
12
|
+
const _su0 = input => (() => {
|
|
13
|
+
if ("reserve" === input.type)
|
|
14
|
+
return _so0(input);
|
|
15
|
+
else if ("release" === input.type)
|
|
16
|
+
return _so1(input);
|
|
17
|
+
else
|
|
18
|
+
_throwTypeGuardError_1._throwTypeGuardError({
|
|
19
|
+
method: "typia.json.createStringify",
|
|
20
|
+
expected: "({ type: \"reserve\"; id: Uint; cpus: number & Type<\"uint32\"> & Minimum<1>; priority: \"interactive\" | \"low\" | \"normal\"; min?: (number & Type<\"uint32\"> & Minimum<...>) | undefined; name?: string | undefined; } | { type: \"release\"; id: Uint; })",
|
|
21
|
+
value: input
|
|
22
|
+
});
|
|
23
|
+
})();
|
|
24
|
+
const _io0 = input => "reserve" === input.type && _ip0(input) && ("number" === typeof input.cpus && (_isTypeUint32_1._isTypeUint32(input.cpus) && 1 <= input.cpus)) && ("interactive" === input.priority || "low" === input.priority || "normal" === input.priority) && (undefined === input.min || "number" === typeof input.min && (_isTypeUint32_1._isTypeUint32(input.min) && 2 <= input.min)) && (undefined === input.name || "string" === typeof input.name);
|
|
25
|
+
const _io1 = input => "release" === input.type && _ip0(input);
|
|
26
|
+
return input => _su0(input);
|
|
27
|
+
})();
|
|
28
|
+
const parseReply = (() => {
|
|
29
|
+
let errors;
|
|
30
|
+
let _report;
|
|
31
|
+
const _ip0 = input => "number" === typeof input["id"] && _isTypeUint32_1._isTypeUint32(input["id"]);
|
|
32
|
+
const _ip1 = input => "string" === typeof input["error"];
|
|
33
|
+
const _ve0 = "({ type: \"error\"; error: string; } | { type: \"granted\"; id: Uint; cpus: number & Type<\"uint32\"> & Minimum<1>; } | { type: \"refused\"; id: Uint; error: string; })";
|
|
34
|
+
const _vp0 = (input, _path, _exceptionable = true) => "number" === typeof input["id"] && (_isTypeUint32_1._isTypeUint32(input["id"]) || _report(_exceptionable, {
|
|
35
|
+
path: _path + ".id",
|
|
36
|
+
expected: "number & Type<\"uint32\">",
|
|
37
|
+
value: input["id"]
|
|
38
|
+
})) || _report(_exceptionable, {
|
|
39
|
+
path: _path + ".id",
|
|
40
|
+
expected: "(number & Type<\"uint32\">)",
|
|
41
|
+
value: input["id"]
|
|
42
|
+
});
|
|
43
|
+
const _vp1 = (input, _path, _exceptionable = true) => "string" === typeof input["error"] || _report(_exceptionable, {
|
|
44
|
+
path: _path + ".error",
|
|
45
|
+
expected: "string",
|
|
46
|
+
value: input["error"]
|
|
47
|
+
});
|
|
48
|
+
const _ve1 = "({ type: \"granted\"; id: Uint; cpus: number & Type<\"uint32\"> & Minimum<1>; } | { type: \"refused\"; id: Uint; error: string; } | { type: \"error\"; error: string; })";
|
|
49
|
+
const _io0 = input => "granted" === input.type && _ip0(input) && ("number" === typeof input.cpus && (_isTypeUint32_1._isTypeUint32(input.cpus) && 1 <= input.cpus));
|
|
50
|
+
const _io1 = input => "refused" === input.type && _ip0(input) && _ip1(input);
|
|
51
|
+
const _io2 = input => "error" === input.type && _ip1(input);
|
|
52
|
+
const _iu0 = input => (() => {
|
|
53
|
+
if ("granted" === input.type)
|
|
54
|
+
return _io0(input);
|
|
55
|
+
else if ("refused" === input.type)
|
|
56
|
+
return _io1(input);
|
|
57
|
+
else if ("error" === input.type)
|
|
58
|
+
return _io2(input);
|
|
59
|
+
else
|
|
60
|
+
return false;
|
|
61
|
+
})();
|
|
62
|
+
const _vo0 = (input, _path, _exceptionable = true) => ["granted" === input.type || _report(_exceptionable, {
|
|
63
|
+
path: _path + ".type",
|
|
64
|
+
expected: "\"granted\"",
|
|
65
|
+
value: input.type
|
|
66
|
+
}), _vp0(input, _path, true && _exceptionable), "number" === typeof input.cpus && (_isTypeUint32_1._isTypeUint32(input.cpus) || _report(_exceptionable, {
|
|
67
|
+
path: _path + ".cpus",
|
|
68
|
+
expected: "number & Type<\"uint32\">",
|
|
69
|
+
value: input.cpus
|
|
70
|
+
})) && (1 <= input.cpus || _report(_exceptionable, {
|
|
71
|
+
path: _path + ".cpus",
|
|
72
|
+
expected: "number & Minimum<1>",
|
|
73
|
+
value: input.cpus
|
|
74
|
+
})) || _report(_exceptionable, {
|
|
75
|
+
path: _path + ".cpus",
|
|
76
|
+
expected: "(number & Type<\"uint32\"> & Minimum<1>)",
|
|
77
|
+
value: input.cpus
|
|
78
|
+
})].every(flag => flag);
|
|
79
|
+
const _vo1 = (input, _path, _exceptionable = true) => ["refused" === input.type || _report(_exceptionable, {
|
|
80
|
+
path: _path + ".type",
|
|
81
|
+
expected: "\"refused\"",
|
|
82
|
+
value: input.type
|
|
83
|
+
}), _vp0(input, _path, true && _exceptionable), _vp1(input, _path, true && _exceptionable)].every(flag => flag);
|
|
84
|
+
const _vo2 = (input, _path, _exceptionable = true) => ["error" === input.type || _report(_exceptionable, {
|
|
85
|
+
path: _path + ".type",
|
|
86
|
+
expected: "\"error\"",
|
|
87
|
+
value: input.type
|
|
88
|
+
}), _vp1(input, _path, true && _exceptionable)].every(flag => flag);
|
|
89
|
+
const _vu0 = (input, _path, _exceptionable = true) => (() => {
|
|
90
|
+
if ("granted" === input.type)
|
|
91
|
+
return _vo0(input, _path, true && _exceptionable);
|
|
92
|
+
else if ("refused" === input.type)
|
|
93
|
+
return _vo1(input, _path, true && _exceptionable);
|
|
94
|
+
else if ("error" === input.type)
|
|
95
|
+
return _vo2(input, _path, true && _exceptionable);
|
|
96
|
+
else
|
|
97
|
+
return _report(_exceptionable, {
|
|
98
|
+
path: _path,
|
|
99
|
+
expected: _ve1,
|
|
100
|
+
value: input
|
|
101
|
+
});
|
|
102
|
+
})();
|
|
103
|
+
const __is = input => "object" === typeof input && null !== input && _iu0(input);
|
|
104
|
+
const __validate = input => {
|
|
105
|
+
if (false === __is(input)) {
|
|
106
|
+
errors = [];
|
|
107
|
+
_report = _validateReport_1._validateReport(errors);
|
|
108
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
|
|
109
|
+
path: _path + "",
|
|
110
|
+
expected: _ve0,
|
|
111
|
+
value: input
|
|
112
|
+
})) && _vu0(input, _path + "", true) || _report(true, {
|
|
113
|
+
path: _path + "",
|
|
114
|
+
expected: _ve0,
|
|
115
|
+
value: input
|
|
116
|
+
}))(input, "$input", true);
|
|
117
|
+
const success = 0 === errors.length;
|
|
118
|
+
return success ? {
|
|
119
|
+
success,
|
|
120
|
+
data: input
|
|
121
|
+
} : {
|
|
122
|
+
success,
|
|
123
|
+
errors,
|
|
124
|
+
data: input
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
success: true,
|
|
129
|
+
data: input
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
return input => __validate(JSON.parse(input));
|
|
133
|
+
})();
|
|
134
|
+
/** A connection just opened to `endpoint`. */
|
|
135
|
+
export function opened(endpoint) {
|
|
136
|
+
return { endpoint, unread: '', entries: new Map(), closed: null };
|
|
137
|
+
}
|
|
138
|
+
/** The next state of `connection` at `event`, and what the shell does about it. */
|
|
139
|
+
export function connectionStep(connection, event) {
|
|
140
|
+
if (connection.closed !== null) {
|
|
141
|
+
// An ended connection answers a request with its end; nothing else of it is left to decide.
|
|
142
|
+
return event.type === 'reserve'
|
|
143
|
+
? [connection, [{ do: 'answer', id: event.id, answer: { ok: false, refusal: connection.closed } }]]
|
|
144
|
+
: [connection, []];
|
|
145
|
+
}
|
|
146
|
+
switch (event.type) {
|
|
147
|
+
case 'reserve': {
|
|
148
|
+
// A minimum of one is no minimum, and mbx refuses one above the ask.
|
|
149
|
+
const gathers = Math.min(event.min, event.cpus);
|
|
150
|
+
const line = stringifyRequest({
|
|
151
|
+
type: 'reserve',
|
|
152
|
+
id: event.id,
|
|
153
|
+
cpus: event.cpus,
|
|
154
|
+
priority: event.priority,
|
|
155
|
+
...(gathers > 1 ? { min: gathers } : {}),
|
|
156
|
+
...(event.name === undefined ? {} : { name: event.name }),
|
|
157
|
+
});
|
|
158
|
+
return [
|
|
159
|
+
{ ...connection, entries: new Map(connection.entries).set(event.id, 'waiting') },
|
|
160
|
+
[{ do: 'ref' }, { do: 'write', line: `${line}\n` }],
|
|
161
|
+
];
|
|
162
|
+
}
|
|
163
|
+
case 'release': {
|
|
164
|
+
const entry = connection.entries.get(event.id);
|
|
165
|
+
// Released, refused or never asked: nothing of it is left to give back.
|
|
166
|
+
if (entry === undefined)
|
|
167
|
+
return [connection, []];
|
|
168
|
+
const entries = without(connection.entries, event.id);
|
|
169
|
+
return [
|
|
170
|
+
{ ...connection, entries },
|
|
171
|
+
[
|
|
172
|
+
...(entry === 'waiting' ? [refused(connection, event.id, 'released while it waited')] : []),
|
|
173
|
+
{ do: 'write', line: `${stringifyRequest({ type: 'release', id: event.id })}\n` },
|
|
174
|
+
...unreferenced(entries),
|
|
175
|
+
],
|
|
176
|
+
];
|
|
177
|
+
}
|
|
178
|
+
case 'data':
|
|
179
|
+
return read({ ...connection, unread: connection.unread + event.text }, []);
|
|
180
|
+
case 'error':
|
|
181
|
+
return close(connection, `mbx reservation endpoint ${connection.endpoint}: ${event.message}`, event.code, []);
|
|
182
|
+
case 'close':
|
|
183
|
+
return close(connection, `mbx reservation endpoint ${connection.endpoint} closed the connection`, null, []);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function without(entries, id) {
|
|
187
|
+
const rest = new Map(entries);
|
|
188
|
+
rest.delete(id);
|
|
189
|
+
return rest;
|
|
190
|
+
}
|
|
191
|
+
function unreferenced(entries) {
|
|
192
|
+
return entries.size === 0 ? [{ do: 'unref' }] : [];
|
|
193
|
+
}
|
|
194
|
+
function refused(connection, id, message) {
|
|
195
|
+
return { do: 'answer', id, answer: { ok: false, refusal: { endpoint: connection.endpoint, errno: null, message } } };
|
|
196
|
+
}
|
|
197
|
+
/** `line` as a reply, or null when it is none: typia's parse validates what `JSON.parse` returns and throws what it throws. */
|
|
198
|
+
function replyOf(line) {
|
|
199
|
+
try {
|
|
200
|
+
const parsed = parseReply(line);
|
|
201
|
+
return parsed.success ? parsed.data : null;
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/** Each whole line of `connection.unread` in turn, until none is left or one ends the connection. */
|
|
208
|
+
function read(connection, done) {
|
|
209
|
+
const end = connection.unread.indexOf('\n');
|
|
210
|
+
if (end === -1)
|
|
211
|
+
return [connection, done];
|
|
212
|
+
const line = connection.unread.slice(0, end);
|
|
213
|
+
const rest = { ...connection, unread: connection.unread.slice(end + 1) };
|
|
214
|
+
const reply = replyOf(line);
|
|
215
|
+
if (reply === null) {
|
|
216
|
+
const why = `mbx reservation endpoint ${connection.endpoint} answered ${JSON.stringify(line)}, which is no reply`;
|
|
217
|
+
return close(rest, why, null, done);
|
|
218
|
+
}
|
|
219
|
+
const [next, effects] = answer(rest, reply);
|
|
220
|
+
return next.closed === null ? read(next, [...done, ...effects]) : [next, [...done, ...effects]];
|
|
221
|
+
}
|
|
222
|
+
function answer(connection, reply) {
|
|
223
|
+
const { endpoint } = connection;
|
|
224
|
+
if (reply.type === 'error') {
|
|
225
|
+
return close(connection, `mbx reservation endpoint ${endpoint} closed this connection: ${reply.error}`, null, []);
|
|
226
|
+
}
|
|
227
|
+
const entry = connection.entries.get(reply.id);
|
|
228
|
+
// Released before its answer arrived: the endpoint drops what it won.
|
|
229
|
+
if (entry === undefined)
|
|
230
|
+
return [connection, []];
|
|
231
|
+
if (entry === 'held') {
|
|
232
|
+
return close(connection, `mbx reservation endpoint ${endpoint} answered reservation ${reply.id} twice`, null, []);
|
|
233
|
+
}
|
|
234
|
+
if (reply.type === 'granted') {
|
|
235
|
+
return [
|
|
236
|
+
{ ...connection, entries: new Map(connection.entries).set(reply.id, 'held') },
|
|
237
|
+
[{ do: 'answer', id: reply.id, answer: { ok: true, cpus: reply.cpus } }],
|
|
238
|
+
];
|
|
239
|
+
}
|
|
240
|
+
const entries = without(connection.entries, reply.id);
|
|
241
|
+
return [{ ...connection, entries }, [refused(connection, reply.id, reply.error), ...unreferenced(entries)]];
|
|
242
|
+
}
|
|
243
|
+
/** End the connection: what waits is refused by its end, what is held is lost to it. */
|
|
244
|
+
function close(connection, message, errno, done) {
|
|
245
|
+
const refusal = { endpoint: connection.endpoint, errno, message };
|
|
246
|
+
const settled = Array.from(connection.entries, ([id, entry]) => entry === 'waiting' ? { do: 'answer', id, answer: { ok: false, refusal } } : { do: 'lose', id, why: message });
|
|
247
|
+
return [{ ...connection, unread: '', entries: new Map(), closed: refusal }, [...done, ...settled, { do: 'hang-up' }]];
|
|
248
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-cpu-pool.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/run-cpu-pool.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAGtH,OAAO,EAAkB,KAAK,gBAAgB,EAAsC,MAAM,kBAAkB,CAAC;AAsD7G;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM5F;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,IAAI,CAAC,wBAAwB,EAAE,IAAI,CAAC,EAC7C,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,KAAK,GAAE,MAA+B,EACtC,UAAU,GAAE,MAAM,OAAO,CAAC,gBAAgB,CAAiB,GAC1D,OAAO,CAAC,IAAI,CAAC,CAoBf;
|
|
1
|
+
{"version":3,"file":"run-cpu-pool.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/run-cpu-pool.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAGtH,OAAO,EAAkB,KAAK,gBAAgB,EAAsC,MAAM,kBAAkB,CAAC;AAsD7G;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM5F;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,IAAI,CAAC,wBAAwB,EAAE,IAAI,CAAC,EAC7C,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,KAAK,GAAE,MAA+B,EACtC,UAAU,GAAE,MAAM,OAAO,CAAC,gBAAgB,CAAiB,GAC1D,OAAO,CAAC,IAAI,CAAC,CAoBf;AAsED,uEAAuE;AACvE,wBAAsB,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,yBAAyB,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAUnG"}
|
|
@@ -139,6 +139,9 @@ function servePoolThread(tokens, memory) {
|
|
|
139
139
|
now.served({ ok: false, error: report.error });
|
|
140
140
|
}
|
|
141
141
|
else if (now.kind === 'closing' && report.kind === 'closed') {
|
|
142
|
+
// What the run's pool left idle beside starved holds, said with the run's end.
|
|
143
|
+
if (report.idle !== null)
|
|
144
|
+
process.stderr.write(report.idle);
|
|
142
145
|
finish(report.outcome);
|
|
143
146
|
now.closed(report.outcome);
|
|
144
147
|
}
|
|
@@ -107,13 +107,15 @@ export declare function withInvocationFlag(command: string, invocation: RegExp,
|
|
|
107
107
|
/**
|
|
108
108
|
* Size the runner to the lesser of its bounded demand and grant, keeping the test-thread ceilings. Rewrite named flags
|
|
109
109
|
* so they cannot outrank that size. `CPU_TOKENS_ENV` still reports the actual held grant.
|
|
110
|
+
* A `gated` nextest runner starts every thread of its ask instead: each case takes its token at the leaf's gate
|
|
111
|
+
* (case-gate.ts; specs/cowshed/05_gateway.md, "A case starts on a core", Inside a hold).
|
|
110
112
|
*
|
|
111
113
|
* Cargo's rustc count is the pool's: the executor's sub-pool exports its jobserver fifo, so no `CARGO_BUILD_JOBS`
|
|
112
114
|
* comes from the grant (specs/cowshed/05_gateway.md, "Cargo reads its holder's jobserver"). Test threads take no
|
|
113
115
|
* jobserver token, so a cargo build's test threads are its size, and a process's, whose script may start Cargo, are
|
|
114
116
|
* its whole held grant.
|
|
115
117
|
*/
|
|
116
|
-
export declare function sizeRunner(demand: Demand, command: string, tokens: number): {
|
|
118
|
+
export declare function sizeRunner(demand: Demand, command: string, tokens: number, gated?: boolean): {
|
|
117
119
|
command: string;
|
|
118
120
|
env: Record<string, string>;
|
|
119
121
|
};
|
|
@@ -121,14 +123,16 @@ export declare function sizeRunner(demand: Demand, command: string, tokens: numb
|
|
|
121
123
|
* The shell statements that run first in a reserved leaf's reservation and size its runner to the grant, which only
|
|
122
124
|
* the command learns as it starts: `CPU_TOKENS_ENV` becomes the cores mbx granted (`GRANTED_CPUS_ENV`), never more
|
|
123
125
|
* than the leaf asked for (`WANT_ENV`, set before it reserved). The test-thread variables a sizing sets follow from it,
|
|
124
|
-
* under their inherited ceilings, outranking the target's own as a numeric grant's do (`sizeRunner`).
|
|
126
|
+
* under their inherited ceilings, outranking the target's own as a numeric grant's do (`sizeRunner`). A `gated` nextest
|
|
127
|
+
* leaf's runner starts every thread of its ask instead: each case takes its core at the leaf's gate (case-gate.ts;
|
|
128
|
+
* specs/cowshed/05_gateway.md, "A case starts on a core").
|
|
125
129
|
*/
|
|
126
|
-
export declare function grantedSizing(demand: ReservedDemand): string;
|
|
130
|
+
export declare function grantedSizing(demand: ReservedDemand, gated: boolean): string;
|
|
127
131
|
/**
|
|
128
132
|
* `command` with a reserved runner's named count read from its grant, `CPU_TOKENS_ENV` as `grantedSizing` sets it,
|
|
129
|
-
* where the runner's shell runs it; the runner then runs on all it holds.
|
|
133
|
+
* where the runner's shell runs it; the runner then runs on all it holds. A `gated` nextest runner's count is its ask.
|
|
130
134
|
*/
|
|
131
|
-
export declare function sizeRunnerToGrant(demand: ReservedDemand, command: string): string;
|
|
135
|
+
export declare function sizeRunnerToGrant(demand: ReservedDemand, command: string, gated: boolean): string;
|
|
132
136
|
/**
|
|
133
137
|
* The count `CPU_TOKENS_ENV` names, as a positive safe integer, or `null` when absent or malformed. It is
|
|
134
138
|
* descriptor input only: a count proves nothing about a live pool and grants nothing. It is a ceiling the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner-sizing.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/runner-sizing.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,kGAAkG;AAClG,MAAM,MAAM,UAAU;AACpB,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KAAK,EAAE,MAAM,EACb,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,EACtC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,GACvC,MAAM,CAiCR;AAuED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAqBpG;AAOD;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,OAAO,GACX,MAAM,CAKR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,KAAK,UAAQ,GACZ;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAoDlD;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAuB5E;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAcjG;AASD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAM7E"}
|
|
@@ -201,21 +201,23 @@ export function withInvocationFlag(command, invocation, flag, value, add) {
|
|
|
201
201
|
/**
|
|
202
202
|
* Size the runner to the lesser of its bounded demand and grant, keeping the test-thread ceilings. Rewrite named flags
|
|
203
203
|
* so they cannot outrank that size. `CPU_TOKENS_ENV` still reports the actual held grant.
|
|
204
|
+
* A `gated` nextest runner starts every thread of its ask instead: each case takes its token at the leaf's gate
|
|
205
|
+
* (case-gate.ts; specs/cowshed/05_gateway.md, "A case starts on a core", Inside a hold).
|
|
204
206
|
*
|
|
205
207
|
* Cargo's rustc count is the pool's: the executor's sub-pool exports its jobserver fifo, so no `CARGO_BUILD_JOBS`
|
|
206
208
|
* comes from the grant (specs/cowshed/05_gateway.md, "Cargo reads its holder's jobserver"). Test threads take no
|
|
207
209
|
* jobserver token, so a cargo build's test threads are its size, and a process's, whose script may start Cargo, are
|
|
208
210
|
* its whole held grant.
|
|
209
211
|
*/
|
|
210
|
-
export function sizeRunner(demand, command, tokens) {
|
|
212
|
+
export function sizeRunner(demand, command, tokens, gated = false) {
|
|
211
213
|
const runnerCount = Math.min(tokens, demand.want);
|
|
212
214
|
const count = String(runnerCount);
|
|
213
215
|
const held = String(tokens);
|
|
214
216
|
switch (demand.kind) {
|
|
215
217
|
case 'nextest':
|
|
216
218
|
return {
|
|
217
|
-
command: command.replace(TEST_THREADS, `--test-threads=${count}`),
|
|
218
|
-
env: { [CPU_TOKENS_ENV]: held, NEXTEST_TEST_THREADS: count },
|
|
219
|
+
command: command.replace(TEST_THREADS, `--test-threads=${gated ? demand.want : count}`),
|
|
220
|
+
env: { [CPU_TOKENS_ENV]: held, NEXTEST_TEST_THREADS: gated ? String(demand.want) : count },
|
|
219
221
|
};
|
|
220
222
|
case 'bun-parallel':
|
|
221
223
|
return { command: command.replace(BUN_PARALLEL, `--parallel=${count}`), env: { [CPU_TOKENS_ENV]: held } };
|
|
@@ -264,9 +266,11 @@ export function sizeRunner(demand, command, tokens) {
|
|
|
264
266
|
* The shell statements that run first in a reserved leaf's reservation and size its runner to the grant, which only
|
|
265
267
|
* the command learns as it starts: `CPU_TOKENS_ENV` becomes the cores mbx granted (`GRANTED_CPUS_ENV`), never more
|
|
266
268
|
* than the leaf asked for (`WANT_ENV`, set before it reserved). The test-thread variables a sizing sets follow from it,
|
|
267
|
-
* under their inherited ceilings, outranking the target's own as a numeric grant's do (`sizeRunner`).
|
|
269
|
+
* under their inherited ceilings, outranking the target's own as a numeric grant's do (`sizeRunner`). A `gated` nextest
|
|
270
|
+
* leaf's runner starts every thread of its ask instead: each case takes its core at the leaf's gate (case-gate.ts;
|
|
271
|
+
* specs/cowshed/05_gateway.md, "A case starts on a core").
|
|
268
272
|
*/
|
|
269
|
-
export function grantedSizing(demand) {
|
|
273
|
+
export function grantedSizing(demand, gated) {
|
|
270
274
|
const asked = `$${WANT_ENV}`;
|
|
271
275
|
const named = `$${GRANTED_CPUS_ENV}`;
|
|
272
276
|
const tokens = `$${CPU_TOKENS_ENV}`;
|
|
@@ -274,7 +278,7 @@ export function grantedSizing(demand) {
|
|
|
274
278
|
const statements = [`export ${CPU_TOKENS_ENV}="$(( ${named} < ${asked} ? ${named} : ${asked} ))"`];
|
|
275
279
|
switch (demand.kind) {
|
|
276
280
|
case 'nextest':
|
|
277
|
-
statements.push(`export NEXTEST_TEST_THREADS="${tokens}"`);
|
|
281
|
+
statements.push(`export NEXTEST_TEST_THREADS="${gated ? asked : tokens}"`);
|
|
278
282
|
break;
|
|
279
283
|
case 'process':
|
|
280
284
|
// A process's script may start Cargo, whose test threads take no jobserver token: its whole grant.
|
|
@@ -288,13 +292,13 @@ export function grantedSizing(demand) {
|
|
|
288
292
|
}
|
|
289
293
|
/**
|
|
290
294
|
* `command` with a reserved runner's named count read from its grant, `CPU_TOKENS_ENV` as `grantedSizing` sets it,
|
|
291
|
-
* where the runner's shell runs it; the runner then runs on all it holds.
|
|
295
|
+
* where the runner's shell runs it; the runner then runs on all it holds. A `gated` nextest runner's count is its ask.
|
|
292
296
|
*/
|
|
293
|
-
export function sizeRunnerToGrant(demand, command) {
|
|
297
|
+
export function sizeRunnerToGrant(demand, command, gated) {
|
|
294
298
|
const granted = `\${${CPU_TOKENS_ENV}}`;
|
|
295
299
|
switch (demand.kind) {
|
|
296
300
|
case 'nextest':
|
|
297
|
-
return command.replace(TEST_THREADS, `--test-threads=${granted}`);
|
|
301
|
+
return command.replace(TEST_THREADS, `--test-threads=${gated ? `\${${WANT_ENV}}` : granted}`);
|
|
298
302
|
case 'bun-parallel':
|
|
299
303
|
return command.replace(BUN_PARALLEL, `--parallel=${granted}`);
|
|
300
304
|
case 'stryker': {
|
|
@@ -30,8 +30,8 @@ export interface BoundedExecCommand {
|
|
|
30
30
|
killAfterMs?: number;
|
|
31
31
|
/**
|
|
32
32
|
* A compiler-fixture producer for `command`: a shell command run first, in the same cwd and environment, inside
|
|
33
|
-
* the run's CPU grant; under mbx
|
|
34
|
-
*
|
|
33
|
+
* the run's CPU grant; under mbx's pool before its leaf's reservation, as pooled work whose compilers mbx admits one
|
|
34
|
+
* by one, since a reservation is never held across a build.
|
|
35
35
|
* Its whole life is a lifecycle build interval — the progress bound does not run during it, as it does not run
|
|
36
36
|
* during a `cargo test` build. Its failure fails the run; `command` starts only after it exits 0.
|
|
37
37
|
*
|