From f79b435b51a2da0ddf5973ce6739dc616bc883f1 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 1 Apr 2021 11:39:15 +0200 Subject: [PATCH] chore(cli-repl): (hopefully) fix flaky mongocryptd test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 () [2021/04/01 09:26:24.908] at Context. (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. --- packages/cli-repl/src/mongocryptd-manager.spec.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/cli-repl/src/mongocryptd-manager.spec.ts b/packages/cli-repl/src/mongocryptd-manager.spec.ts index 66e122e040..e756388e9c 100644 --- a/packages/cli-repl/src/mongocryptd-manager.spec.ts +++ b/packages/cli-repl/src/mongocryptd-manager.spec.ts @@ -2,11 +2,11 @@ import Nanobus from 'nanobus'; import { promises as fs } from 'fs'; import path from 'path'; -import { promisify } from 'util'; import { getMongocryptdPaths, MongocryptdManager } from './mongocryptd-manager'; import type { MongoshBus } from '@mongosh/types'; import { ShellHomeDirectory } from './config-directory'; import { startTestServer } from '../../../testing/integration-testing-hooks'; +import { eventually } from '../test/helpers'; import { expect } from 'chai'; describe('getMongocryptdPaths', () => { @@ -180,8 +180,9 @@ describe('MongocryptdManager', () => { manager.idleShutdownTimeoutSecs = 1; await manager.start(); const pidfile = path.join(manager.path, 'mongocryptd.pid'); - await promisify(setTimeout)(2000); - expect(JSON.parse(await fs.readFile(pidfile, 'utf8')).connections).to.be.greaterThan(1); + await eventually(async() => { + expect(JSON.parse(await fs.readFile(pidfile, 'utf8')).connections).to.be.greaterThan(1); + }); }); }); });