@zukhruf/testing 0.8.17 → 0.8.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 +47 -37
- package/dist/databases/collector.d.ts +23 -20
- package/dist/databases/collector.d.ts.map +1 -1
- package/dist/databases/collector.js +9 -6
- package/dist/databases/collector.js.map +1 -1
- package/dist/databases/mysql-family-collector.d.ts +1 -6
- package/dist/databases/mysql-family-collector.d.ts.map +1 -1
- package/dist/databases/mysql-family-collector.js +12 -20
- package/dist/databases/mysql-family-collector.js.map +1 -1
- package/dist/databases/mysql-family-server.d.ts.map +1 -1
- package/dist/databases/mysql-family-server.js +2 -6
- package/dist/databases/mysql-family-server.js.map +1 -1
- package/dist/databases/postgres-collector.d.ts +1 -6
- package/dist/databases/postgres-collector.d.ts.map +1 -1
- package/dist/databases/postgres-collector.js +13 -20
- package/dist/databases/postgres-collector.js.map +1 -1
- package/dist/databases/postgres.d.ts.map +1 -1
- package/dist/databases/postgres.js +2 -3
- package/dist/databases/postgres.js.map +1 -1
- package/dist/databases/sqlserver-collector.d.ts +2 -5
- package/dist/databases/sqlserver-collector.d.ts.map +1 -1
- package/dist/databases/sqlserver-collector.js +20 -37
- package/dist/databases/sqlserver-collector.js.map +1 -1
- package/dist/databases/sqlserver.d.ts +5 -2
- package/dist/databases/sqlserver.d.ts.map +1 -1
- package/dist/databases/sqlserver.js +11 -18
- package/dist/databases/sqlserver.js.map +1 -1
- package/dist/docker/reaper.d.ts +96 -0
- package/dist/docker/reaper.d.ts.map +1 -0
- package/dist/docker/reaper.js +557 -0
- package/dist/docker/reaper.js.map +1 -0
- package/dist/docker/run-records.d.ts +3 -10
- package/dist/docker/run-records.d.ts.map +1 -1
- package/dist/docker/run-records.js +3 -14
- package/dist/docker/run-records.js.map +1 -1
- package/dist/docker/testbed.d.ts +6 -7
- package/dist/docker/testbed.d.ts.map +1 -1
- package/dist/docker/testbed.js +52 -20
- package/dist/docker/testbed.js.map +1 -1
- package/dist/scripts/docker-global-setup.d.ts +6 -1
- package/dist/scripts/docker-global-setup.d.ts.map +1 -1
- package/dist/scripts/docker-global-setup.js +42 -97
- package/dist/scripts/docker-global-setup.js.map +1 -1
- package/dist/scripts/run-cleanup.d.ts +5 -13
- package/dist/scripts/run-cleanup.d.ts.map +1 -1
- package/dist/scripts/run-cleanup.js +24 -259
- package/dist/scripts/run-cleanup.js.map +1 -1
- package/package.json +3 -3
- package/dist/scripts/docker-cleanup-worker.d.ts +0 -21
- package/dist/scripts/docker-cleanup-worker.d.ts.map +0 -1
- package/dist/scripts/docker-cleanup-worker.js +0 -31
- package/dist/scripts/docker-cleanup-worker.js.map +0 -1
|
@@ -1,280 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
-
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
return path;
|
|
8
|
-
};
|
|
9
|
-
import { execFile } from 'node:child_process';
|
|
10
|
-
import { readFile, readdir, rm } from 'node:fs/promises';
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { readFileSync, readdirSync, rmSync } from 'node:fs';
|
|
11
3
|
import { join } from 'node:path';
|
|
12
|
-
import { promisify } from 'node:util';
|
|
13
|
-
import { ContainerNotFoundError, Docker, ImageNotFoundError, } from '@zukhruf/docker';
|
|
14
|
-
import { KIND_LABEL, ownedBy, } from "../databases/collector.js";
|
|
15
|
-
import { EngineLease, LEASED_SERVER_LABEL, LEASE_IMAGE, LEASE_LABEL, sweepLeaseName, } from "../docker/engine-lease.js";
|
|
16
4
|
import { DockerHost, SHELL_TIMEOUT, quote } from "../docker/host.js";
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export const ENGINE_CALL_TIMEOUT = 240_000;
|
|
21
|
-
const execute = promisify(execFile);
|
|
22
|
-
const codeOf = (error) => Error.isError(error) && 'code' in error ? error.code : undefined;
|
|
23
|
-
/**
|
|
24
|
-
* The collector of each kind, loaded when a server of the kind runs. A
|
|
25
|
-
* driver is an optional peer dependency: without it, the run's test
|
|
26
|
-
* processes could not create a database of the kind.
|
|
27
|
-
*/
|
|
28
|
-
const collectors = {
|
|
29
|
-
postgres: {
|
|
30
|
-
load: async () => (await import("../databases/postgres-collector.js")).postgres,
|
|
31
|
-
},
|
|
32
|
-
mysql: {
|
|
33
|
-
load: async () => (await import("../databases/mysql-family-collector.js")).mysql,
|
|
34
|
-
},
|
|
35
|
-
mariadb: {
|
|
36
|
-
load: async () => (await import("../databases/mysql-family-collector.js")).mariadb,
|
|
37
|
-
},
|
|
38
|
-
sqlserver: {
|
|
39
|
-
driver: 'mssql',
|
|
40
|
-
load: async () => (await import("../databases/sqlserver-collector.js")).sqlserver,
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
const isKind = (value) => value !== undefined && Object.hasOwn(collectors, value);
|
|
44
|
-
/** The collector of `kind`, or undefined when its driver is not installed. */
|
|
45
|
-
async function collectorOf(kind) {
|
|
46
|
-
const { driver, load } = collectors[kind];
|
|
47
|
-
if (driver !== undefined)
|
|
48
|
-
try {
|
|
49
|
-
await import(__rewriteRelativeImportExtension(driver));
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
if (codeOf(error) === 'ERR_MODULE_NOT_FOUND')
|
|
53
|
-
return undefined;
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
return load();
|
|
57
|
-
}
|
|
58
|
-
const running = async (container) => (await container.inspect().catch(() => undefined))?.State?.Running === true;
|
|
59
|
-
/**
|
|
60
|
-
* Drops the run's databases on each running shared server of a database
|
|
61
|
-
* fixture. A server that stops takes its databases with it. A server that
|
|
62
|
-
* does not answer yet holds none: a fixture creates a database only after
|
|
63
|
-
* the server answered its readiness check. Each list and drop has the
|
|
64
|
-
* deadline of one engine call.
|
|
65
|
-
*/
|
|
66
|
-
async function dropDatabases(engine, host, runId, signal) {
|
|
67
|
-
for (const summary of await engine.containers.list({
|
|
68
|
-
filters: { label: [SERVER_LABEL, KIND_LABEL] },
|
|
69
|
-
signal: signal(),
|
|
70
|
-
})) {
|
|
71
|
-
const kind = summary.Labels?.[KIND_LABEL];
|
|
72
|
-
if (!isKind(kind))
|
|
73
|
-
continue;
|
|
74
|
-
const collector = await collectorOf(kind);
|
|
75
|
-
if (!collector)
|
|
76
|
-
continue;
|
|
77
|
-
const container = await engine.containers.find(summary.Id, {
|
|
78
|
-
signal: signal(),
|
|
79
|
-
});
|
|
80
|
-
if (!container)
|
|
81
|
-
continue;
|
|
82
|
-
// Another run's teardown can remove it after the find.
|
|
83
|
-
const inspected = await container
|
|
84
|
-
.inspect({ signal: signal() })
|
|
85
|
-
.catch((error) => {
|
|
86
|
-
if (error instanceof ContainerNotFoundError)
|
|
87
|
-
return undefined;
|
|
88
|
-
throw error;
|
|
89
|
-
});
|
|
90
|
-
if (!inspected?.State?.Running)
|
|
91
|
-
continue;
|
|
92
|
-
const environment = Object.fromEntries((inspected.Config?.Env ?? []).map((entry) => {
|
|
93
|
-
const separator = entry.indexOf('=');
|
|
94
|
-
return [entry.slice(0, separator), entry.slice(separator + 1)];
|
|
95
|
-
}));
|
|
96
|
-
await using connection = new AsyncDisposableStack();
|
|
97
|
-
let server;
|
|
98
|
-
let names;
|
|
99
|
-
try {
|
|
100
|
-
server = connection.use(await collector.open(container, environment, host));
|
|
101
|
-
names = await collector.list(server, { signal: signal() });
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
for (const name of names.filter(ownedBy(runId))) {
|
|
107
|
-
const deadline = signal();
|
|
108
|
-
try {
|
|
109
|
-
await collector.drop(server, name, { signal: deadline });
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
// A server that does not answer within the deadline keeps the run's
|
|
113
|
-
// databases, as one whose list fails: a hung shared server neither
|
|
114
|
-
// fails nor hangs this cleanup.
|
|
115
|
-
if (deadline.aborted)
|
|
116
|
-
break;
|
|
117
|
-
if (await running(container))
|
|
118
|
-
throw error;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
async function readRecordedPath(file) {
|
|
124
|
-
const { path } = JSON.parse(await readFile(file, 'utf8'));
|
|
5
|
+
import { directoryPrefix, forwardPrefix } from "../docker/run-records.js";
|
|
6
|
+
const recordedPath = (file) => {
|
|
7
|
+
const { path } = JSON.parse(readFileSync(file, 'utf8'));
|
|
125
8
|
return path;
|
|
126
|
-
}
|
|
9
|
+
};
|
|
127
10
|
/**
|
|
128
|
-
* Removes
|
|
129
|
-
*
|
|
11
|
+
* Removes the paths that the run's records name, and then each record: the
|
|
12
|
+
* SSH forward directories and the host directories. The reaper of the run
|
|
13
|
+
* removes its engine objects (ADR 0020, item 6). Synchronous, so the global
|
|
14
|
+
* teardown finishes under `--test-force-exit`.
|
|
130
15
|
*/
|
|
131
|
-
export
|
|
132
|
-
const host = new DockerHost(
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
// remove a shared server here, or trust names alone as proof of ownership.
|
|
136
|
-
const filters = { label: [`${TEST_RUN_LABEL}=${previous.id}`] };
|
|
137
|
-
for (const summary of await engine.containers.list({
|
|
138
|
-
all: true,
|
|
139
|
-
filters,
|
|
140
|
-
signal: signal(),
|
|
141
|
-
})) {
|
|
142
|
-
if (summary.Labels?.[SERVER_LABEL] !== undefined)
|
|
143
|
-
continue;
|
|
144
|
-
const container = await engine.containers.find(summary.Id, {
|
|
145
|
-
signal: signal(),
|
|
146
|
-
});
|
|
147
|
-
await container?.remove({ force: true, v: true, signal: signal() });
|
|
148
|
-
}
|
|
149
|
-
for (const { Name } of await engine.volumes.list({
|
|
150
|
-
filters,
|
|
151
|
-
signal: signal(),
|
|
152
|
-
})) {
|
|
153
|
-
const volume = await engine.volumes.find(Name, { signal: signal() });
|
|
154
|
-
await volume?.remove({ signal: signal() });
|
|
155
|
-
}
|
|
156
|
-
for (const file of await readdir(directory)) {
|
|
16
|
+
export function removeRecordedPaths(run, directory) {
|
|
17
|
+
const host = new DockerHost(run.endpoint, undefined);
|
|
18
|
+
for (const file of readdirSync(directory)) {
|
|
19
|
+
const record = join(directory, file);
|
|
157
20
|
if (file.startsWith('forward-')) {
|
|
158
|
-
const path =
|
|
159
|
-
if (!path.startsWith(forwardPrefix(
|
|
21
|
+
const path = recordedPath(record);
|
|
22
|
+
if (!path.startsWith(forwardPrefix(run.id)) ||
|
|
160
23
|
path.slice(5).includes('/'))
|
|
161
24
|
throw new Error(`Invalid SSH forwarding cleanup record: ${path}`);
|
|
162
|
-
|
|
25
|
+
rmSync(path, { recursive: true, force: true });
|
|
163
26
|
}
|
|
164
27
|
else if (file.startsWith('directory-')) {
|
|
165
|
-
const path =
|
|
166
|
-
if (!path.includes(`/${directoryPrefix(
|
|
28
|
+
const path = recordedPath(record);
|
|
29
|
+
if (!path.includes(`/${directoryPrefix(run.id)}`) ||
|
|
167
30
|
path.includes('/../'))
|
|
168
31
|
throw new Error(`Invalid fixture cleanup record: ${path}`);
|
|
169
32
|
if (host.remote)
|
|
170
|
-
|
|
33
|
+
execFileSync('ssh', [...host.sshArgs(), `rm -rf -- ${quote(path)}`], {
|
|
171
34
|
timeout: SHELL_TIMEOUT,
|
|
35
|
+
stdio: 'ignore',
|
|
172
36
|
});
|
|
173
37
|
else
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
await dropDatabases(engine, host, previous.id, signal);
|
|
178
|
-
}
|
|
179
|
-
/** The tries of a teardown to take a sweep lease that another holder has. */
|
|
180
|
-
const SWEEP_LEASE_TRIES = 3;
|
|
181
|
-
/** How long a teardown waits for the sweep lease of one server that another holder has. */
|
|
182
|
-
const SWEEP_LEASE_WAIT = 30_000;
|
|
183
|
-
/** The age from which a teardown removes a shared server that no process lease holds (ADR 0019). */
|
|
184
|
-
const SERVER_TTL = 7 * 24 * 60 * 60 * 1000;
|
|
185
|
-
/**
|
|
186
|
-
* Takes the sweep lease of `fingerprint`, and pulls its image when the engine
|
|
187
|
-
* does not have it. When the name is taken, it waits until that lease is
|
|
188
|
-
* gone, as a test process does, and tries again: a teardown killed before
|
|
189
|
-
* the start of its lease leaves it created, and the wait removes it. Gives
|
|
190
|
-
* undefined when each try found the name taken, or when the wait took
|
|
191
|
-
* longer than SWEEP_LEASE_WAIT: the server stays for a later teardown, and
|
|
192
|
-
* another teardown's sweep never fails this run.
|
|
193
|
-
*/
|
|
194
|
-
async function takeSweepLease(engine, fingerprint, signal, clock) {
|
|
195
|
-
const name = sweepLeaseName(fingerprint);
|
|
196
|
-
const take = () => EngineLease.take(engine, { [LEASE_LABEL]: 'sweep', [LEASED_SERVER_LABEL]: fingerprint }, { name, signal: signal() });
|
|
197
|
-
const wait = AbortSignal.timeout(SWEEP_LEASE_WAIT);
|
|
198
|
-
for (let tries = 0; tries < SWEEP_LEASE_TRIES; tries += 1) {
|
|
199
|
-
let lease;
|
|
200
|
-
try {
|
|
201
|
-
lease = await take();
|
|
202
|
-
}
|
|
203
|
-
catch (error) {
|
|
204
|
-
if (!(error instanceof ImageNotFoundError))
|
|
205
|
-
throw error;
|
|
206
|
-
await engine.images.pull(LEASE_IMAGE, { signal: signal() });
|
|
207
|
-
lease = await take();
|
|
208
|
-
}
|
|
209
|
-
if (lease !== undefined)
|
|
210
|
-
return lease;
|
|
211
|
-
try {
|
|
212
|
-
await EngineLease.gone(engine, name, { signal: wait, clock });
|
|
38
|
+
rmSync(path, { recursive: true, force: true });
|
|
213
39
|
}
|
|
214
|
-
|
|
215
|
-
if (wait.aborted)
|
|
216
|
-
return undefined;
|
|
217
|
-
throw error;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return undefined;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Removes each shared server that is older than SERVER_TTL, unless a test
|
|
224
|
-
* process holds a process lease for it (ADR 0019). The sweep lease of the
|
|
225
|
-
* server comes first, and the look for process leases after it (ADR 0014).
|
|
226
|
-
* A removal that fails keeps the server, and the teardown goes on.
|
|
227
|
-
*/
|
|
228
|
-
async function removeExpiredServers(engine, clock) {
|
|
229
|
-
const signal = () => AbortSignal.timeout(ENGINE_CALL_TIMEOUT);
|
|
230
|
-
const expiry = (clock.Date.now() - SERVER_TTL) / 1000;
|
|
231
|
-
const servers = await engine.containers.list({
|
|
232
|
-
all: true,
|
|
233
|
-
filters: { label: [SERVER_LABEL] },
|
|
234
|
-
signal: signal(),
|
|
235
|
-
});
|
|
236
|
-
for (const { Id, Created, Labels } of servers) {
|
|
237
|
-
// The filter and the engine give both; the Engine API types mark each field optional.
|
|
238
|
-
const fingerprint = Labels?.[SERVER_LABEL];
|
|
239
|
-
if (fingerprint === undefined || Created === undefined || Created > expiry)
|
|
40
|
+
else
|
|
240
41
|
continue;
|
|
241
|
-
|
|
242
|
-
await using lease = await takeSweepLease(engine, fingerprint, signal, clock);
|
|
243
|
-
if (lease === undefined)
|
|
244
|
-
continue;
|
|
245
|
-
const holders = await engine.containers.list({
|
|
246
|
-
filters: {
|
|
247
|
-
label: [
|
|
248
|
-
`${LEASE_LABEL}=process`,
|
|
249
|
-
`${LEASED_SERVER_LABEL}=${fingerprint}`,
|
|
250
|
-
],
|
|
251
|
-
},
|
|
252
|
-
signal: signal(),
|
|
253
|
-
});
|
|
254
|
-
if (holders.length > 0)
|
|
255
|
-
continue;
|
|
256
|
-
// Another run's teardown can remove it first.
|
|
257
|
-
const container = await engine.containers.find(Id, { signal: signal() });
|
|
258
|
-
// A server that the engine does not remove stays for a later teardown:
|
|
259
|
-
// the sweep never fails this run.
|
|
260
|
-
await container
|
|
261
|
-
?.remove({ force: true, v: true, signal: signal() })
|
|
262
|
-
.catch(() => { });
|
|
42
|
+
rmSync(record, { force: true });
|
|
263
43
|
}
|
|
264
44
|
}
|
|
265
|
-
/**
|
|
266
|
-
* Connects to the run's engine, cleans the run, removes the expired shared
|
|
267
|
-
* servers, and ends the connection. Only the global teardown calls it, for a
|
|
268
|
-
* run that used Docker.
|
|
269
|
-
*/
|
|
270
|
-
export async function connectAndCleanup(previous, directory, clock) {
|
|
271
|
-
// Disposal ends the connection, and with it the ssh child of an SSH engine.
|
|
272
|
-
await using engine = await Docker.connect({
|
|
273
|
-
clock,
|
|
274
|
-
host: previous.endpoint,
|
|
275
|
-
signal: AbortSignal.timeout(ENGINE_CALL_TIMEOUT),
|
|
276
|
-
});
|
|
277
|
-
await cleanup(engine, previous, directory);
|
|
278
|
-
await removeExpiredServers(engine, clock);
|
|
279
|
-
}
|
|
280
45
|
//# sourceMappingURL=run-cleanup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-cleanup.js","sourceRoot":"","sources":["../../src/scripts/run-cleanup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run-cleanup.js","sourceRoot":"","sources":["../../src/scripts/run-cleanup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAS1E,MAAM,YAAY,GAAG,CAAC,IAAY,EAAU,EAAE;IAC5C,MAAM,EAAE,IAAI,EAAE,GAAqB,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF;;;;;GAKG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E,QAAQ;iBAChB,CAAC,CAAC;;gBACA,MAAM,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACtD,CAAC;;YAAM,SAAS;QAChB,MAAM,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAClC,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/testing",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.19",
|
|
4
4
|
"description": "Disposable fixtures for integration tests: Docker containers, database servers, SQLite and DuckDB databases, HTTP servers, streams, temporary directories and intercepted requests. Node's global setup and teardown remove what a killed test run left behind.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -151,8 +151,8 @@
|
|
|
151
151
|
"pg": "^8.23.1"
|
|
152
152
|
},
|
|
153
153
|
"dependencies": {
|
|
154
|
-
"@zukhruf/async": "^0.8.
|
|
155
|
-
"@zukhruf/docker": "^0.8.
|
|
154
|
+
"@zukhruf/async": "^0.8.19",
|
|
155
|
+
"@zukhruf/docker": "^0.8.19",
|
|
156
156
|
"nano-spawn": "^2.1.0",
|
|
157
157
|
"p-memoize": "^8.0.0",
|
|
158
158
|
"p-retry": "^8.0.1"
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type MessagePort } from 'node:worker_threads';
|
|
2
|
-
import type { Run } from './run-cleanup.ts';
|
|
3
|
-
/** What the teardown passes to this worker. */
|
|
4
|
-
export interface CleanupWork {
|
|
5
|
-
run: Run;
|
|
6
|
-
directory: string;
|
|
7
|
-
port: MessagePort;
|
|
8
|
-
/** One Int32 that this worker sets to 1 after it posted its outcome. */
|
|
9
|
-
signal: SharedArrayBuffer;
|
|
10
|
-
}
|
|
11
|
-
/** What this worker posts: errors as plain fields, which a port can carry. */
|
|
12
|
-
export type CleanupOutcome = {
|
|
13
|
-
ok: true;
|
|
14
|
-
} | {
|
|
15
|
-
error: {
|
|
16
|
-
name: string;
|
|
17
|
-
message: string;
|
|
18
|
-
detail: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=docker-cleanup-worker.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"docker-cleanup-worker.d.ts","sourceRoot":"","sources":["../../src/scripts/docker-cleanup-worker.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,WAAW,EAAc,MAAM,qBAAqB,CAAC;AAEnE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAE5C,+CAA+C;AAC/C,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,WAAW,CAAC;IAClB,wEAAwE;IACxE,MAAM,EAAE,iBAAiB,CAAC;CAC3B;AAED,8EAA8E;AAC9E,MAAM,MAAM,cAAc,GACxB;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The worker of the global teardown. The teardown must be synchronous, and
|
|
3
|
-
* the Engine API client is asynchronous, so the teardown starts this worker
|
|
4
|
-
* and waits on `signal` until it posts its outcome on `port`.
|
|
5
|
-
*/
|
|
6
|
-
import { inspect } from 'node:util';
|
|
7
|
-
import { workerData } from 'node:worker_threads';
|
|
8
|
-
const { run, directory, port, signal } = workerData;
|
|
9
|
-
async function sweep() {
|
|
10
|
-
try {
|
|
11
|
-
// Imported here, so that a module that fails to load is an outcome too:
|
|
12
|
-
// the teardown would otherwise wait until its timeout.
|
|
13
|
-
const { connectAndCleanup } = await import("./run-cleanup.js");
|
|
14
|
-
await connectAndCleanup(run, directory, globalThis);
|
|
15
|
-
return { ok: true };
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
return {
|
|
19
|
-
error: {
|
|
20
|
-
name: Error.isError(error) ? error.name : 'Error',
|
|
21
|
-
message: Error.isError(error) ? error.message : String(error),
|
|
22
|
-
detail: inspect(error),
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
port.postMessage(await sweep());
|
|
28
|
-
const flag = new Int32Array(signal);
|
|
29
|
-
Atomics.store(flag, 0, 1);
|
|
30
|
-
Atomics.notify(flag, 0);
|
|
31
|
-
//# sourceMappingURL=docker-cleanup-worker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"docker-cleanup-worker.js","sourceRoot":"","sources":["../../src/scripts/docker-cleanup-worker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAoB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAiBnE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,GAAgB,UAAU,CAAC;AAEjE,KAAK,UAAU,KAAK;IAClB,IAAI,CAAC;QACH,wEAAwE;QACxE,uDAAuD;QACvD,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAC/D,MAAM,iBAAiB,CAAC,GAAG,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;QACpD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,KAAK,EAAE;gBACL,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAA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