From 75cacf1fdfdbf807b225cbc29aac2976c2a44ca2 Mon Sep 17 00:00:00 2001 From: tulios Date: Thu, 14 Mar 2019 10:20:40 +0100 Subject: [PATCH] Make some tests less flaky --- src/consumer/__tests__/runner.spec.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/consumer/__tests__/runner.spec.js b/src/consumer/__tests__/runner.spec.js index 3f650632b..a1e61cff5 100644 --- a/src/consumer/__tests__/runner.spec.js +++ b/src/consumer/__tests__/runner.spec.js @@ -4,6 +4,7 @@ const { KafkaJSProtocolError, KafkaJSNotImplemented } = require('../../errors') const { createErrorFromCode } = require('../../protocol/error') const InstrumentationEventEmitter = require('../../instrumentation/emitter') const { newLogger } = require('testHelpers') +const sleep = require('../../utils/sleep') const UNKNOWN = -1 const REBALANCE_IN_PROGRESS = 27 @@ -198,6 +199,11 @@ describe('Consumer > Runner', () => { runner.scheduleFetch = jest.fn() await runner.start() + + // scheduleFetch in runner#start is async, and we never wait for it, + // so we have to wait a bit to give the callback a chance of being executed + await sleep(100) + expect(runner.scheduleFetch).not.toHaveBeenCalled() expect(onCrash).toHaveBeenCalledWith(unknowError) }) @@ -209,6 +215,11 @@ describe('Consumer > Runner', () => { }) await runner.start() + + // scheduleFetch in runner#start is async, and we never wait for it, + // so we have to wait a bit to give the callback a chance of being executed + await sleep(100) + expect(onCrash).toHaveBeenCalledWith(notImplementedError) }) })