From 0b6b6f64ab5984cc8dbaeb1b80136ce1c8a1e3b7 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Thu, 11 Apr 2024 09:49:58 +0100 Subject: [PATCH] fix: Anvil start retry in case something bad. Fix colors. (#5673) Please read [contributing guidelines](CONTRIBUTING.md) and remove this line. --- .circleci/config.yml | 2 +- yarn-project/end-to-end/Earthfile | 2 +- yarn-project/end-to-end/package.json | 2 +- yarn-project/end-to-end/package.local.json | 2 +- .../end-to-end/src/fixtures/snapshot_manager.ts | 16 ++++++++++++---- yarn-project/foundation/src/log/logger.ts | 2 +- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 739f1b542fc..9a6268b2c75 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -715,7 +715,7 @@ jobs: - *setup_env - run: name: "Test" - command: cond_spot_run_container end-to-end 8 ./src/e2e_token_contract/ + command: cond_spot_run_container end-to-end 16 ./src/e2e_token_contract/ aztec_manifest_key: end-to-end <<: *defaults_e2e_test diff --git a/yarn-project/end-to-end/Earthfile b/yarn-project/end-to-end/Earthfile index 20a59e4b78c..85d6ffb644a 100644 --- a/yarn-project/end-to-end/Earthfile +++ b/yarn-project/end-to-end/Earthfile @@ -117,7 +117,7 @@ e2e-lending-contract: e2e-token-contract: LOCALLY WITH DOCKER --load end-to-end=../+end-to-end - RUN docker run --rm -e LOG_LEVEL=silent -e DEBUG=aztec:e2e_token_contract* end-to-end ./src/e2e_token_contract/ + RUN docker run --rm -e LOG_LEVEL=silent -e DEBUG=aztec:e2e* end-to-end ./src/e2e_token_contract/ END e2e-authwit-test: diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index b5df23580ee..f49c55a71e7 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -15,7 +15,7 @@ "clean": "rm -rf ./dest .tsbuildinfo", "formatting": "run -T prettier --check ./src \"!src/web/main.js\" && run -T eslint ./src", "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src", - "test": "LOG_LEVEL=${LOG_LEVEL:-verbose} NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --testTimeout=120000 --forceExit", + "test": "LOG_LEVEL=${LOG_LEVEL:-verbose} DEBUG_COLORS=1 NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --testTimeout=120000 --forceExit", "test:integration": "concurrently -k -s first -c reset,dim -n test,anvil \"yarn test:integration:run\" \"anvil\"", "test:integration:run": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --no-cache --runInBand --config jest.integration.config.json" }, diff --git a/yarn-project/end-to-end/package.local.json b/yarn-project/end-to-end/package.local.json index d7161c03659..9c4d44ff289 100644 --- a/yarn-project/end-to-end/package.local.json +++ b/yarn-project/end-to-end/package.local.json @@ -2,6 +2,6 @@ "scripts": { "build": "yarn clean && tsc -b && webpack", "formatting": "run -T prettier --check ./src \"!src/web/main.js\" && run -T eslint ./src", - "test": "LOG_LEVEL=${LOG_LEVEL:-verbose} NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --testTimeout=120000 --forceExit" + "test": "LOG_LEVEL=${LOG_LEVEL:-verbose} DEBUG_COLORS=1 NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --testTimeout=120000 --forceExit" } } diff --git a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts index f5536ea1cdd..a7cf971f861 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -12,6 +12,7 @@ import { import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment'; import { asyncMap } from '@aztec/foundation/async-map'; import { createDebugLogger } from '@aztec/foundation/log'; +import { makeBackoff, retry } from '@aztec/foundation/retry'; import { resolver, reviver } from '@aztec/foundation/serialize'; import { type PXEService, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; @@ -175,10 +176,17 @@ export class SnapshotManager { // Start anvil. We go via a wrapper script to ensure if the parent dies, anvil dies. this.logger.verbose('Starting anvil...'); - const ethereumHostPort = await getPort(); - aztecNodeConfig.rpcUrl = `http://localhost:${ethereumHostPort}`; - const anvil = createAnvil({ anvilBinary: './scripts/anvil_kill_wrapper.sh', port: ethereumHostPort }); - await anvil.start(); + const anvil = await retry( + async () => { + const ethereumHostPort = await getPort(); + aztecNodeConfig.rpcUrl = `http://localhost:${ethereumHostPort}`; + const anvil = createAnvil({ anvilBinary: './scripts/anvil_kill_wrapper.sh', port: ethereumHostPort }); + await anvil.start(); + return anvil; + }, + 'Start anvil', + makeBackoff([5, 5, 5]), + ); // Deploy our L1 contracts. this.logger.verbose('Deploying L1 contracts...'); diff --git a/yarn-project/foundation/src/log/logger.ts b/yarn-project/foundation/src/log/logger.ts index d85647c17bb..b2cfbc31b39 100644 --- a/yarn-project/foundation/src/log/logger.ts +++ b/yarn-project/foundation/src/log/logger.ts @@ -97,7 +97,7 @@ function logWithDebug(debug: debug.Debugger, level: LogLevel, msg: string, data? function getPrefix(debugLogger: debug.Debugger, level: LogLevel) { const levelLabel = currentLevel !== level ? ` ${level.toUpperCase()}` : ''; const prefix = `${debugLogger.namespace.replace(/^aztec:/, '')}${levelLabel}`; - if (!isNode || !isatty(process.stderr.fd)) { + if ((!isNode || !isatty(process.stderr.fd)) && !process.env.DEBUG_COLORS) { return prefix; } const colorIndex = debug.selectColor(debugLogger.namespace) as number;