Skip to content

Commit 82ae28b

Browse files
committed
Revert await-dependencies script
1 parent b10e40e commit 82ae28b

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

packages/delegator-e2e/src/await-dependencies.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { deployDeleGatorEnvironment } from '@metamask/delegation-toolkit/utils';
1111
import { ENTRYPOINT_ADDRESS_V07 } from 'permissionless';
1212
import { writeFile } from 'fs/promises';
1313

14-
const POLL_INTERVAL_MS = 1000;
14+
const POLL_INTERVAL_MS = 1_000;
15+
// timeout is 5 minutes, which is sufficiently long to never trigger a false positive
16+
const TIMEOUT_MS = 5 * 60_000;
17+
let hasTimedOut = false;
1518

1619
const waitFor = async (name: string, url: string) => {
1720
let isAvailable: boolean | undefined = undefined;
@@ -32,10 +35,8 @@ const waitFor = async (name: string, url: string) => {
3235
await client
3336
.request({ method: 'web3_clientVersion' })
3437
.then(() => (isAvailable = true))
35-
.catch((e: any) => {
36-
isAvailable = (e as Error).name !== 'HttpRequestError';
37-
});
38-
} while (!isAvailable);
38+
.catch((_) => (isAvailable = false));
39+
} while (!isAvailable && !hasTimedOut);
3940

4041
console.log(`${name} is available`);
4142
};
@@ -61,14 +62,27 @@ const deployEnvironment = async () => {
6162
};
6263

6364
(async () => {
65+
const startTime = Date.now();
66+
67+
const timeoutRef = setTimeout(() => (hasTimedOut = true), TIMEOUT_MS);
68+
6469
await waitFor('Blockchain node', nodeUrl);
65-
const waitingForDependencies = Promise.all([
70+
71+
const environment = await deployEnvironment();
72+
await writeFile('./.gator-env.json', JSON.stringify(environment, null, 2));
73+
74+
await Promise.all([
6675
waitFor('Bundler', bundlerUrl),
6776
waitFor('Mock paymaster', paymasterUrl),
6877
]);
6978

70-
const environment = await deployEnvironment();
71-
await writeFile('./.gator-env.json', JSON.stringify(environment, null, 2));
79+
clearTimeout(timeoutRef);
7280

73-
await waitingForDependencies;
81+
if (hasTimedOut) {
82+
console.error('Timed out waiting for dependencies');
83+
process.exitCode = 1;
84+
} else {
85+
const duration = Date.now() - startTime;
86+
console.log(`Dependencies ready in ${duration}ms`);
87+
}
7488
})();

0 commit comments

Comments
 (0)