Skip to content

Commit d688652

Browse files
authored
chore(cli-repl): (hopefully) fix flaky mongocryptd test (#754)
Example failure: [2021/04/01 09:26:24.908] 1) MongocryptdManager [2021/04/01 09:26:24.908] with network testing [2021/04/01 09:26:24.908] performs keepalive pings: [2021/04/01 09:26:24.908] SyntaxError: Unexpected end of JSON input [2021/04/01 09:26:24.908] at JSON.parse (<anonymous>) [2021/04/01 09:26:24.908] at Context.<anonymous> (src/mongocryptd-manager.spec.ts:184:19) Presumably this is happening because the connections aren’t established fast enough when the host is under load, e.g. because multiple tests are running at the same time. Using the `eventually` helper would be the right thing to do here anyway, because it allows for a longer timeout while at the same time finishing faster under normal circumstances.
1 parent f2f2469 commit d688652

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/cli-repl/src/mongocryptd-manager.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import Nanobus from 'nanobus';
33
import { promises as fs } from 'fs';
44
import path from 'path';
5-
import { promisify } from 'util';
65
import { getMongocryptdPaths, MongocryptdManager } from './mongocryptd-manager';
76
import type { MongoshBus } from '@mongosh/types';
87
import { ShellHomeDirectory } from './config-directory';
98
import { startTestServer } from '../../../testing/integration-testing-hooks';
9+
import { eventually } from '../test/helpers';
1010
import { expect } from 'chai';
1111

1212
describe('getMongocryptdPaths', () => {
@@ -180,8 +180,9 @@ describe('MongocryptdManager', () => {
180180
manager.idleShutdownTimeoutSecs = 1;
181181
await manager.start();
182182
const pidfile = path.join(manager.path, 'mongocryptd.pid');
183-
await promisify(setTimeout)(2000);
184-
expect(JSON.parse(await fs.readFile(pidfile, 'utf8')).connections).to.be.greaterThan(1);
183+
await eventually(async() => {
184+
expect(JSON.parse(await fs.readFile(pidfile, 'utf8')).connections).to.be.greaterThan(1);
185+
});
185186
});
186187
});
187188
});

0 commit comments

Comments
 (0)