@smoothbricks/nx-plugin 0.4.26 → 0.4.28
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 +994 -117
- package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
- package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
- package/dist/bin/smoo-nx-bound-failures.js +31 -0
- package/dist/bin/smoo-nx-cargo-hash.js +28 -3
- package/dist/bin/smoo-nx-exec.js +15 -73
- package/dist/bin/smoo-nx-failures.d.ts +3 -0
- package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
- package/dist/bin/smoo-nx-failures.js +3 -0
- package/dist/bin/smoo-nx-nextest-extract.js +3 -2
- package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
- package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
- package/dist/bin/smoo-nx-test-walks.js +34 -0
- package/dist/bounded-test-policy.d.ts +7 -1
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +101 -40
- package/dist/build-state-output-policy.d.ts +25 -0
- package/dist/build-state-output-policy.d.ts.map +1 -0
- package/dist/build-state-output-policy.js +64 -0
- package/dist/cargo-closure-input.d.ts +3 -2
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +16 -15
- package/dist/cargo-dev-profile.d.ts +37 -0
- package/dist/cargo-dev-profile.d.ts.map +1 -0
- package/dist/cargo-dev-profile.js +108 -0
- package/dist/cargo-source-hash.d.ts +43 -6
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +309 -73
- package/dist/cargo-toolchain-policy.d.ts +4 -0
- package/dist/cargo-toolchain-policy.d.ts.map +1 -1
- package/dist/cargo-toolchain-policy.js +5 -0
- package/dist/cargo-workspace.d.ts +101 -5
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +291 -10
- package/dist/cross-check-policy.d.ts +21 -3
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +24 -6
- package/dist/disk-command-policy.d.ts +7 -0
- package/dist/disk-command-policy.d.ts.map +1 -0
- package/dist/disk-command-policy.js +98 -0
- package/dist/ensure-built-receipt.d.ts +25 -0
- package/dist/ensure-built-receipt.d.ts.map +1 -0
- package/dist/ensure-built-receipt.js +261 -0
- package/dist/ensure-built-witness.d.ts +57 -0
- package/dist/ensure-built-witness.d.ts.map +1 -0
- package/dist/ensure-built-witness.js +412 -0
- package/dist/ensure-built.d.ts +207 -12
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +576 -202
- package/dist/eslint-file-set.d.ts +7 -0
- package/dist/eslint-file-set.d.ts.map +1 -0
- package/dist/eslint-file-set.js +12 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-pool.js +379 -0
- package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
- package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
- package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
- package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
- package/dist/executors/bounded-exec/disk-lease.js +91 -0
- package/dist/executors/bounded-exec/executor.d.ts +45 -2
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +447 -52
- package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
- package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
- package/dist/executors/bounded-exec/gateway-lease.js +143 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
- package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
- package/dist/executors/bounded-exec/progress.d.ts +35 -0
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
- package/dist/executors/bounded-exec/progress.js +79 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
- package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
- package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp.js +1528 -0
- package/dist/executors/bounded-exec/schema.d.ts +29 -11
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.d.ts +162 -0
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
- package/dist/executors/bounded-exec/verdict.js +318 -0
- package/dist/executors/shard-timings/executor.d.ts +14 -0
- package/dist/executors/shard-timings/executor.d.ts.map +1 -0
- package/dist/executors/shard-timings/executor.js +25 -0
- package/dist/executors/shard-timings/schema.d.ts +4 -0
- package/dist/executors/shard-timings/schema.d.ts.map +1 -0
- package/dist/executors/shard-timings/schema.js +1 -0
- package/dist/failure-summary.d.ts +5 -0
- package/dist/failure-summary.d.ts.map +1 -0
- package/dist/failure-summary.js +118 -0
- package/dist/generators/create-package/generator.d.ts.map +1 -1
- package/dist/generators/create-package/generator.js +6 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +370 -138
- package/dist/managed-files/ci-workflow.d.ts +13 -0
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +44 -13
- package/dist/managed-files/files.d.ts +7 -1
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +62 -8
- package/dist/managed-files/json-edit.d.ts +21 -0
- package/dist/managed-files/json-edit.d.ts.map +1 -0
- package/dist/managed-files/json-edit.js +295 -0
- package/dist/managed-files/managed-format.d.ts +33 -1
- package/dist/managed-files/managed-format.d.ts.map +1 -1
- package/dist/managed-files/managed-format.js +82 -2
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
- package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/managed-files/publish-workflow.js +231 -48
- package/dist/managed-files/tree.d.ts +5 -0
- package/dist/managed-files/tree.d.ts.map +1 -1
- package/dist/managed-files/tree.js +5 -3
- package/dist/manifest-hash.d.ts.map +1 -1
- package/dist/manifest-hash.js +2 -5
- package/dist/nextest-code-bound.d.ts +62 -0
- package/dist/nextest-code-bound.d.ts.map +1 -0
- package/dist/nextest-code-bound.js +154 -0
- package/dist/nextest-extraction.d.ts +24 -8
- package/dist/nextest-extraction.d.ts.map +1 -1
- package/dist/nextest-extraction.js +42 -7
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +3 -5
- package/dist/release-config-policy.d.ts.map +1 -1
- package/dist/release-config-policy.js +3 -5
- package/dist/runtime-input.d.ts +14 -0
- package/dist/runtime-input.d.ts.map +1 -0
- package/dist/runtime-input.js +15 -0
- package/dist/rust-tokens.d.ts +11 -0
- package/dist/rust-tokens.d.ts.map +1 -0
- package/dist/rust-tokens.js +81 -0
- package/dist/task-results.d.ts +6 -0
- package/dist/task-results.d.ts.map +1 -0
- package/dist/task-results.js +61 -0
- package/dist/test-program.d.ts +54 -0
- package/dist/test-program.d.ts.map +1 -0
- package/dist/test-program.js +292 -0
- package/dist/test-timings.d.ts +71 -0
- package/dist/test-timings.d.ts.map +1 -0
- package/dist/test-timings.js +393 -0
- package/dist/test-walk-policy.d.ts +103 -0
- package/dist/test-walk-policy.d.ts.map +1 -0
- package/dist/test-walk-policy.js +657 -0
- package/dist/testing.d.ts +177 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +824 -0
- package/dist/type-guards.d.ts +3 -0
- package/dist/type-guards.d.ts.map +1 -0
- package/dist/type-guards.js +4 -0
- package/dist/typecheck-test-policy.d.ts +8 -5
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +113 -100
- package/dist/workspace-config-policy.d.ts +8 -0
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +175 -63
- package/dist/workspace-index.d.ts +12 -0
- package/dist/workspace-index.d.ts.map +1 -0
- package/dist/workspace-index.js +17 -0
- package/dist/workspace-manifest.d.ts +37 -0
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/executors.json +5 -0
- package/loader.js +13 -11
- package/managed/raw/envrc +33 -67
- package/managed/raw/git-format-staged.yml +30 -35
- package/managed/raw/patches/nx@23.2.1.patch +3484 -0
- package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
- package/managed/raw/tooling/direnv/developer-links.ts +569 -11
- package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -93
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
- package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
- package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
- package/managed/raw/tooling/direnv/repo-path +14 -2
- package/managed/raw/tooling/direnv/setup-environment.ts +1146 -159
- package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
- package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
- package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
- package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
- package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
- package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
- package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
- package/managed/templates/github/actions/cache-nx/action.yml +1 -1
- package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
- package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
- package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
- package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
- package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
- package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
- package/managed/templates/github/workflows/managed-files.yml +1 -2
- package/nextest.toml +8 -41
- package/package.json +74 -12
- package/runtime-input.sh +81 -0
- package/src/__tests__/counted-cargo.ts +33 -14
- package/src/__tests__/fixture-nx-env.ts +111 -46
- package/src/__tests__/progress-clock.ts +43 -0
- package/src/__tests__/runtime-input.ts +23 -0
- package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
- package/src/bin/smoo-nx-bound-failures.ts +33 -0
- package/src/bin/smoo-nx-cargo-hash.ts +28 -3
- package/src/bin/smoo-nx-exec.ts +16 -74
- package/src/bin/smoo-nx-failures.ts +4 -0
- package/src/bin/smoo-nx-nextest-extract.ts +3 -2
- package/src/bin/smoo-nx-test-walks.ts +42 -0
- package/src/bounded-test-policy.test.ts +268 -21
- package/src/bounded-test-policy.ts +114 -42
- package/src/build-state-output-policy.test.ts +115 -0
- package/src/build-state-output-policy.ts +90 -0
- package/src/bun-bootstrap.test.ts +57 -3
- package/src/bun-file-packages.test.ts +47 -0
- package/src/cargo-closure-input.test.ts +138 -66
- package/src/cargo-closure-input.ts +17 -15
- package/src/cargo-dev-profile.ts +137 -0
- package/src/cargo-resolve-cache.test.ts +70 -1
- package/src/cargo-source-hash.test.ts +193 -97
- package/src/cargo-source-hash.ts +345 -68
- package/src/cargo-toolchain-policy.ts +6 -0
- package/src/cargo-workspace.test.ts +320 -0
- package/src/cargo-workspace.ts +336 -10
- package/src/cross-check-policy.test.ts +59 -1
- package/src/cross-check-policy.ts +25 -6
- package/src/disk-command-policy.test.ts +61 -0
- package/src/disk-command-policy.ts +107 -0
- package/src/ensure-built-receipt.test.ts +184 -0
- package/src/ensure-built-receipt.ts +263 -0
- package/src/ensure-built-witness.test.ts +344 -0
- package/src/ensure-built-witness.ts +252 -0
- package/src/ensure-built.test.ts +1036 -578
- package/src/ensure-built.ts +820 -224
- package/src/eslint-file-set.ts +9 -0
- package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
- package/src/executors/bounded-exec/cpu-pool.ts +417 -0
- package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
- package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
- package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
- package/src/executors/bounded-exec/disk-lease.ts +139 -0
- package/src/executors/bounded-exec/executor-host.test.ts +778 -0
- package/src/executors/bounded-exec/executor.test.ts +1116 -63
- package/src/executors/bounded-exec/executor.ts +565 -67
- package/src/executors/bounded-exec/gateway-lease.ts +176 -0
- package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
- package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
- package/src/executors/bounded-exec/progress.test.ts +79 -0
- package/src/executors/bounded-exec/progress.ts +118 -0
- package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
- package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
- package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
- package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
- package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
- package/src/executors/bounded-exec/ram-temp.ts +1918 -0
- package/src/executors/bounded-exec/schema.json +11 -5
- package/src/executors/bounded-exec/schema.ts +27 -11
- package/src/executors/bounded-exec/verdict.test.ts +440 -0
- package/src/executors/bounded-exec/verdict.ts +433 -0
- package/src/executors/shard-timings/executor.ts +36 -0
- package/src/executors/shard-timings/schema.json +21 -0
- package/src/executors/shard-timings/schema.ts +4 -0
- package/src/failure-summary.ts +119 -0
- package/src/generators/bounded-test-targets/generator.test.ts +4 -4
- package/src/generators/bun-test-tracing/generator.test.ts +2 -2
- package/src/generators/create-package/generator.test.ts +6 -0
- package/src/generators/create-package/generator.ts +6 -2
- package/src/host-controller-wiring.test.ts +31 -0
- package/src/index.test.ts +909 -295
- package/src/index.ts +441 -143
- package/src/linked-snapshots.nx.test.ts +172 -0
- package/src/managed-files/ci-workflow.ts +54 -13
- package/src/managed-files/files.ts +65 -9
- package/src/managed-files/forgejo-artifact.test.ts +395 -0
- package/src/managed-files/generator.test.ts +60 -1
- package/src/managed-files/json-edit.test.ts +216 -0
- package/src/managed-files/json-edit.ts +290 -0
- package/src/managed-files/managed-format-json.test.ts +308 -0
- package/src/managed-files/managed-format.ts +90 -2
- package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
- package/src/managed-files/publish-workflow.ts +285 -67
- package/src/managed-files/repo-path.test.ts +129 -0
- package/src/managed-files/trace-db-artifact.test.ts +7 -0
- package/src/managed-files/tree.ts +11 -3
- package/src/manifest-hash.ts +2 -6
- package/src/nextest-code-bound.test.ts +155 -0
- package/src/nextest-code-bound.ts +195 -0
- package/src/nextest-extraction.test.ts +37 -5
- package/src/nextest-extraction.ts +51 -9
- package/src/nextest-partitions.test.ts +427 -82
- package/src/nx-cache-bound.test.ts +5 -10
- package/src/nx-cache-restore-mtime.test.ts +170 -0
- package/src/nx-daemon-claim.test.ts +277 -0
- package/src/nx-daemon-idle-cpu.test.ts +81 -0
- package/src/nx-daemon-idle-policy.test.ts +51 -0
- package/src/nx-daemon-ignore-files.test.ts +210 -0
- package/src/nx-daemon-root-normalization.test.ts +105 -0
- package/src/nx-daemon-validity.test.ts +925 -0
- package/src/nx-dot-input-policy.test.ts +353 -0
- package/src/nx-failure-life-cycles.test.ts +207 -0
- package/src/nx-files-archive-racy.test.ts +97 -0
- package/src/nx-foreign-workspace-env.test.ts +329 -0
- package/src/nx-incomplete-run-summary.test.ts +70 -0
- package/src/nx-plugin-load-errors.test.ts +120 -0
- package/src/nx-project-resolution-cache.test.ts +176 -0
- package/src/nx-raw-inputs.test.ts +166 -0
- package/src/nx-resident-graph-workers.test.ts +7 -16
- package/src/nx-run-information.test.ts +118 -0
- package/src/nx-skipped-task-exit.test.ts +180 -0
- package/src/nx-state-location.test.ts +63 -0
- package/src/nx-store-resolution.test.ts +26 -25
- package/src/nx-task-graph-cycles.test.ts +148 -0
- package/src/nx-task-output-lease.test.ts +414 -0
- package/src/nx-use-local.test.ts +103 -0
- package/src/package-target-policy.ts +3 -6
- package/src/release-config-policy.ts +3 -6
- package/src/runtime-input.test.ts +215 -0
- package/src/runtime-input.ts +17 -0
- package/src/rust-tokens.ts +78 -0
- package/src/serial-group-wiring.test.ts +326 -0
- package/src/task-history-namespace.test.ts +87 -89
- package/src/task-results.test.ts +226 -0
- package/src/task-results.ts +75 -0
- package/src/test-program.test.ts +303 -0
- package/src/test-program.ts +341 -0
- package/src/test-timings.test.ts +240 -0
- package/src/test-timings.ts +311 -0
- package/src/test-walk-policy.test.ts +585 -0
- package/src/test-walk-policy.ts +731 -0
- package/src/testing.test.ts +509 -0
- package/src/testing.ts +922 -0
- package/src/type-guards.ts +4 -0
- package/src/typecheck-test-policy.test.ts +496 -11
- package/src/typecheck-test-policy.ts +137 -103
- package/src/workspace-config-policy.test.ts +212 -13
- package/src/workspace-config-policy.ts +101 -73
- package/src/workspace-index.ts +18 -0
- package/src/workspace-manifest.ts +41 -0
- package/test-timings.json +85 -30
- package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -665
- package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import typia from 'typia';
|
|
2
|
+
|
|
3
|
+
/** The exact command and sources source-aware ESLint inference retains for cache inspectors. */
|
|
4
|
+
export interface EslintFileSet {
|
|
5
|
+
readonly command: string;
|
|
6
|
+
readonly files: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const isEslintFileSet = typia.createEquals<EslintFileSet>();
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'bun:test';
|
|
2
|
+
import { chmodSync, existsSync, mkdirSync, readdirSync, rmSync, statSync } from 'node:fs';
|
|
3
|
+
import { writeFile } from 'node:fs/promises';
|
|
4
|
+
import { connect, type Socket } from 'node:net';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import typia from 'typia';
|
|
7
|
+
import { ownedSocketDirectory, socketNamespace } from '../../testing.js';
|
|
8
|
+
import {
|
|
9
|
+
CPU_POOL_ENV,
|
|
10
|
+
type CpuPool,
|
|
11
|
+
createCpuPool,
|
|
12
|
+
type InheritedCpuPool,
|
|
13
|
+
readInheritedCpuPool,
|
|
14
|
+
takeParentCpuTokens,
|
|
15
|
+
} from './cpu-pool.js';
|
|
16
|
+
import { CPU_TOKENS_ENV, type TokenGrant } from './cpu-tokens.js';
|
|
17
|
+
|
|
18
|
+
/** The pool's replies as the wire carries them, one line each. */
|
|
19
|
+
type PoolReply =
|
|
20
|
+
| { ok: true; lease: 'queued' }
|
|
21
|
+
| { ok: true; lease: 'granted'; tokens: number; pool?: string }
|
|
22
|
+
| { ok: false; code: 'invalid-request'; error: string };
|
|
23
|
+
|
|
24
|
+
const parseReply = typia.json.createAssertParse<PoolReply>();
|
|
25
|
+
|
|
26
|
+
type Granted = Extract<TokenGrant, { granted: true }>;
|
|
27
|
+
|
|
28
|
+
/** A raw child connection: its replies come one line at a time, and `closed` resolves when it ends. */
|
|
29
|
+
interface Child {
|
|
30
|
+
readonly socket: Socket;
|
|
31
|
+
readonly closed: Promise<void>;
|
|
32
|
+
next(): Promise<PoolReply>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface Opened {
|
|
36
|
+
readonly pool: CpuPool;
|
|
37
|
+
readonly parent: InheritedCpuPool;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const NEVER: Promise<void> = new Promise<void>(() => {});
|
|
41
|
+
const QUEUED: PoolReply = { ok: true, lease: 'queued' };
|
|
42
|
+
const pools: CpuPool[] = [];
|
|
43
|
+
const sockets: Socket[] = [];
|
|
44
|
+
const directories: string[] = [];
|
|
45
|
+
|
|
46
|
+
afterEach(async () => {
|
|
47
|
+
for (const socket of sockets.splice(0)) {
|
|
48
|
+
socket.destroy();
|
|
49
|
+
}
|
|
50
|
+
for (const pool of pools.splice(0)) {
|
|
51
|
+
// Every pool a test leaves open is closed here, and its outcome is asserted, not dropped.
|
|
52
|
+
expect(await pool.close()).toEqual({ ok: true });
|
|
53
|
+
}
|
|
54
|
+
for (const directory of directories.splice(0)) {
|
|
55
|
+
rmSync(directory, { recursive: true, force: true });
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/** Make a pool of `tokens` and read its endpoint back through the same path a child uses. */
|
|
60
|
+
async function openPool(tokens: number, closed: Promise<void> = NEVER): Promise<Opened> {
|
|
61
|
+
const made = await createCpuPool(tokens, closed);
|
|
62
|
+
if (!made.ok) {
|
|
63
|
+
throw new Error(made.error);
|
|
64
|
+
}
|
|
65
|
+
pools.push(made.pool);
|
|
66
|
+
const parent = readInheritedCpuPool(made.pool.environment);
|
|
67
|
+
if (parent === null) {
|
|
68
|
+
throw new Error('the pool environment names no endpoint');
|
|
69
|
+
}
|
|
70
|
+
return { pool: made.pool, parent };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** A granted lease for a child that the pool must admit: a refusal here is a test failure. */
|
|
74
|
+
async function takeOrThrow(parent: InheritedCpuPool, want: number): Promise<Granted> {
|
|
75
|
+
const grant = await takeParentCpuTokens(parent, want, 8);
|
|
76
|
+
if (!grant.granted) {
|
|
77
|
+
throw new Error(`the pool refused ${want} tokens: ${grant.reason}`);
|
|
78
|
+
}
|
|
79
|
+
return grant;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The count a child is granted for `want` at `cores`. The grant is released and its close awaited before
|
|
84
|
+
* returning, so the next ask starts from the pool as this one left it.
|
|
85
|
+
*/
|
|
86
|
+
async function grantedFor(parent: InheritedCpuPool, want: number, cores: number): Promise<number> {
|
|
87
|
+
const grant = await takeParentCpuTokens(parent, want, cores);
|
|
88
|
+
if (!grant.granted) {
|
|
89
|
+
throw new Error(`the pool refused ${want} tokens: ${grant.reason}`);
|
|
90
|
+
}
|
|
91
|
+
grant.release();
|
|
92
|
+
await grant.closed;
|
|
93
|
+
return grant.tokens;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The pool directories in the socket namespace right now; a closed pool leaves none behind. */
|
|
97
|
+
const cpuPoolDirectories = (): string[] =>
|
|
98
|
+
readdirSync(socketNamespace().directory)
|
|
99
|
+
.filter((name) => name.startsWith('cpu-pool-'))
|
|
100
|
+
.sort();
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* A raw child: connects, writes `request` as its one line, and reads the replies. The child's
|
|
104
|
+
* socket errors are recorded and surfaced by `next()`, never dropped.
|
|
105
|
+
*/
|
|
106
|
+
function childOf(endpoint: string, request: string): Child {
|
|
107
|
+
const socket = connect(endpoint);
|
|
108
|
+
sockets.push(socket);
|
|
109
|
+
socket.setEncoding('utf8');
|
|
110
|
+
const lines: string[] = [];
|
|
111
|
+
let buffered = '';
|
|
112
|
+
let ended = false;
|
|
113
|
+
let failure: Error | undefined;
|
|
114
|
+
let wake: (() => void) | undefined;
|
|
115
|
+
const rouse = (): void => {
|
|
116
|
+
const resume = wake;
|
|
117
|
+
wake = undefined;
|
|
118
|
+
resume?.();
|
|
119
|
+
};
|
|
120
|
+
socket.on('connect', () => {
|
|
121
|
+
socket.write(`${request}\n`);
|
|
122
|
+
});
|
|
123
|
+
socket.on('data', (chunk: string) => {
|
|
124
|
+
buffered += chunk;
|
|
125
|
+
for (let newline = buffered.indexOf('\n'); newline !== -1; newline = buffered.indexOf('\n')) {
|
|
126
|
+
lines.push(buffered.slice(0, newline));
|
|
127
|
+
buffered = buffered.slice(newline + 1);
|
|
128
|
+
}
|
|
129
|
+
rouse();
|
|
130
|
+
});
|
|
131
|
+
socket.on('error', (error: Error) => {
|
|
132
|
+
failure = error;
|
|
133
|
+
rouse();
|
|
134
|
+
});
|
|
135
|
+
const closed = new Promise<void>((resolve) => {
|
|
136
|
+
socket.once('close', () => {
|
|
137
|
+
ended = true;
|
|
138
|
+
rouse();
|
|
139
|
+
resolve();
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
socket,
|
|
144
|
+
closed,
|
|
145
|
+
async next(): Promise<PoolReply> {
|
|
146
|
+
for (;;) {
|
|
147
|
+
const line = lines.shift();
|
|
148
|
+
if (line !== undefined) {
|
|
149
|
+
return parseReply(line);
|
|
150
|
+
}
|
|
151
|
+
if (ended) {
|
|
152
|
+
throw (
|
|
153
|
+
failure ?? new Error(`the pool closed before replying to ${request.slice(0, 80)} (${request.length} bytes)`)
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
await new Promise<void>((resolve) => {
|
|
157
|
+
wake = resolve;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Read a child process's stdout until `marker` has been printed. */
|
|
165
|
+
async function untilLine(stream: ReadableStream<Uint8Array>, marker: string): Promise<void> {
|
|
166
|
+
const reader = stream.getReader();
|
|
167
|
+
const decoder = new TextDecoder();
|
|
168
|
+
let text = '';
|
|
169
|
+
while (!text.includes(marker)) {
|
|
170
|
+
const next = await reader.read();
|
|
171
|
+
if (next.done) {
|
|
172
|
+
throw new Error(`the child exited before printing ${marker}: ${text}`);
|
|
173
|
+
}
|
|
174
|
+
text += decoder.decode(next.value, { stream: true });
|
|
175
|
+
}
|
|
176
|
+
reader.releaseLock();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
describe('the parent-held CPU pool', () => {
|
|
180
|
+
it('serves a Cargo allocation as its own live child pool without competing with the occupied ancestor', async () => {
|
|
181
|
+
const { parent, pool } = await openPool(4);
|
|
182
|
+
const cargo = childOf(parent.socket, JSON.stringify({ op: 'cpu-pool', want: 4, children: true }));
|
|
183
|
+
expect(await cargo.next()).toEqual(QUEUED);
|
|
184
|
+
const granted = await cargo.next();
|
|
185
|
+
if (!granted.ok || granted.lease !== 'granted' || granted.pool === undefined)
|
|
186
|
+
throw new Error('no live child pool granted');
|
|
187
|
+
expect(granted.tokens).toBe(4);
|
|
188
|
+
expect(granted.pool).not.toBe(parent.socket);
|
|
189
|
+
const sibling = childOf(parent.socket, JSON.stringify({ op: 'cpu-pool', want: 1 }));
|
|
190
|
+
expect(await sibling.next()).toEqual(QUEUED);
|
|
191
|
+
const a = childOf(granted.pool, JSON.stringify({ op: 'cpu-pool', want: 3 }));
|
|
192
|
+
const b = childOf(granted.pool, JSON.stringify({ op: 'cpu-pool', want: 3 }));
|
|
193
|
+
expect(await a.next()).toEqual(QUEUED);
|
|
194
|
+
expect(await a.next()).toEqual({ ok: true, lease: 'granted', tokens: 3 });
|
|
195
|
+
expect(await b.next()).toEqual(QUEUED);
|
|
196
|
+
expect(await b.next()).toEqual({ ok: true, lease: 'granted', tokens: 1 });
|
|
197
|
+
cargo.socket.destroy();
|
|
198
|
+
await cargo.closed;
|
|
199
|
+
await Promise.all([a.closed, b.closed]);
|
|
200
|
+
expect(await sibling.next()).toEqual({ ok: true, lease: 'granted', tokens: 1 });
|
|
201
|
+
sibling.socket.destroy();
|
|
202
|
+
await sibling.closed;
|
|
203
|
+
expect(await pool.close()).toEqual({ ok: true });
|
|
204
|
+
expect(existsSync(granted.pool)).toBe(false);
|
|
205
|
+
});
|
|
206
|
+
it('admits queued children first-in, first-out, each at most its want', async () => {
|
|
207
|
+
const { parent } = await openPool(4);
|
|
208
|
+
const a = childOf(parent.socket, JSON.stringify({ op: 'cpu-pool', want: 3 }));
|
|
209
|
+
expect(await a.next()).toEqual(QUEUED);
|
|
210
|
+
expect(await a.next()).toEqual({ ok: true, lease: 'granted', tokens: 3 });
|
|
211
|
+
const b = childOf(parent.socket, JSON.stringify({ op: 'cpu-pool', want: 2 }));
|
|
212
|
+
expect(await b.next()).toEqual(QUEUED);
|
|
213
|
+
expect(await b.next()).toEqual({ ok: true, lease: 'granted', tokens: 1 });
|
|
214
|
+
const c = childOf(parent.socket, JSON.stringify({ op: 'cpu-pool', want: 2 }));
|
|
215
|
+
expect(await c.next()).toEqual(QUEUED);
|
|
216
|
+
const d = childOf(parent.socket, JSON.stringify({ op: 'cpu-pool', want: 3 }));
|
|
217
|
+
expect(await d.next()).toEqual(QUEUED);
|
|
218
|
+
a.socket.destroy();
|
|
219
|
+
expect(await c.next()).toEqual({ ok: true, lease: 'granted', tokens: 2 });
|
|
220
|
+
expect(await d.next()).toEqual({ ok: true, lease: 'granted', tokens: 1 });
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('never grants more than the pool holds, and admits queued siblings in arrival order', async () => {
|
|
224
|
+
const { parent } = await openPool(4);
|
|
225
|
+
const request = JSON.stringify({ op: 'cpu-pool', want: 2 });
|
|
226
|
+
const one = childOf(parent.socket, request);
|
|
227
|
+
expect(await one.next()).toEqual(QUEUED);
|
|
228
|
+
expect(await one.next()).toEqual({ ok: true, lease: 'granted', tokens: 2 });
|
|
229
|
+
const two = childOf(parent.socket, request);
|
|
230
|
+
expect(await two.next()).toEqual(QUEUED);
|
|
231
|
+
expect(await two.next()).toEqual({ ok: true, lease: 'granted', tokens: 2 });
|
|
232
|
+
// Two siblings of two hold all four tokens: each later sibling queues, and holds nothing.
|
|
233
|
+
const third = childOf(parent.socket, request);
|
|
234
|
+
expect(await third.next()).toEqual(QUEUED);
|
|
235
|
+
const fourth = childOf(parent.socket, request);
|
|
236
|
+
expect(await fourth.next()).toEqual(QUEUED);
|
|
237
|
+
const fifth = childOf(parent.socket, request);
|
|
238
|
+
expect(await fifth.next()).toEqual(QUEUED);
|
|
239
|
+
const sixth = childOf(parent.socket, request);
|
|
240
|
+
expect(await sixth.next()).toEqual(QUEUED);
|
|
241
|
+
one.socket.destroy();
|
|
242
|
+
expect(await third.next()).toEqual({ ok: true, lease: 'granted', tokens: 2 });
|
|
243
|
+
two.socket.destroy();
|
|
244
|
+
expect(await fourth.next()).toEqual({ ok: true, lease: 'granted', tokens: 2 });
|
|
245
|
+
third.socket.destroy();
|
|
246
|
+
expect(await fifth.next()).toEqual({ ok: true, lease: 'granted', tokens: 2 });
|
|
247
|
+
fourth.socket.destroy();
|
|
248
|
+
expect(await sixth.next()).toEqual({ ok: true, lease: 'granted', tokens: 2 });
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('drops a queued child that closes, and still admits the next child', async () => {
|
|
252
|
+
const { parent } = await openPool(4);
|
|
253
|
+
const holder = childOf(parent.socket, JSON.stringify({ op: 'cpu-pool', want: 4 }));
|
|
254
|
+
expect(await holder.next()).toEqual(QUEUED);
|
|
255
|
+
expect(await holder.next()).toEqual({ ok: true, lease: 'granted', tokens: 4 });
|
|
256
|
+
const queued = childOf(parent.socket, JSON.stringify({ op: 'cpu-pool', want: 2 }));
|
|
257
|
+
expect(await queued.next()).toEqual(QUEUED);
|
|
258
|
+
queued.socket.destroy();
|
|
259
|
+
await queued.closed;
|
|
260
|
+
// The server may process the two closes in either order: a dropped waiter is never granted, so
|
|
261
|
+
// the next child gets its tokens in both orders.
|
|
262
|
+
holder.socket.destroy();
|
|
263
|
+
const next = childOf(parent.socket, JSON.stringify({ op: 'cpu-pool', want: 2 }));
|
|
264
|
+
expect(await next.next()).toEqual(QUEUED);
|
|
265
|
+
expect(await next.next()).toEqual({ ok: true, lease: 'granted', tokens: 2 });
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it("returns a SIGKILLed holder's tokens to its queued sibling", async () => {
|
|
269
|
+
const { parent } = await openPool(4);
|
|
270
|
+
// A plain Node-API child: it needs no typia transform, and SIGKILL closes its socket as a crash does.
|
|
271
|
+
// Its connected socket keeps the child alive, so it needs no timer.
|
|
272
|
+
const holder = Bun.spawn(
|
|
273
|
+
[
|
|
274
|
+
process.execPath,
|
|
275
|
+
'-e',
|
|
276
|
+
`
|
|
277
|
+
const { connect } = require('node:net');
|
|
278
|
+
const socket = connect(${JSON.stringify(parent.socket)});
|
|
279
|
+
socket.on('connect', () => socket.write('{"op":"cpu-pool","want":2}\\n'));
|
|
280
|
+
socket.on('data', (chunk) => process.stdout.write(chunk));
|
|
281
|
+
`,
|
|
282
|
+
],
|
|
283
|
+
{ stdout: 'pipe', stderr: 'inherit' },
|
|
284
|
+
);
|
|
285
|
+
try {
|
|
286
|
+
await untilLine(holder.stdout, '"granted"');
|
|
287
|
+
const filler = childOf(parent.socket, JSON.stringify({ op: 'cpu-pool', want: 2 }));
|
|
288
|
+
expect(await filler.next()).toEqual(QUEUED);
|
|
289
|
+
expect(await filler.next()).toEqual({ ok: true, lease: 'granted', tokens: 2 });
|
|
290
|
+
const sibling = childOf(parent.socket, JSON.stringify({ op: 'cpu-pool', want: 2 }));
|
|
291
|
+
expect(await sibling.next()).toEqual(QUEUED);
|
|
292
|
+
holder.kill('SIGKILL');
|
|
293
|
+
await holder.exited;
|
|
294
|
+
expect(await sibling.next()).toEqual({ ok: true, lease: 'granted', tokens: 2 });
|
|
295
|
+
} finally {
|
|
296
|
+
holder.kill('SIGKILL');
|
|
297
|
+
await holder.exited;
|
|
298
|
+
}
|
|
299
|
+
}, 20_000);
|
|
300
|
+
|
|
301
|
+
it('treats a dead or non-socket endpoint as absent, and a malformed endpoint as no pool', async () => {
|
|
302
|
+
const { pool, parent } = await openPool(2);
|
|
303
|
+
expect(await pool.close()).toEqual({ ok: true });
|
|
304
|
+
expect(await takeParentCpuTokens(parent, 1, 2)).toMatchObject({ granted: false, cause: 'absent' });
|
|
305
|
+
|
|
306
|
+
const stale = await ownedSocketDirectory('cpu-stale-', 'p.sock');
|
|
307
|
+
directories.push(stale);
|
|
308
|
+
await writeFile(join(stale, 'p.sock'), 'not a socket');
|
|
309
|
+
expect(await takeParentCpuTokens({ socket: join(stale, 'p.sock'), tokens: 2 }, 1, 2)).toMatchObject({
|
|
310
|
+
granted: false,
|
|
311
|
+
cause: 'absent',
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
expect(readInheritedCpuPool({ [CPU_POOL_ENV]: 'a\0b', [CPU_TOKENS_ENV]: '2' })).toBeNull();
|
|
315
|
+
expect(await takeParentCpuTokens({ socket: 'a\0b', tokens: 2 }, 1, 2)).toMatchObject({
|
|
316
|
+
granted: false,
|
|
317
|
+
cause: 'other',
|
|
318
|
+
});
|
|
319
|
+
expect(readInheritedCpuPool({ [CPU_POOL_ENV]: '', [CPU_TOKENS_ENV]: '2' })).toBeNull();
|
|
320
|
+
expect(readInheritedCpuPool({ [CPU_POOL_ENV]: '/tmp/p.sock' })).toBeNull();
|
|
321
|
+
expect(readInheritedCpuPool({ [CPU_TOKENS_ENV]: '4' })).toBeNull();
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('names the endpoint and count it holds, in private owned paths, and removes them on close', async () => {
|
|
325
|
+
const made = await createCpuPool(3, NEVER);
|
|
326
|
+
if (!made.ok) {
|
|
327
|
+
throw new Error(made.error);
|
|
328
|
+
}
|
|
329
|
+
pools.push(made.pool);
|
|
330
|
+
const inherited = readInheritedCpuPool(made.pool.environment);
|
|
331
|
+
if (inherited === null) {
|
|
332
|
+
throw new Error('the pool environment names no endpoint');
|
|
333
|
+
}
|
|
334
|
+
expect(inherited.tokens).toBe(3);
|
|
335
|
+
expect(made.pool.environment[CPU_TOKENS_ENV]).toBe('3');
|
|
336
|
+
expect(statSync(dirname(inherited.socket)).mode & 0o777).toBe(0o700);
|
|
337
|
+
expect(statSync(inherited.socket).mode & 0o777).toBe(0o600);
|
|
338
|
+
expect(await made.pool.close()).toEqual({ ok: true });
|
|
339
|
+
expect(await made.pool.close()).toEqual({ ok: true });
|
|
340
|
+
expect(existsSync(dirname(inherited.socket))).toBe(false);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it('refuses each malformed request, and keeps admitting valid ones', async () => {
|
|
344
|
+
const { parent } = await openPool(2);
|
|
345
|
+
const malformed = [
|
|
346
|
+
'not json',
|
|
347
|
+
'{"op":"other","want":1}',
|
|
348
|
+
'{"op":"cpu-pool","want":0}',
|
|
349
|
+
'{"op":"cpu-pool","want":1.5}',
|
|
350
|
+
'x'.repeat(5000),
|
|
351
|
+
'x'.repeat(1024 * 1024),
|
|
352
|
+
];
|
|
353
|
+
for (const line of malformed) {
|
|
354
|
+
const refused = childOf(parent.socket, line);
|
|
355
|
+
expect(await refused.next()).toMatchObject({ ok: false, code: 'invalid-request' });
|
|
356
|
+
}
|
|
357
|
+
expect((await takeOrThrow(parent, 2)).tokens).toBe(2);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it('destroys a granted child that sends a second request, returning its tokens', async () => {
|
|
361
|
+
const { parent } = await openPool(2);
|
|
362
|
+
const first = childOf(parent.socket, JSON.stringify({ op: 'cpu-pool', want: 2 }));
|
|
363
|
+
expect(await first.next()).toEqual(QUEUED);
|
|
364
|
+
expect(await first.next()).toEqual({ ok: true, lease: 'granted', tokens: 2 });
|
|
365
|
+
first.socket.write(`${JSON.stringify({ op: 'cpu-pool', want: 1 })}\n`);
|
|
366
|
+
await first.closed;
|
|
367
|
+
expect((await takeOrThrow(parent, 2)).tokens).toBe(2);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('makes release idempotent, closes the connection, and grants again', async () => {
|
|
371
|
+
const { parent } = await openPool(2);
|
|
372
|
+
const grant = await takeOrThrow(parent, 2);
|
|
373
|
+
grant.release();
|
|
374
|
+
grant.release();
|
|
375
|
+
await grant.closed;
|
|
376
|
+
expect((await takeOrThrow(parent, 2)).tokens).toBe(2);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it('closes a lent pool and its grandchildren when the upstream grant closes', async () => {
|
|
380
|
+
const upstream = await openPool(4);
|
|
381
|
+
const lent = await takeOrThrow(upstream.parent, 2);
|
|
382
|
+
const sub = await openPool(lent.tokens, lent.closed);
|
|
383
|
+
const grandchild = await takeParentCpuTokens(sub.parent, 2, 2);
|
|
384
|
+
if (!grandchild.granted) {
|
|
385
|
+
throw new Error(`the sub-pool refused its grandchild: ${grandchild.reason}`);
|
|
386
|
+
}
|
|
387
|
+
expect(grandchild.tokens).toBe(1);
|
|
388
|
+
|
|
389
|
+
expect(await upstream.pool.close()).toEqual({ ok: true });
|
|
390
|
+
await lent.closed;
|
|
391
|
+
await grandchild.closed;
|
|
392
|
+
expect(await sub.pool.close()).toEqual({ ok: true });
|
|
393
|
+
expect(existsSync(dirname(sub.parent.socket))).toBe(false);
|
|
394
|
+
expect(await takeParentCpuTokens(sub.parent, 1, 2)).toMatchObject({ granted: false, cause: 'absent' });
|
|
395
|
+
expect(await takeParentCpuTokens(upstream.parent, 1, 8)).toMatchObject({ granted: false, cause: 'absent' });
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
it('asks for min(want, inherited count, ceil(cores / 2)), and the grant follows that ask', async () => {
|
|
399
|
+
const cases = [
|
|
400
|
+
{ want: 1, inherited: 8, cores: 8, tokens: 1 },
|
|
401
|
+
{ want: 8, inherited: 2, cores: 8, tokens: 2 },
|
|
402
|
+
{ want: 8, inherited: 8, cores: 8, tokens: 4 },
|
|
403
|
+
{ want: 8, inherited: 8, cores: 5, tokens: 3 },
|
|
404
|
+
{ want: 8, inherited: 8, cores: 3, tokens: 2 },
|
|
405
|
+
{ want: 8, inherited: 8, cores: 1, tokens: 1 },
|
|
406
|
+
];
|
|
407
|
+
for (const check of cases) {
|
|
408
|
+
// A fresh full pool isolates the clamp from delivery of the previous client's close event.
|
|
409
|
+
const { parent } = await openPool(8);
|
|
410
|
+
expect(await grantedFor({ socket: parent.socket, tokens: check.inherited }, check.want, check.cores)).toBe(
|
|
411
|
+
check.tokens,
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
it('never grants more than the live pool holds, even when the inherited count claims more', async () => {
|
|
417
|
+
const { parent } = await openPool(2);
|
|
418
|
+
// The child's descriptor claims 8 tokens: the ask is min(8, 8, 8), but the live pool holds 2 and grants 2.
|
|
419
|
+
expect(await grantedFor({ socket: parent.socket, tokens: 8 }, 8, 16)).toBe(2);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
it('reports a teardown that cannot remove its directory, and reports the same outcome on every close', async () => {
|
|
423
|
+
const made = await createCpuPool(2, NEVER);
|
|
424
|
+
if (!made.ok) {
|
|
425
|
+
throw new Error(made.error);
|
|
426
|
+
}
|
|
427
|
+
const inherited = readInheritedCpuPool(made.pool.environment);
|
|
428
|
+
if (inherited === null) {
|
|
429
|
+
throw new Error('the pool environment names no endpoint');
|
|
430
|
+
}
|
|
431
|
+
const directory = dirname(inherited.socket);
|
|
432
|
+
directories.push(directory);
|
|
433
|
+
// A nonempty subdirectory no one may read makes recursive removal fail on real files, not a stub.
|
|
434
|
+
const stuck = join(directory, 'stuck');
|
|
435
|
+
mkdirSync(stuck);
|
|
436
|
+
await writeFile(join(stuck, 'held'), 'owned cleanup witness');
|
|
437
|
+
chmodSync(stuck, 0o000);
|
|
438
|
+
try {
|
|
439
|
+
const first = await made.pool.close();
|
|
440
|
+
expect(first).toMatchObject({ ok: false, error: expect.stringContaining('its directory was not removed') });
|
|
441
|
+
expect(await made.pool.close()).toEqual(first);
|
|
442
|
+
} finally {
|
|
443
|
+
if (existsSync(stuck)) chmodSync(stuck, 0o700);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it('makes no pool when its grant closes during setup, and refuses a non-positive count', async () => {
|
|
448
|
+
const before = cpuPoolDirectories();
|
|
449
|
+
const made = await createCpuPool(2, Promise.resolve());
|
|
450
|
+
expect(made.ok).toBe(false);
|
|
451
|
+
expect(cpuPoolDirectories()).toEqual(before);
|
|
452
|
+
await expect(createCpuPool(0, NEVER)).rejects.toBeInstanceOf(RangeError);
|
|
453
|
+
});
|
|
454
|
+
});
|