Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add ability to stop test nodes and httpds
Sebastian Martinez committed 2 years ago
commit 78663937d15d7c09bfd0133f8e85a2d92e0888a1
parent e5dccba3ff4c545ce0375f005dfbe89b73daa36d
3 files changed +32 -4
modified tests/support/fixtures.ts
@@ -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) {
modified tests/support/globalSetup.ts
@@ -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();
  }
modified tests/support/peerManager.ts
@@ -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;