Skip to content

Commit 047fad5

Browse files
committed
refactor: Improve binary index test reliability
Add backoff retry and cleanup.
1 parent 9d42d51 commit 047fad5

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

packages/cli/tests/binary/index.bin-spec.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { ChildProcess } from 'child_process';
1+
import { ChildProcess } from 'node:child_process';
2+
import { rm } from 'node:fs/promises';
3+
4+
import { retry } from 'async';
5+
26
import { buildRubyProject, runInBackground, waitForStdout } from './helpers';
37
import { Client } from 'jayson/promise';
48
import { AppMapRpc } from '@appland/rpc';
@@ -28,9 +32,11 @@ describe('appmap', () => {
2832

2933
afterEach(() => {
3034
indexProcess.kill();
35+
// remove the temporary project directory
36+
void rm(projectPath, { recursive: true });
3137
});
3238

33-
it('picks up the correct configuration', async () => {
39+
const checkStats = async () => {
3440
const { error, result } = await rpcClient.request(AppMapRpc.Stats.V1.Method, {});
3541
expect(error).toBeUndefined();
3642
expect(result).toStrictEqual({
@@ -44,7 +50,15 @@ describe('appmap', () => {
4450
tables: ['api_keys', 'pg_attribute', 'pg_type', 'users'],
4551
numAppMaps: 1,
4652
});
47-
});
53+
};
54+
55+
// it might take a moment for the maps to be indexed
56+
it('picks up the correct configuration', backoffRetry(checkStats));
4857
});
4958
});
5059
});
60+
61+
function backoffRetry<T>(fn: () => Promise<T>, times = 10, initialDelay = 10): () => Promise<T> {
62+
const interval = (retryCount: number) => Math.pow(2, retryCount) * initialDelay;
63+
return () => retry({ times, interval }, fn);
64+
}

0 commit comments

Comments
 (0)