Skip to content

Commit

Permalink
fix: allow writes to finish in run-once mode to fix snaspshot tests (#…
Browse files Browse the repository at this point in the history
…291)

* fix: allow writes to finish in run-once mode to fix snaspshot tests

* enh: clarify snapshot scripts and add convenience script
  • Loading branch information
bard authored Sep 20, 2023
1 parent afa44d7 commit 2d43801
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"scripts": {
"start": "node dist/src/index.js",
"dev": "tsx watch src/index.ts | pino-pretty",
"dev:snap:before": "NODE_ENV=snapshot-testing INDEXED_CHAINS=mainnet STORAGE_DIR=test/snapshot.BEFORE/data CACHE_DIR=test/snapshot.BEFORE/cache tsx src/index.ts --to-block 17199975 --run-once | pino-pretty",
"dev:snap:after": "NODE_ENV=snapshot-testing INDEXED_CHAINS=mainnet STORAGE_DIR=test/snapshot.AFTER/data CACHE_DIR=test/snapshot.AFTER/cache tsx src/index.ts --to-block 17199975 --run-once | pino-pretty",
"dev:snap:compare": "diff -r --brief test/snapshot.BEFORE/data test/snapshot.AFTER/data",
"test:snapshot:generate-before": "NODE_ENV=snapshot-testing INDEXED_CHAINS=mainnet STORAGE_DIR=test/snapshot.BEFORE/data CACHE_DIR=test/snapshot.BEFORE/cache tsx src/index.ts --to-block 17199975 --run-once | pino-pretty",
"test:snapshot:generate-after": "NODE_ENV=snapshot-testing INDEXED_CHAINS=mainnet STORAGE_DIR=test/snapshot.AFTER/data CACHE_DIR=test/snapshot.AFTER/cache tsx src/index.ts --to-block 17199975 --run-once | pino-pretty",
"test:snapshot:compare": "diff -r --brief test/snapshot.BEFORE/data test/snapshot.AFTER/data",
"test:snapshot": "test -d test/snapshot.BEFORE/data || (echo 'Missing BEFORE snapshot.'; exit 1); npm run test:snapshot:generate-after && npm run test:snapshot:compare && echo 'Snapshots match!'",
"build": "tsc",
"lint": "eslint src",
"test": "vitest run --reporter verbose",
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ async function main(): Promise<void> {
)
);
// Workaround for active handles preventing process to terminate
// TODO investigate with console.log(process._getActiveHandles())
// (to investigate: console.log(process._getActiveHandles()))
// Note: the delay is necessary to allow completing writes.
baseLogger.info("exiting");
await new Promise((resolve) => setTimeout(resolve, 1000));
process.exit(0);
} else {
// Promises will be resolved once the initial catchup is done. Afterwards, services
Expand Down

0 comments on commit 2d43801

Please sign in to comment.