Skip to content

Commit

Permalink
chopsticks tail support
Browse files Browse the repository at this point in the history
  • Loading branch information
timbrinded committed Sep 12, 2023
1 parent a30131d commit ddf7923
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
7 changes: 5 additions & 2 deletions packages/cli/src/cmds/runNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ const resolveTailChoice = async (env: Environment) => {
resolve("");
});
} else {
const logFilePath = reportLogLocation(true);
const logFilePath = process.env.MOON_LOG_LOCATION;

// eslint-disable-next-line prefer-const
let currentReadPosition = 0;
Expand Down Expand Up @@ -451,11 +451,12 @@ const resolveTailChoice = async (env: Environment) => {

if (char === "p") {
tailing = false;
printLogs(fs.statSync(logFilePath).size, 0);
// printLogs(fs.statSync(logFilePath).size, currentReadPosition);
ui.updateBottomBar(bottomBarContents + resumePauseProse[1]);
}

if (char === "r") {
printLogs(fs.statSync(logFilePath).size, currentReadPosition);
tailing = true;
ui.updateBottomBar(bottomBarContents + resumePauseProse[0]);
}
Expand All @@ -469,12 +470,14 @@ const resolveTailChoice = async (env: Environment) => {

if (char === "t") {
await resolveTestChoice(env, true);
ui.updateBottomBar(bottomBarContents + resumePauseProse[tailing ? 0 : 1]);
}

if (char === "g") {
ui.rl.input.pause();
tailing = false;
await resolveGrepChoice(env, true);
ui.updateBottomBar(bottomBarContents + resumePauseProse[tailing ? 0 : 1]);
tailing = true;
ui.rl.input.resume();
}
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/internal/cmdFunctions/tempLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export function reportLogLocation(silent: boolean = false) {
let consoleMessage = "";
let filePath = "";
try {
filePath = path.join(dirPath, result.find((file) => path.extname(file) == ".log")!);
filePath = process.env.MOON_LOG_LOCATION
? process.env.MOON_LOG_LOCATION
: path.join(dirPath, result.find((file) => path.extname(file) == ".log")!);
consoleMessage = ` 🪵 Log location: ${filePath}`;
} catch (e) {
console.error(e);
Expand Down
11 changes: 7 additions & 4 deletions packages/cli/src/internal/localNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ export async function launchNode(cmd: string, args: string[], name: string): Pro
process.once("SIGINT", onProcessInterrupt);

const runningNode = spawn(cmd, args);

const fsStream = fs.createWriteStream(
path.join(
const logLocation = path
.join(
dirPath,
`${path.basename(cmd)}_node_${args.find((a) => a.includes("port"))?.split("=")[1]}_${
runningNode.pid
}.log`
)
);
.replaceAll("node_node_undefined", "chopsticks");

process.env.MOON_LOG_LOCATION = logLocation;

const fsStream = fs.createWriteStream(logLocation);

runningNode.once("exit", () => {
process.removeListener("exit", onProcessExit);
Expand Down
14 changes: 7 additions & 7 deletions test/suites/chopsticks/test-chopsticks-basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describeSuite({
});

it({
id: "T1",
id: "T01",
title: "Query the chain",
timeout: 60000,
// modifier:"only",
Expand All @@ -33,7 +33,7 @@ describeSuite({
});

it({
id: "T2",
id: "T02",
title: "Send a transaction ",
timeout: 60000,
test: async function () {
Expand All @@ -47,7 +47,7 @@ describeSuite({
});

it({
id: "T3",
id: "T03",
title: "Skips multiple blocks ",
timeout: 60000,
test: async function () {
Expand All @@ -59,7 +59,7 @@ describeSuite({
});

it({
id: "T4",
id: "T04",
title: "Can overwrite storage values",
timeout: 60000,
test: async function () {
Expand Down Expand Up @@ -94,7 +94,7 @@ describeSuite({
});

it({
id: "T5",
id: "T05",
title: "Do an upgrade test",
timeout: 120000,
modifier: "skip",
Expand All @@ -109,7 +109,7 @@ describeSuite({
});

it({
id: "T6",
id: "T06",
title: "Create block and check events",
timeout: 60000,
test: async function () {
Expand All @@ -126,7 +126,7 @@ describeSuite({
});

it({
id: "T7",
id: "T07",
title: "Create block, allow failures and check events",
timeout: 60000,
test: async function () {
Expand Down
4 changes: 2 additions & 2 deletions test/suites/chopsticks/test-chopsticks-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describeSuite({
});

it({
id: "T1",
id: "T01",
title: "Check initial balance is zero",
test: async function () {
const currentBalance = (await api.query.system.account(RANDOM_ADDRESS)).data.free;
Expand All @@ -27,7 +27,7 @@ describeSuite({
});

it({
id: "T2",
id: "T02",
title: "Send a transaction ",
test: async function () {
const currentBalance = (await api.query.system.account(RANDOM_ADDRESS)).data.free;
Expand Down
4 changes: 2 additions & 2 deletions test/suites/chopsticks/test-chopsticks-state2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describeSuite({
});

it({
id: "T1",
id: "T01",
title: "Check initial balance is zero",
test: async function () {
const currentBalance = (await api.query.system.account(RANDOM_ADDRESS)).data.free;
Expand All @@ -27,7 +27,7 @@ describeSuite({
});

it({
id: "T2",
id: "T02",
title: "Send a transaction ",
test: async function () {
const currentBalance = (await api.query.system.account(RANDOM_ADDRESS)).data.free;
Expand Down

0 comments on commit ddf7923

Please sign in to comment.