Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: wait for healthcheck in waitForNodeToStart #3325

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions core/tests/ts-integration/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,14 @@ export class NodeSpawner {
const { fileConfig, pathToHome, options, logs } = this;

const testMode = overrides?.newPubdataPrice != null || overrides?.newL1GasPrice != null;
let healthcheckPort;

console.log('Overrides: ', overrides);

if (fileConfig.loadFromFile) {
this.restoreConfig();
const config = this.readFileConfig();
healthcheckPort = config['api']['healthcheck']['port'];
config['state_keeper']['transaction_slots'] = testMode ? 1 : 8192;

if (overrides != null) {
Expand Down Expand Up @@ -199,6 +201,7 @@ export class NodeSpawner {

this.writeFileConfig(config);
} else {
healthcheckPort = process.env.API_HEALTHCHECK_PORT;
env['DATABASE_MERKLE_TREE_MODE'] = 'full';

if (overrides != null) {
Expand Down Expand Up @@ -267,8 +270,9 @@ export class NodeSpawner {
chain: fileConfig.chain
});

healthcheckPort ??= '3071';
// Wait until the main node starts responding.
await waitForNodeToStart(proc, options.apiWeb3JsonRpcHttpUrl);
await waitForNodeToStart(proc, options.apiWeb3JsonRpcHttpUrl, healthcheckPort);
return new Node(proc, options.apiWeb3JsonRpcHttpUrl, NodeType.MAIN);
}

Expand All @@ -293,21 +297,25 @@ export class NodeSpawner {
}
}

async function waitForNodeToStart(proc: ChildProcessWithoutNullStreams, l2Url: string) {
async function waitForNodeToStart(proc: ChildProcessWithoutNullStreams, l2Url: string, healthcheckPort: string) {
while (true) {
try {
const l2Provider = new zksync.Provider(l2Url);
const blockNumber = await l2Provider.getBlockNumber();
if (blockNumber != 0) {
console.log(`Initialized node API on ${l2Url}; latest block: ${blockNumber}`);
break;
const nodeHealth = (await fetch(`http://127.0.0.1:${healthcheckPort}/health`)).status;
if (nodeHealth == 200) {
const l2Provider = new zksync.Provider(l2Url);
const blockNumber = await l2Provider.getBlockNumber();
if (blockNumber != 0) {
console.log(`Initialized node API on ${l2Url}; latest block: ${blockNumber}`);
break;
}
}
} catch (err) {
if (proc.exitCode != null) {
assert.fail(`server failed to start, exitCode = ${proc.exitCode}`);
}
console.log(`Node waiting for API on ${l2Url}`);
await utils.sleep(1);
// Ignore
}
if (proc.exitCode != null) {
assert.fail(`server failed to start, exitCode = ${proc.exitCode}`);
}
console.log(`Node waiting for API on ${l2Url}`);
await utils.sleep(1);
}
}
Loading