-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
executable file
·82 lines (66 loc) · 1.87 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
var abstractTest = require('mqtt/test/abstract_store'),
mqttNedbStore = require('./'),
mqtt = require('mqtt'),
concat = require('concat-stream');
describe('mqtt nedb store', function () {
abstractTest(function (done) {
done(null, mqttNedbStore.single('/tmp/.mqtt-nedb-store', {}));
});
});
describe('mqtt nedb store manager', function () {
var manager;
beforeEach(function () {
manager = mqttNedbStore('/tmp/.mqtt-nedb-store', {});
});
afterEach(function (done) {
manager.close(done);
});
describe('incoming', function () {
abstractTest(function (done) {
done(null, manager.incoming);
});
});
describe('outgoing', function () {
abstractTest(function (done) {
done(null, manager.outgoing);
});
});
});
describe('mqtt.connect flow', function () {
var server,
manager;
beforeEach(function (done) {
server = new mqtt.Server();
server.listen(8883, done);
server.on('client', function (client) {
client.on('connect', function () {
client.connack({returnCode: 0});
});
});
manager = mqttNedbStore('/tmp/.mqtt-nedb-store', {});
});
it('should resend messages', function (done) {
var client = mqtt.connect({
port: 8883,
incomingStore: manager.incoming,
outgoingStore: manager.outgoing
});
client.publish('hello', 'world', {qos: 1});
server.once('client', function (serverClient) {
serverClient.once('publish', function () {
serverClient.stream.destroy();
manager.outgoing.createStream().pipe(concat(function (list) {
list.length.should.equal(1);
}));
});
server.once('client', function (serverClient2) {
serverClient2.once('publish', function (packet) {
serverClient2.puback(packet);
client.end();
done();
});
});
});
});
});