Add ability to stop test nodes and httpds

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2023-07-04 09:56:23 +02:00
parent e5dccba3ff
commit 78663937d1
3 changed files with 32 additions and 4 deletions
+2
View File
@@ -303,6 +303,8 @@ export async function createSourceBrowsingFixture(
{ type: "refs-synced", remote: alice.nodeId, rid },
2000,
);
await alice.stopNode();
await bob.stopNode();
}
export async function createCobsFixture(peer: RadiclePeer) {
+5 -2
View File
@@ -19,7 +19,9 @@ import { killAllProcesses } from "@tests/support/process.js";
const workspacePaths = [Path.join(tmpDir, "peers"), Path.join(tmpDir, "repos")];
export default async function globalSetup(_config: FullConfig): Promise<void> {
export default async function globalSetup(
_config: FullConfig,
): Promise<() => void> {
try {
await assertRadInstalled();
} catch (error) {
@@ -45,7 +47,7 @@ export default async function globalSetup(_config: FullConfig): Promise<void> {
dataDir: Path.resolve(Path.join(tmpDir, "peers")),
outputLog: FsSync.createWriteStream(
Path.join(tmpDir, "peerManager.log"),
).setMaxListeners(20),
).setMaxListeners(16),
});
const palm = await peerManager.startPeer({
@@ -62,6 +64,7 @@ export default async function globalSetup(_config: FullConfig): Promise<void> {
console.log("Creating cobs fixture");
await createCobsFixture(palm);
console.log("Running tests");
await palm.stopNode();
} else {
await startPalmHttpd();
}
+25 -2
View File
@@ -115,6 +115,8 @@ export class RadiclePeer {
#outputLog: Stream.Writable;
#gitOptions?: Record<string, string>;
#listenSocketAddr?: string;
#nodeProcess?: ExecaChildProcess;
#httpdProcess?: ExecaChildProcess;
private constructor(props: {
checkoutPath: string;
@@ -183,7 +185,10 @@ export class RadiclePeer {
}
public async startHttpd(port: number) {
void this.spawn("radicle-httpd", ["--listen", `0.0.0.0:${port}`]);
this.#httpdProcess = this.spawn("radicle-httpd", [
"--listen",
`0.0.0.0:${port}`,
]);
await waitOn({
resources: [`tcp:127.0.0.1:${port}`],
@@ -191,6 +196,15 @@ export class RadiclePeer {
});
}
public async stopHttpd(port: number) {
this.#httpdProcess?.kill("SIGTERM");
await waitOn({
resources: [`tcp:127.0.0.1:${port}`],
reverse: true,
});
}
public async startNode(params?: {
trackingScope?: "trusted" | "all";
trackingPolicy?: "track" | "block";
@@ -213,7 +227,7 @@ export class RadiclePeer {
args.push("--tracking-policy", params.trackingPolicy);
}
void this.spawn("radicle-node", args);
this.#nodeProcess = this.spawn("radicle-node", args);
await waitOn({
resources: [`socket:${this.#socket}`],
@@ -239,6 +253,15 @@ export class RadiclePeer {
);
}
public async stopNode() {
this.#nodeProcess?.kill("SIGTERM");
await waitOn({
resources: [`socket:${this.#socket}`],
reverse: true,
});
}
public async waitForRoutes(rid: string, ...nodes: string[]) {
let remaining = nodes;