Skip to content

Commit 49ffbe3

Browse files
committed
add test timeout
1 parent d249be6 commit 49ffbe3

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

packages/cli/src/command-helpers/contracts.test.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ async function retry<T>(operation: () => Promise<T>, maxRetries = 3, sleepMs = 5
142142
throw lastError;
143143
}
144144

145+
const withTimeout = <T>(promise: Promise<T>, timeoutMs: number): Promise<T> => {
146+
return Promise.race([
147+
promise,
148+
new Promise<T>((_, reject) =>
149+
setTimeout(() => reject(new Error(`Operation timed out after ${timeoutMs}ms`)), timeoutMs)
150+
)
151+
]);
152+
};
153+
145154
describe('getStartBlockForContract', { concurrent: true }, async () => {
146155
const registry = await loadRegistry();
147156
const contractService = new ContractService(registry);
@@ -152,7 +161,7 @@ describe('getStartBlockForContract', { concurrent: true }, async () => {
152161
{ timeout: 50_000 },
153162
async ({ expect }) => {
154163
const startBlock = await retry(
155-
() => contractService.getStartBlock(network, contract),
164+
async () => withTimeout(contractService.getStartBlock(network, contract), 5000),
156165
10,
157166
);
158167
expect(parseInt(startBlock)).toBe(startBlockExp);

packages/cli/tests/cli/__snapshots__/init.test.ts.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,13 @@ exports[`Init > From existing subgraph > From existing subgraph 2`] = `0`;
270270

271271
exports[`Init > From existing subgraph > From existing subgraph 3`] = `
272272
"
273-
Subgraph userfrom-existing-subgraph created in subgraph
273+
Subgraph userfrom-existing-subgraph created in from-subgraph
274274
275275
Next steps:
276276
277277
1. Run \`graph auth\` to authenticate with your deploy key.
278278
279-
2. Type \`cd subgraph\` to enter the subgraph.
279+
2. Type \`cd from-subgraph\` to enter the subgraph.
280280
281281
3. Run \`yarn deploy\` to deploy the subgraph.
282282

packages/cli/tests/cli/init.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ describe(
257257
'--protocol',
258258
'subgraph',
259259
'user/from-existing-subgraph',
260-
path.join(fromSubgraphBaseDir, 'subgraph'),
260+
path.join(fromSubgraphBaseDir, 'from-subgraph'),
261261
],
262-
path.join('init', 'subgraph', 'subgraph'),
262+
path.join('init', 'subgraph', 'from-subgraph'),
263263
{
264264
exitCode: 0,
265265
timeout: 100_000,

0 commit comments

Comments
 (0)