Public dry run dryrun-750f29790fe2
Source commit: 750f29790fe2046599fbe5b5d06fdb63d92fabff Public tree identity: sha256:02326e08850bb287585789733ea5f3f153e1f7f3fd88afcc24e249107df91506
This commit is contained in:
commit
de66658961
102 changed files with 31669 additions and 0 deletions
244
scripts/artifact-export-smoke.js
Normal file
244
scripts/artifact-export-smoke.js
Normal file
|
|
@ -0,0 +1,244 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const assert = require("assert");
|
||||
const cp = require("child_process");
|
||||
const net = require("net");
|
||||
const path = require("path");
|
||||
|
||||
const repo = path.resolve(__dirname, "..");
|
||||
const project = path.join(repo, "examples/launch-build-demo");
|
||||
|
||||
function waitForJsonLine(child) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let buffer = "";
|
||||
child.stdout.on("data", (chunk) => {
|
||||
buffer += chunk.toString();
|
||||
const newline = buffer.indexOf("\n");
|
||||
if (newline < 0) return;
|
||||
try {
|
||||
resolve(JSON.parse(buffer.slice(0, newline).trim()));
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
child.once("exit", (code) => {
|
||||
reject(new Error(`process exited before JSON line with code ${code}`));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function send(addr, message) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const socket = net.connect(addr.port, addr.host, () => {
|
||||
socket.write(`${JSON.stringify(message)}\n`);
|
||||
});
|
||||
let buffer = "";
|
||||
socket.on("data", (chunk) => {
|
||||
buffer += chunk.toString();
|
||||
const newline = buffer.indexOf("\n");
|
||||
if (newline < 0) return;
|
||||
socket.end();
|
||||
try {
|
||||
resolve(JSON.parse(buffer.slice(0, newline)));
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
socket.on("error", reject);
|
||||
});
|
||||
}
|
||||
|
||||
function runProducerNode(addr) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = cp.spawn(
|
||||
"cargo",
|
||||
[
|
||||
"run",
|
||||
"-q",
|
||||
"-p",
|
||||
"disasmer-node",
|
||||
"--bin",
|
||||
"disasmer-node",
|
||||
"--",
|
||||
"--coordinator",
|
||||
`${addr.host}:${addr.port}`,
|
||||
"--tenant",
|
||||
"tenant",
|
||||
"--project-id",
|
||||
"project",
|
||||
"--node",
|
||||
"node-export-source",
|
||||
"--process",
|
||||
"vp-export",
|
||||
"--task",
|
||||
"compile-linux",
|
||||
"--project",
|
||||
project,
|
||||
"--artifact",
|
||||
"/vfs/artifacts/export-output.txt",
|
||||
],
|
||||
{ cwd: repo }
|
||||
);
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
child.stdout.on("data", (chunk) => {
|
||||
stdout += chunk.toString();
|
||||
});
|
||||
child.stderr.on("data", (chunk) => {
|
||||
stderr += chunk.toString();
|
||||
});
|
||||
child.on("exit", (code) => {
|
||||
if (code !== 0) {
|
||||
reject(new Error(`producer node failed with code ${code}\n${stderr}`));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
resolve(JSON.parse(stdout.trim().split("\n").at(-1)));
|
||||
} catch (error) {
|
||||
reject(new Error(`producer node output was not JSON: ${stdout}\n${error.stack || error.message}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function nodeCapabilities() {
|
||||
return {
|
||||
os: "Linux",
|
||||
arch: "x86_64",
|
||||
capabilities: ["Command", "VfsArtifacts"],
|
||||
environment_backends: [],
|
||||
source_providers: ["filesystem"],
|
||||
};
|
||||
}
|
||||
|
||||
async function reportNode(addr, node, { directConnectivity = true, online = true } = {}) {
|
||||
const response = await send(addr, {
|
||||
type: "report_node_capabilities",
|
||||
tenant: "tenant",
|
||||
project: "project",
|
||||
node,
|
||||
capabilities: nodeCapabilities(),
|
||||
cached_environment_digests: [],
|
||||
dependency_cache_digests: [],
|
||||
source_snapshots: [],
|
||||
artifact_locations: [],
|
||||
direct_connectivity: directConnectivity,
|
||||
online,
|
||||
});
|
||||
assert.strictEqual(response.type, "node_capabilities_recorded");
|
||||
assert.strictEqual(response.node, node);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const coordinator = cp.spawn(
|
||||
"cargo",
|
||||
[
|
||||
"run",
|
||||
"-q",
|
||||
"-p",
|
||||
"disasmer-coordinator",
|
||||
"--bin",
|
||||
"disasmer-coordinator",
|
||||
"--",
|
||||
"--listen",
|
||||
"127.0.0.1:0",
|
||||
],
|
||||
{ cwd: repo }
|
||||
);
|
||||
|
||||
try {
|
||||
const ready = await waitForJsonLine(coordinator);
|
||||
const [host, portText] = ready.listen.split(":");
|
||||
const addr = { host, port: Number(portText) };
|
||||
assert.strictEqual((await send(addr, { type: "ping" })).type, "pong");
|
||||
|
||||
const produced = await runProducerNode(addr);
|
||||
assert.strictEqual(produced.node_status, "completed");
|
||||
assert.strictEqual(produced.coordinator_response.type, "task_recorded");
|
||||
assert.strictEqual(produced.staged_artifact.path, "/vfs/artifacts/export-output.txt");
|
||||
|
||||
await reportNode(addr, "node-export-source");
|
||||
|
||||
const attachedReceiver = await send(addr, {
|
||||
type: "attach_node",
|
||||
tenant: "tenant",
|
||||
project: "project",
|
||||
node: "node-export-receiver",
|
||||
public_key: "node-export-receiver-public-key",
|
||||
});
|
||||
assert.strictEqual(attachedReceiver.type, "node_attached");
|
||||
await reportNode(addr, "node-export-receiver");
|
||||
|
||||
const exportPlan = await send(addr, {
|
||||
type: "export_artifact_to_node",
|
||||
tenant: "tenant",
|
||||
project: "project",
|
||||
actor_user: "user",
|
||||
artifact: "export-output.txt",
|
||||
receiver_node: "node-export-receiver",
|
||||
direct_connectivity: true,
|
||||
failure_reason: "",
|
||||
});
|
||||
assert.strictEqual(exportPlan.type, "artifact_export_plan");
|
||||
assert.strictEqual(exportPlan.source_node, "node-export-source");
|
||||
assert.strictEqual(exportPlan.receiver_node, "node-export-receiver");
|
||||
assert.strictEqual(exportPlan.plan.transport, "NativeQuic");
|
||||
assert.strictEqual(exportPlan.plan.scope.tenant, "tenant");
|
||||
assert.strictEqual(exportPlan.plan.scope.project, "project");
|
||||
assert.strictEqual(exportPlan.plan.scope.process, "vp-export");
|
||||
assert.deepStrictEqual(exportPlan.plan.scope.object, { Artifact: "export-output.txt" });
|
||||
assert.strictEqual(exportPlan.plan.source.node, "node-export-source");
|
||||
assert.strictEqual(exportPlan.plan.destination.node, "node-export-receiver");
|
||||
assert.strictEqual(exportPlan.plan.coordinator_assisted_rendezvous, true);
|
||||
assert.strictEqual(exportPlan.plan.coordinator_bulk_relay_allowed, false);
|
||||
assert.match(exportPlan.plan.authorization_digest, /^sha256:[0-9a-f]{64}$/);
|
||||
|
||||
const crossTenant = await send(addr, {
|
||||
type: "export_artifact_to_node",
|
||||
tenant: "other",
|
||||
project: "project",
|
||||
actor_user: "user",
|
||||
artifact: "export-output.txt",
|
||||
receiver_node: "node-export-receiver",
|
||||
direct_connectivity: true,
|
||||
failure_reason: "",
|
||||
});
|
||||
assert.strictEqual(crossTenant.type, "error");
|
||||
assert.match(crossTenant.message, /tenant mismatch/);
|
||||
|
||||
const failedDirect = await send(addr, {
|
||||
type: "export_artifact_to_node",
|
||||
tenant: "tenant",
|
||||
project: "project",
|
||||
actor_user: "user",
|
||||
artifact: "export-output.txt",
|
||||
receiver_node: "node-export-receiver",
|
||||
direct_connectivity: false,
|
||||
failure_reason: "nat traversal failed",
|
||||
});
|
||||
assert.strictEqual(failedDirect.type, "error");
|
||||
assert.match(failedDirect.message, /nat traversal failed/);
|
||||
assert.match(failedDirect.message, /coordinator bulk relay is disabled/);
|
||||
|
||||
await reportNode(addr, "node-export-receiver", { online: false });
|
||||
const offlineReceiver = await send(addr, {
|
||||
type: "export_artifact_to_node",
|
||||
tenant: "tenant",
|
||||
project: "project",
|
||||
actor_user: "user",
|
||||
artifact: "export-output.txt",
|
||||
receiver_node: "node-export-receiver",
|
||||
direct_connectivity: true,
|
||||
failure_reason: "",
|
||||
});
|
||||
assert.strictEqual(offlineReceiver.type, "error");
|
||||
assert.match(offlineReceiver.message, /offline/);
|
||||
} finally {
|
||||
coordinator.kill("SIGTERM");
|
||||
}
|
||||
|
||||
console.log("Artifact export smoke passed");
|
||||
})().catch((error) => {
|
||||
console.error(error.stack || error.message);
|
||||
process.exit(1);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue