Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): close all open connections in abstract_client test #1917

Merged
merged 24 commits into from
Aug 8, 2024
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e9702d2
fix: tets hang up
MaximoLiberata Jul 19, 2024
f44744e
Merge branch 'mqttjs:main' into improve-tests
MaximoLiberata Jul 26, 2024
a141420
fix(test): close open connections
MaximoLiberata Jul 26, 2024
19e6c3f
test: catch error
MaximoLiberata Jul 26, 2024
25da706
feat: move clean_method class to help
MaximoLiberata Jul 31, 2024
54a56ac
fix: hang tests
MaximoLiberata Jul 31, 2024
72add25
fix: lint style
MaximoLiberata Jul 31, 2024
0290cda
fix: teardown helper functionality
robertsLando Aug 1, 2024
7ae2764
docs: change examples according new changes
MaximoLiberata Aug 1, 2024
eed4ef3
Merge branch 'main' into improve-tests
MaximoLiberata Aug 1, 2024
308448f
fix(test): close all open connections in abstract_client test
MaximoLiberata Aug 1, 2024
d031475
fix(lint): rename variable
MaximoLiberata Aug 1, 2024
34ee338
Merge branch 'main' into improve-tests
robertsLando Aug 2, 2024
8d154b0
fix(test): prevent hanging of some tests
MaximoLiberata Aug 2, 2024
f70e825
test: let the responsibility to beforeEachExec method of closing the …
MaximoLiberata Aug 2, 2024
0e9edea
lint: fix style
MaximoLiberata Aug 2, 2024
2dc39f2
fix(test): do not listen connect event
MaximoLiberata Aug 3, 2024
bd9bde7
Revert "fix(test): do not listen connect event"
MaximoLiberata Aug 4, 2024
02c4e50
fix(test): do not for close client connection
MaximoLiberata Aug 5, 2024
6165051
Merge branch 'main' into improve-tests
robertsLando Aug 5, 2024
2e7c366
fix(test): hanging by clock
MaximoLiberata Aug 5, 2024
b5b725a
test: remove unnecesary timeout
MaximoLiberata Aug 5, 2024
aecb808
Merge branch 'main' into improve-tests
MaximoLiberata Aug 7, 2024
600b925
fix(typo): rename variable
MaximoLiberata Aug 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: remove unnecesary timeout
  • Loading branch information
MaximoLiberata committed Aug 5, 2024
commit b5b725a087345d1f89f1683fba30dc6b6c66300d
68 changes: 53 additions & 15 deletions test/abstract_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,7 @@ export default function abstractTest(server, config, ports) {

client.once('connect', () => {
assert.strictEqual(client.queue.length, 0)
setTimeout(() => {
client.end(true, done)
}, 10)
client.end((err) => done(err))
})
})

Expand All @@ -672,9 +670,7 @@ export default function abstractTest(server, config, ports) {
client.publish('test', 'test', { qos: 0 })
assert.strictEqual(client.queue.length, 0)
client.on('connect', () => {
setTimeout(() => {
client.end(true, done)
}, 10)
client.end((err) => done(err))
})
})

Expand All @@ -687,9 +683,7 @@ export default function abstractTest(server, config, ports) {
client.unsubscribe('test')
assert.strictEqual(client.queue.length, 2)
client.on('connect', () => {
setTimeout(() => {
client.end(true, done)
}, 10)
client.end((err) => done(err))
})
})

Expand Down Expand Up @@ -857,9 +851,7 @@ export default function abstractTest(server, config, ports) {

client.on('connect', () => {
assert.isTrue(called)
setTimeout(() => {
client.end(true, done)
}, 10)
client.end((err) => done(err))
})
})

Expand Down Expand Up @@ -1356,6 +1348,17 @@ export default function abstractTest(server, config, ports) {
})

function testQosHandleMessage(qos, done) {
teardownHelper.add({ executeOnce: true, order: 1 }, () => {
if (clock) {
clock.restore()
}
})

const clock = sinon.useFakeTimers({
...fakeTimersOptions,
toFake: ['setTimeout'],
})

const client = connect()

let messageEventCount = 0
Expand All @@ -1369,10 +1372,14 @@ export default function abstractTest(server, config, ports) {
if (handleMessageCount === 10) {
setTimeout(() => {
client.end(true, done)
})
}, 10)

clock.tick(10)
}
callback()
}, 10)

clock.tick(10)
}

client.on('message', (topic, message, packet) => {
Expand Down Expand Up @@ -3270,15 +3277,33 @@ export default function abstractTest(server, config, ports) {
})

it('should always cleanup successfully on reconnection', function _test(t, done) {
teardownHelper.add({ executeOnce: true, order: 1 }, () => {
if (clock) {
clock.restore()
}
})

const clock = sinon.useFakeTimers({
...fakeTimersOptions,
toFake: ['setTimeout'],
})

const client = connect({
host: 'this_hostname_should_not_exist',
connectTimeout: 0,
reconnectPeriod: 1,
})

// bind client.end so that when it is called it is automatically passed in the done callback
setTimeout(() => {
client.end(done)
}, 100)
setTimeout(() => {
client.end(done)
}, 10)

clock.tick(10)
}, 10)

clock.tick(10)
})

it('should emit connack timeout error', function _test(t, done) {
Expand Down Expand Up @@ -4023,6 +4048,17 @@ export default function abstractTest(server, config, ports) {
})

it('should be able to pub/sub if reconnect() is called at out of close handler', function _test(t, done) {
teardownHelper.add({ executeOnce: true, order: 1 }, () => {
if (clock) {
clock.restore()
}
})

const clock = sinon.useFakeTimers({
...fakeTimersOptions,
toFake: ['setTimeout'],
})

const client = connect({ reconnectPeriod: 0 })
let tryReconnect = true
let reconnectEvent = false
Expand All @@ -4033,6 +4069,8 @@ export default function abstractTest(server, config, ports) {
setTimeout(() => {
client.reconnect()
}, 100)

clock.tick(100)
} else {
assert.isTrue(reconnectEvent)
done()
Expand Down