Skip to content

Commit 1b3bb3d

Browse files
committed
test many wills
1 parent 3d7fd28 commit 1b3bb3d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/will.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,40 @@ test('delivers old will in case of a crash', async (t) => {
117117
t.assert.equal(received.length, 1, 'only one will has been delivered')
118118
})
119119

120+
test('delivers many old wills in case of a crash', async (t) => {
121+
t.plan(1)
122+
123+
const numWills = 100
124+
const persistence = await memorySetup({ id: 'anotherBroker' })
125+
const will = {
126+
topic: 'mywill',
127+
payload: Buffer.from('last will'),
128+
qos: 0,
129+
retain: false
130+
}
131+
132+
for (let id = 0; id < numWills; id++) {
133+
const cWill = structuredClone(will)
134+
cWill.topic = 'mywill'
135+
await persistence.putWill({ id: `myClientId${id}` }, cWill)
136+
}
137+
138+
const interval = 10 // ms, so that the will check happens fast!
139+
const broker = await Aedes.createBroker({
140+
persistence,
141+
heartbeatInterval: interval,
142+
authorizePublish: (client, packet, callback) => {
143+
callback(null)
144+
}
145+
})
146+
147+
t.after(() => broker.close())
148+
149+
const received = await willsFromBroker(broker)
150+
await delay(100) // give Aedes some time to process to ensure that all wills are sent
151+
t.assert.equal(received.length, numWills, 'all wills have been delivered')
152+
})
153+
120154
test('deliver old will without authorization in case of a crash', async (t) => {
121155
t.plan(1)
122156

0 commit comments

Comments
 (0)