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

Added a unit test, check offline queue in QoS 1 #264

Merged
merged 5 commits into from
Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
],
"license": "MIT",
"devDependencies": {
"@types/node": "^12.6.3",
"@typescript-eslint/eslint-plugin": "^1.12.0",
"@typescript-eslint/parser": "^1.12.0",
"@types/node": "^12.6.8",
"@typescript-eslint/eslint-plugin": "^1.13.0",
"@typescript-eslint/parser": "^1.13.0",
"compute-mode": "^1.0.0",
"concat-stream": "^2.0.0",
"convert-hrtime": "^3.0.0",
Expand All @@ -76,8 +76,8 @@
"websocket-stream": "^5.5.0"
},
"dependencies": {
"aedes-packet": "^2.0.0",
"aedes-persistence": "^6.0.0",
"aedes-packet": "^2.1.0",
"aedes-persistence": "^7.1.1",
"bulk-write-stream": "^2.0.0",
"end-of-stream": "^1.4.1",
"fastfall": "^1.5.1",
Expand Down
70 changes: 70 additions & 0 deletions test/qos1.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,76 @@ test('publish QoS 1', function (t) {
})
})

test('publish QoS 1 and check offline queue', function (t) {
t.plan(13)

var broker = aedes()
var publisher = connect(setup(broker), { clean: false })
var subscriber = connect(setup(broker), { clean: false, clientId: 'abcde' })
var subscriberClient = {
id: 'abcde'
}
var expected = {
cmd: 'publish',
topic: 'hello',
qos: 1,
dup: false,
retain: false
}
var expectedAck = {
cmd: 'puback',
retain: false,
qos: 0,
dup: false,
length: 2,
messageId: 10
}
var sent = {
cmd: 'publish',
topic: 'hello',
payload: 'world',
qos: 1,
messageId: 10,
retain: false
}
var queue = []
subscribe(t, subscriber, 'hello', 1, function () {
publisher.outStream.on('data', function (packet) {
t.deepEqual(packet, expectedAck, 'ack packet must patch')
})
subscriber.outStream.on('data', function (packet) {
queue.push(packet)
delete packet.payload
delete packet.length
t.notEqual(packet.messageId, undefined, 'messageId is assigned a value')
t.notEqual(packet.messageId, 10, 'messageId should be unique')
expected.messageId = packet.messageId
t.deepEqual(packet, expected, 'publish packet must patch')
if (queue.length === 2) {
setImmediate(() => {
for (var i = 0; i < queue.length; i++) {
broker.persistence.outgoingClearMessageId(subscriberClient, queue[i], function (_, origPacket) {
if (origPacket) {
delete origPacket.brokerId
delete origPacket.brokerCounter
delete origPacket.payload
delete origPacket.messageId
delete sent.payload
delete sent.messageId
t.deepEqual(origPacket, sent, 'origPacket must match')
}
})
}
t.end()
})
}
})
publisher.inStream.write(sent)
sent.payload = 'world2world'
publisher.inStream.write(sent)
})
})

test('subscribe QoS 1', function (t) {
var broker = aedes()
var publisher = connect(setup(broker))
Expand Down