Skip to content

Commit

Permalink
compose.ts throws on container start error
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Feb 28, 2025
1 parent 5262b54 commit de5e289
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions tests/support/compose.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
downAll,
logs,
ps,
upAll,
type IDockerComposeOptions,
} from "docker-compose";
Expand All @@ -14,25 +15,59 @@ const options: IDockerComposeOptions = {
// log: true,
};

export async function testnetUp(): Promise<void> {
export async function testnetUp(): Promise<boolean> {
await upAll(options);

const targetString = "QCReady"; // Replace with the actual string you expect

const targetString = "QCReady";
console.log("waiting for logs");
while (true) {
const logOutput = await logs("alice", options);
// const targetString = `"event":"NewRound","reason":"QCReady"`; // Replace with the actual string you expect

if (logOutput.out.includes(targetString)) {
console.log("testnet started, proceeding...");
break; // Exit the loop when the message is found
}

if (logOutput.out.includes("exited with code")) {
console.log(`last logs: ${logOutput.out}`);
throw new Error("containers exited with non zero code!");
}

const runs = await isComposeRunning(composeFilePath);
if (!runs) {
console.log(`last logs: ${logOutput.out}`);

throw new Error("containers are not running!");

Check failure on line 40 in tests/support/compose.ts

View workflow job for this annotation

GitHub Actions / e2e-tests

error: containers are not running!

at <anonymous> (/home/runner/work/open-libra-sdk/open-libra-sdk/tests/support/compose.ts:40:13)

Check failure on line 40 in tests/support/compose.ts

View workflow job for this annotation

GitHub Actions / e2e-tests

error: containers are not running!

at <anonymous> (/home/runner/work/open-libra-sdk/open-libra-sdk/tests/support/compose.ts:40:13)

Check failure on line 40 in tests/support/compose.ts

View workflow job for this annotation

GitHub Actions / e2e-tests

error: containers are not running!

at <anonymous> (/home/runner/work/open-libra-sdk/open-libra-sdk/tests/support/compose.ts:40:13)

Check failure on line 40 in tests/support/compose.ts

View workflow job for this annotation

GitHub Actions / e2e-tests

error: containers are not running!

at <anonymous> (/home/runner/work/open-libra-sdk/open-libra-sdk/tests/support/compose.ts:40:13)

Check failure on line 40 in tests/support/compose.ts

View workflow job for this annotation

GitHub Actions / e2e-tests

error: containers are not running!

at <anonymous> (/home/runner/work/open-libra-sdk/open-libra-sdk/tests/support/compose.ts:40:13)

Check failure on line 40 in tests/support/compose.ts

View workflow job for this annotation

GitHub Actions / e2e-tests

error: containers are not running!

at <anonymous> (/home/runner/work/open-libra-sdk/open-libra-sdk/tests/support/compose.ts:40:13)

Check failure on line 40 in tests/support/compose.ts

View workflow job for this annotation

GitHub Actions / e2e-tests

error: containers are not running!

at <anonymous> (/home/runner/work/open-libra-sdk/open-libra-sdk/tests/support/compose.ts:40:13)

Check failure on line 40 in tests/support/compose.ts

View workflow job for this annotation

GitHub Actions / e2e-tests

error: containers are not running!

at <anonymous> (/home/runner/work/open-libra-sdk/open-libra-sdk/tests/support/compose.ts:40:13)

Check failure on line 40 in tests/support/compose.ts

View workflow job for this annotation

GitHub Actions / e2e-tests

error: containers are not running!

at <anonymous> (/home/runner/work/open-libra-sdk/open-libra-sdk/tests/support/compose.ts:40:13)

Check failure on line 40 in tests/support/compose.ts

View workflow job for this annotation

GitHub Actions / e2e-tests

error: containers are not running!

at <anonymous> (/home/runner/work/open-libra-sdk/open-libra-sdk/tests/support/compose.ts:40:13)
}
// check logs every second
await new Promise((resolve) => setTimeout(resolve, 1_000));
}
return true;
}

export async function testnetDown() {
await downAll(options);
}

async function isComposeRunning(path: string): Promise<boolean> {
try {
const result = await ps({
cwd: path,
commandOptions: [["--format", "json"]],
});
if (!result || result.data.services.length == 0) {
console.error("[ERROR] no containers running");
return false;
}
for (const service of result.data.services) {
if (service.state != "running") {
console.error(`[ERROR] service ${service.name} is not running`);
return false;
}
}
} catch {
console.error("[ERROR] could not run docker-compose ps");
return false;
}
return true;
}

0 comments on commit de5e289

Please sign in to comment.