Skip to content

Commit

Permalink
Make some tests less flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
tulios committed Mar 14, 2019
1 parent 47c5fab commit 75cacf1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/consumer/__tests__/runner.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
})
Expand All @@ -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)
})
})

0 comments on commit 75cacf1

Please sign in to comment.