Skip to content

Commit

Permalink
Merge pull request #122 from galadriel-ai/kristjan/e2e-tests-console-…
Browse files Browse the repository at this point in the history
…log-timestamps

Basic timestamps for console.logs for e2e cron job
  • Loading branch information
kristjanpeterson1 authored Jul 16, 2024
2 parents c8aaa29 + fc061ed commit dec56d4
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions contracts/tasks/e2eCron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@ import {spawn} from 'child_process';

const TIMEOUT_SECONDS: number = 60 * 60

const getTimestamp = (): string => {
return new Date().toISOString()
}

async function main(): Promise<void> {
const command = 'npx';
const contractAddress = process.env.TEST_CONTRACT_ADDRESS
const oracleAddress = process.env.TEST_ORACLE_ADDRESS
const network = process.env.TEST_NETWORK
const slackWebHookUrl = process.env.TEST_SLACK_WEBHOOK_URL
if (!contractAddress) {
console.log(".env is missing TEST_CONTRACT_ADDRESS")
console.log(getTimestamp(), ".env is missing TEST_CONTRACT_ADDRESS")
return
}
if (!oracleAddress) {
console.log(".env is missing ORACLE_ADDRESS")
console.log(getTimestamp(), ".env is missing ORACLE_ADDRESS")
return
}
if (!network) {
console.log(".env is missing TEST_NETWORK")
console.log(getTimestamp(), ".env is missing TEST_NETWORK")
return
}
if (!slackWebHookUrl) {
console.log(".env is missing TEST_SLACK_WEBHOOK_URL")
console.log(getTimestamp(), ".env is missing TEST_SLACK_WEBHOOK_URL")
return
}
const args: string[] = [
Expand All @@ -36,9 +40,9 @@ async function main(): Promise<void> {

let previousResult = false;
while (true) {
console.log(`Running e2e tests with `)
console.log(getTimestamp(), `Running e2e tests with `)
previousResult = await runTests(command, args, slackWebHookUrl, previousResult)
console.log(`Run done, sleeping for ${TIMEOUT_SECONDS} seconds`)
console.log(getTimestamp(), `Run done, sleeping for ${TIMEOUT_SECONDS} seconds`)
await new Promise((resolve) => setTimeout(resolve, TIMEOUT_SECONDS * 1000));
}
}
Expand All @@ -63,7 +67,7 @@ async function runTests(

childProcess.stderr.on('data', (data) => {
stderrData += data.toString();
console.error(data.toString());
console.error(getTimestamp(), data.toString());
});

childProcess.on('close', (code) => {
Expand All @@ -75,7 +79,7 @@ async function runTests(
});
});
} catch (e: any) {
console.error(e.message);
console.error(getTimestamp(), e.message);
await postSlackMessage(
e.message,
slackWebHookUrl,
Expand Down Expand Up @@ -119,13 +123,13 @@ async function postSlackMessage(
}
)
} catch (e: any) {
console.error("Failed to post msg to slack", e.message)
console.error(getTimestamp(), "Failed to post msg to slack", e.message)
}
}

main()
.then(() => process.exit(0))
.catch((error: any) => {
console.error(error);
console.error(getTimestamp(), error);
process.exit(1);
});

0 comments on commit dec56d4

Please sign in to comment.