Skip to content

Commit

Permalink
fix: keepalive tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed May 13, 2024
1 parent d5da083 commit d9491ed
Showing 1 changed file with 34 additions and 21 deletions.
55 changes: 34 additions & 21 deletions test/abstract_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1987,17 +1987,26 @@ export default function abstractTest(server, config, ports) {
})
})

client.once('connect', () => {
clock.tick(interval)
assert.strictEqual(spy.callCount, 1)
let pingReceived = 0

clock.tick(interval)
assert.strictEqual(spy.callCount, 2)
client.on('packetreceive', (packet) => {
if (packet.cmd === 'pingresp') {
process.nextTick(() => {
pingReceived++
assert.strictEqual(spy.callCount, pingReceived)

clock.tick(interval)
assert.strictEqual(spy.callCount, 3)
if (pingReceived === 3) {
client.end(true, done)
} else {
clock.tick(interval)
}
})
clock.tick(1)
}
})

client.end(true, done)
client.once('connect', () => {
clock.tick(interval)
})
})

Expand Down Expand Up @@ -2067,22 +2076,26 @@ export default function abstractTest(server, config, ports) {

client.on('packetreceive', (packet) => {
if (packet.cmd === 'puback') {
clock.tick(intervalMs)
process.nextTick(() => {
clock.tick(intervalMs)

received++
received++

if (reschedulePings) {
assert.strictEqual(
spyReschedule.callCount,
received,
)
} else {
assert.strictEqual(spyReschedule.callCount, 0)
}
if (reschedulePings) {
assert.strictEqual(
spyReschedule.callCount,
received,
)
} else {
assert.strictEqual(spyReschedule.callCount, 0)
}

if (received === 2) {
client.end(true, done)
}
if (received === 2) {
client.end(true, done)
}
})

clock.tick(1)
}
})

Expand Down

0 comments on commit d9491ed

Please sign in to comment.