Skip to content

Commit

Permalink
fix: tets hang up (#1906)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximoLiberata committed Jul 22, 2024
1 parent 11bb9bd commit c462530
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions test/abstract_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3202,15 +3202,30 @@ export default function abstractTest(server, config, ports) {
})

it('should emit connack timeout error', function _test(t, done) {
const client = connect({
connectTimeout: 0,
reconnectPeriod: 5000,
// Use fake timers to simulate the timeout. The setTimeout inside the client connection
// will inactive by other tests (maybe) causing this test never ends.
const clock = sinon.useFakeTimers({
...fakeTimersOptions,
toFake: ['setTimeout'],
})

client.on('error', (err) => {
assert.equal(err.message, 'connack timeout')
client.end(true, done)
const connectTimeout = 10

t.after(() => {
clock.restore()
})

const client = connect({
connectTimeout,
reconnectPeriod: 5000,
})
.on('connect', () => {
clock.tick(connectTimeout)
})
.on('error', (err) => {
assert.equal(err.message, 'connack timeout')
client.end(true, done)
})
})

it(
Expand Down

0 comments on commit c462530

Please sign in to comment.