Skip to content

Commit db7181a

Browse files
committed
Add timeout, to fail after dependencies are not available before 5 minutes. Fix issue where dependency is marked as unavailable even when it's responding, if the method is not supported.
1 parent b10e40e commit db7181a

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

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

Lines changed: 22 additions & 5 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,9 @@ 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+
// as soon as the node is responding (even if it's MethodNotFoundRpcError)
39+
.catch((e) => (isAvailable = (e as Error).name !== 'HttpRequestError'));
40+
} while (!isAvailable && !hasTimedOut);
3941

4042
console.log(`${name} is available`);
4143
};
@@ -61,7 +63,12 @@ const deployEnvironment = async () => {
6163
};
6264

6365
(async () => {
66+
const startTime = Date.now();
67+
68+
const timeoutRef = setTimeout(() => (hasTimedOut = true), TIMEOUT_MS);
69+
6470
await waitFor('Blockchain node', nodeUrl);
71+
6572
const waitingForDependencies = Promise.all([
6673
waitFor('Bundler', bundlerUrl),
6774
waitFor('Mock paymaster', paymasterUrl),
@@ -71,4 +78,14 @@ const deployEnvironment = async () => {
7178
await writeFile('./.gator-env.json', JSON.stringify(environment, null, 2));
7279

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

0 commit comments

Comments
 (0)