Skip to content

Commit 87be5a2

Browse files
committed
Revert await-dependencies script
1 parent b10e40e commit 87be5a2

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ 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+
const TIMEOUT_MS = 60_000;
16+
let hasTimedOut = false;
1517

1618
const waitFor = async (name: string, url: string) => {
1719
let isAvailable: boolean | undefined = undefined;
@@ -32,10 +34,8 @@ const waitFor = async (name: string, url: string) => {
3234
await client
3335
.request({ method: 'web3_clientVersion' })
3436
.then(() => (isAvailable = true))
35-
.catch((e: any) => {
36-
isAvailable = (e as Error).name !== 'HttpRequestError';
37-
});
38-
} while (!isAvailable);
37+
.catch((_) => (isAvailable = false));
38+
} while (!isAvailable && !hasTimedOut);
3939

4040
console.log(`${name} is available`);
4141
};
@@ -61,14 +61,27 @@ const deployEnvironment = async () => {
6161
};
6262

6363
(async () => {
64+
const startTime = Date.now();
65+
66+
const timeoutRef = setTimeout(() => (hasTimedOut = true), TIMEOUT_MS);
67+
6468
await waitFor('Blockchain node', nodeUrl);
65-
const waitingForDependencies = Promise.all([
69+
70+
const environment = await deployEnvironment();
71+
await writeFile('./.gator-env.json', JSON.stringify(environment, null, 2));
72+
73+
await Promise.all([
6674
waitFor('Bundler', bundlerUrl),
6775
waitFor('Mock paymaster', paymasterUrl),
6876
]);
6977

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

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

0 commit comments

Comments
 (0)