Skip to content

Commit

Permalink
Correct kill the process
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed Sep 25, 2024
1 parent f5cfc0d commit f70e7d8
Show file tree
Hide file tree
Showing 11 changed files with 287 additions and 362 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,10 @@ jobs:
- name: Fee projection tests
run: |
ci_run killall -INT zksync_server || true
ci_run zk_supervisor test fees --chain era &> ${{ env.FEES_LOGS_DIR }}/era.log
ci_run zk_supervisor test fees --no-kill --chain era &> ${{ env.FEES_LOGS_DIR }}/era.log
ci_run zk_supervisor test fees --no-kill --chain validium &> ${{ env.FEES_LOGS_DIR }}/validium.log
ci_run zk_supervisor test fees --no-kill --chain custom_token &> ${{ env.FEES_LOGS_DIR }}/custom_token.log
ci_run zk_supervisor test fees --no-kill --chain consensus &> ${{ env.FEES_LOGS_DIR }}/consensus.log
- name: Run revert tests
run: |
Expand Down
55 changes: 45 additions & 10 deletions core/tests/ts-integration/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ import { DataAvailabityMode, NodeMode, TestEnvironment } from './types';
import { Reporter } from './reporter';
import * as yaml from 'yaml';
import { L2_BASE_TOKEN_ADDRESS } from 'zksync-ethers/build/utils';
import { loadConfig, loadEcosystem, shouldLoadConfigFromFile } from 'utils/build/file-configs';
import { FileConfig, loadConfig, loadEcosystem, shouldLoadConfigFromFile } from 'utils/build/file-configs';
import { NodeSpawner } from './utils';
import { logsTestPath } from 'utils/build/logs';
import * as nodefs from 'node:fs/promises';
import { exec } from 'utils';

const enableConsensus = process.env.ENABLE_CONSENSUS === 'true';

async function logsPath(chain: string, name: string): Promise<string> {
return await logsTestPath(chain, 'logs/server/', name);
}

/**
* Attempts to connect to server.
Expand Down Expand Up @@ -60,8 +70,10 @@ function getMainWalletPk(pathToHome: string): string {
/*
Loads the environment for file based configs.
*/
async function loadTestEnvironmentFromFile(chain: string): Promise<TestEnvironment> {
async function loadTestEnvironmentFromFile(fileConfig: FileConfig): Promise<TestEnvironment> {
let chain = fileConfig.chain!;
const pathToHome = path.join(__dirname, '../../../..');
let spawnNode = process.env.SPAWN_NODE;
let nodeMode;
if (process.env.EXTERNAL_NODE == 'true') {
nodeMode = NodeMode.External;
Expand All @@ -75,18 +87,42 @@ async function loadTestEnvironmentFromFile(chain: string): Promise<TestEnvironme
let configsFolderSuffix = nodeMode == NodeMode.External ? 'external_node' : undefined;
let generalConfig = loadConfig({ pathToHome, chain, config: 'general.yaml', configsFolderSuffix });
let secretsConfig = loadConfig({ pathToHome, chain, config: 'secrets.yaml', configsFolderSuffix });
let contracts = loadConfig({ pathToHome, chain, config: 'contracts.yaml', configsFolderSuffix });

const network = ecosystem.l1_network.toLowerCase();
let mainWalletPK = getMainWalletPk(pathToHome);

const l2NodeUrl = generalConfig.api.web3_json_rpc.http_url;

await waitForServer(l2NodeUrl);
const l1NodeUrl = secretsConfig.l1.l1_rpc_url;

const pathToMainLogs = await logsPath(fileConfig.chain!, 'server.log');
let mainLogs = await nodefs.open(pathToMainLogs, 'a');
let l2Node;
if (spawnNode) {
// Before starting any actual logic, we need to ensure that the server is running (it may not
// be the case, for example, right after deployment on stage).
const autoKill: boolean = process.env.NO_KILL !== 'true';
if (autoKill) {
try {
await exec(`killall -KILL zksync_server`);
} catch (err) {
console.log(`ignored error: ${err}`);
}
}
let mainNodeSpawner = new NodeSpawner(pathToHome, mainLogs, fileConfig, {
enableConsensus,
ethClientWeb3Url: l1NodeUrl,
apiWeb3JsonRpcHttpUrl: l2NodeUrl,
baseTokenAddress: contracts.l1.base_token_addr
});

l2Node = await mainNodeSpawner.spawnMainNode();
}

const l2Provider = new zksync.Provider(l2NodeUrl);
const baseTokenAddress = await l2Provider.getBaseTokenContractAddress();

const l1NodeUrl = secretsConfig.l1.l1_rpc_url;
const wsL2NodeUrl = generalConfig.api.web3_json_rpc.ws_url;

const contractVerificationUrl = generalConfig.contract_verifier.url;
Expand Down Expand Up @@ -129,7 +165,6 @@ async function loadTestEnvironmentFromFile(chain: string): Promise<TestEnvironme
const maxLogsLimit = parseInt(generalConfig.api.web3_json_rpc.req_entities_limit);

const healthcheckPort = generalConfig.api.healthcheck.port;
const l2NodePid = 0;
return {
maxLogsLimit,
pathToHome,
Expand All @@ -142,7 +177,7 @@ async function loadTestEnvironmentFromFile(chain: string): Promise<TestEnvironme
network,
mainWalletPK,
l2NodeUrl,
l2NodePid,
l2Node,
l1NodeUrl,
wsL2NodeUrl,
contractVerificationUrl,
Expand All @@ -165,10 +200,10 @@ async function loadTestEnvironmentFromFile(chain: string): Promise<TestEnvironme
}

export async function loadTestEnvironment(): Promise<TestEnvironment> {
const { loadFromFile, chain } = shouldLoadConfigFromFile();
const fileConfig = shouldLoadConfigFromFile();

if (loadFromFile) {
return await loadTestEnvironmentFromFile(chain);
if (fileConfig.loadFromFile) {
return await loadTestEnvironmentFromFile(fileConfig);
}
return await loadTestEnvironmentFromEnv();
}
Expand Down Expand Up @@ -260,7 +295,7 @@ export async function loadTestEnvironmentFromEnv(): Promise<TestEnvironment> {
network,
mainWalletPK,
l2NodeUrl,
l2NodePid,
l2Node: undefined,
l1NodeUrl,
wsL2NodeUrl,
healthcheckPort,
Expand Down
33 changes: 3 additions & 30 deletions core/tests/ts-integration/src/jest-setup/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { shouldLoadConfigFromFile } from 'utils/build/file-configs';
import { bigIntReplacer } from '../helpers';
import { TestContextOwner, loadTestEnvironment } from '../index';
import path from 'path';
import { runServerInBackground } from '../utils';
import { NodeSpawner, runServerInBackground } from '../utils';
import { exec } from 'utils';
import fs from 'node:fs/promises';
import { logsTestPath } from 'utils/build/logs';

declare global {
var __ZKSYNC_TEST_CONTEXT_OWNER__: TestContextOwner;
Expand All @@ -22,36 +24,7 @@ async function performSetup(_globalConfig: any, _projectConfig: any) {
console.log('');
globalThis.rawWriteToConsole = console.log;

// Before starting any actual logic, we need to ensure that the server is running (it may not
// be the case, for example, right after deployment on stage).
const fileConfig = shouldLoadConfigFromFile();
const pathToHome = path.join(__dirname, '../../../../..');
const autoKill: boolean = !fileConfig.loadFromFile || !process.env.NO_KILL;

if (autoKill) {
try {
await exec(`killall -KILL zksync_server`);
} catch (err) {
console.log(`ignored error: ${ err }`);
}
}

let components = 'api,tree,eth,state_keeper,da_dispatcher,vm_runner_protective_reads';
const env = process.env;

let proc = runServerInBackground({
components: [components],
stdio: ['ignore', 'ignore', 'ignore'],
cwd: pathToHome,
env: env,
useZkInception: fileConfig.loadFromFile,
chain: fileConfig.chain
});

proc.unref();

let testEnvironment = await loadTestEnvironment();
testEnvironment.l2NodePid = proc.pid!;
const testContextOwner = new TestContextOwner(testEnvironment);
const testContext = await testContextOwner.setupContext();

Expand Down
75 changes: 0 additions & 75 deletions core/tests/ts-integration/src/tester.ts

This file was deleted.

4 changes: 3 additions & 1 deletion core/tests/ts-integration/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Node, NodeType } from './utils';

export enum NodeMode {
Main,
External
Expand Down Expand Up @@ -58,7 +60,7 @@ export interface TestEnvironment {
/*
* L2 node PID
*/
l2NodePid: number;
l2Node: Node<NodeType.MAIN> | undefined;
/**
* Plaintext name of the L1 network name (i.e. `localhost` or `goerli`).
*/
Expand Down
Loading

0 comments on commit f70e7d8

Please sign in to comment.