Skip to content

Commit 800a4dd

Browse files
committed
Updated dependencies and more stable tests
1 parent 5f56cf8 commit 800a4dd

File tree

3 files changed

+110
-80
lines changed

3 files changed

+110
-80
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,23 @@
7070
"inherits": "^2.0.3",
7171
"minimist": "^1.2.0",
7272
"mqtt-packet": "^5.4.0",
73-
"pump": "^1.0.2",
73+
"pump": "^2.0.0",
7474
"readable-stream": "^2.3.3",
7575
"reinterval": "^1.1.0",
7676
"split2": "^2.1.1",
7777
"websocket-stream": "^5.0.1",
7878
"xtend": "^4.0.1"
7979
},
8080
"devDependencies": {
81-
"@types/node": "^8.0.28",
81+
"@types/node": "^8.0.57",
8282
"browserify": "^14.4.0",
8383
"codecov": "^3.0.0",
8484
"global": "^4.3.2",
8585
"istanbul": "^0.4.5",
8686
"mkdirp": "^0.5.1",
8787
"mocha": "^3.5.3",
8888
"mqtt-connection": "^3.0.0",
89-
"nsp": "^2.8.0",
89+
"nsp": "^3.1.0",
9090
"pre-commit": "^1.2.2",
9191
"rimraf": "^2.6.2",
9292
"should": "^13.1.3",
@@ -96,9 +96,9 @@
9696
"through2": "^2.0.3",
9797
"tslint": "^5.7.0",
9898
"tslint-config-standard": "^7.0.0",
99-
"typescript": "^2.6.1",
100-
"uglify-js": "^3.1.6",
101-
"ws": "^3.1.0",
99+
"typescript": "^2.6.2",
100+
"uglify-js": "^3.2.1",
101+
"ws": "^3.3.2",
102102
"zuul": "^3.11.1",
103103
"zuul-ngrok": "^4.0.0"
104104
},

test/abstract_client.js

Lines changed: 104 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -291,35 +291,37 @@ module.exports = function (server, config) {
291291
'system/registry/event/new_device', 'system/+/+/new_device'
292292
],
293293
function (err) {
294-
client.end()
295-
if (err) {
296-
return done(new Error(err))
297-
}
298-
done()
294+
client.end(function () {
295+
if (err) {
296+
return done(new Error(err))
297+
}
298+
done()
299+
})
299300
}
300301
)
301302
})
302303

303304
it('should return an error (via callbacks) for topic #/event', function (done) {
304305
var client = connect()
305306
client.subscribe(['#/event', 'event#', 'event+'], function (err) {
306-
client.end()
307-
if (err) {
308-
return done()
309-
}
310-
done(new Error('Validations do NOT work'))
307+
client.end(false, function () {
308+
if (err) {
309+
return done()
310+
}
311+
done(new Error('Validations do NOT work'))
312+
})
311313
})
312314
})
313315

314316
it('should return an empty array for duplicate subs', function (done) {
315317
var client = connect()
316318
client.subscribe('event', function (err, granted1) {
317319
if (err) {
318-
return done()
320+
return done(err)
319321
}
320322
client.subscribe('event', function (err, granted2) {
321323
if (err) {
322-
return done()
324+
return done(err)
323325
}
324326
granted2.should.Array()
325327
granted2.should.be.empty()
@@ -331,33 +333,36 @@ module.exports = function (server, config) {
331333
it('should return an error (via callbacks) for topic #/event', function (done) {
332334
var client = connect()
333335
client.subscribe('#/event', function (err) {
334-
client.end()
335-
if (err) {
336-
return done()
337-
}
338-
done(new Error('Validations do NOT work'))
336+
client.end(function () {
337+
if (err) {
338+
return done()
339+
}
340+
done(new Error('Validations do NOT work'))
341+
})
339342
})
340343
})
341344

342345
it('should return an error (via callbacks) for topic event#', function (done) {
343346
var client = connect()
344347
client.subscribe('event#', function (err) {
345-
client.end()
346-
if (err) {
347-
return done()
348-
}
349-
done(new Error('Validations do NOT work'))
348+
client.end(function () {
349+
if (err) {
350+
return done()
351+
}
352+
done(new Error('Validations do NOT work'))
353+
})
350354
})
351355
})
352356

353357
it('should return an error (via callbacks) for topic system/#/event', function (done) {
354358
var client = connect()
355359
client.subscribe('system/#/event', function (err) {
356-
client.end()
357-
if (err) {
358-
return done()
359-
}
360-
done(new Error('Validations do NOT work'))
360+
client.end(function () {
361+
if (err) {
362+
return done()
363+
}
364+
done(new Error('Validations do NOT work'))
365+
})
361366
})
362367
})
363368

@@ -375,11 +380,12 @@ module.exports = function (server, config) {
375380
it('should return an error (via callbacks) for topic system/+/#/event', function (done) {
376381
var client = connect()
377382
client.subscribe('system/+/#/event', function (err) {
378-
client.end()
379-
if (err) {
380-
return done()
381-
}
382-
done(new Error('Validations do NOT work'))
383+
client.end(true, function () {
384+
if (err) {
385+
return done()
386+
}
387+
done(new Error('Validations do NOT work'))
388+
})
383389
})
384390
})
385391
})
@@ -395,7 +401,9 @@ module.exports = function (server, config) {
395401

396402
client.once('connect', function () {
397403
client.queue.length.should.equal(0)
398-
client.end(true, done)
404+
setTimeout(function () {
405+
client.end(true, done)
406+
}, 10)
399407
})
400408
})
401409

@@ -404,72 +412,94 @@ module.exports = function (server, config) {
404412

405413
client.publish('test', 'test', {qos: 0})
406414
client.queue.length.should.equal(0)
407-
client.end(true, done)
415+
client.on('connect', function () {
416+
setTimeout(function () {
417+
client.end(true, done)
418+
}, 10)
419+
})
408420
})
409421

410-
it('should not queue qos != 0 messages', function (done) {
422+
it('should queue qos != 0 messages', function (done) {
411423
var client = connect({queueQoSZero: false})
412424

413425
client.publish('test', 'test', {qos: 1})
414426
client.publish('test', 'test', {qos: 2})
415427
client.subscribe('test')
416428
client.unsubscribe('test')
417429
client.queue.length.should.equal(2)
418-
client.end(true, done)
430+
client.on('connect', function () {
431+
setTimeout(function () {
432+
client.end(true, done)
433+
}, 10)
434+
})
419435
})
420436

421437
it('should call cb if an outgoing QoS 0 message is not sent', function (done) {
422438
var client = connect({queueQoSZero: false})
439+
var called = false
423440

424441
client.publish('test', 'test', {qos: 0}, function () {
425-
client.end(true, done)
442+
called = true
443+
})
444+
445+
client.on('connect', function () {
446+
called.should.equal(true)
447+
setTimeout(function () {
448+
client.end(true, done)
449+
}, 10)
426450
})
427451
})
428452

429-
if (!process.env.TRAVIS) {
430-
it('should delay ending up until all inflight messages are delivered', function (done) {
431-
var client = connect()
453+
it('should delay ending up until all inflight messages are delivered', function (done) {
454+
var client = connect()
455+
var subscribeCalled = false
432456

433-
client.on('connect', function () {
434-
client.subscribe('test', function () {
457+
client.on('connect', function () {
458+
client.subscribe('test', function () {
459+
subscribeCalled = true
460+
})
461+
client.publish('test', 'test', function () {
462+
client.end(false, function () {
463+
subscribeCalled.should.be.equal(true)
435464
done()
436465
})
437-
client.publish('test', 'test', function () {
438-
client.end()
439-
})
440466
})
441467
})
468+
})
442469

443-
it('wait QoS 1 publish messages', function (done) {
444-
var client = connect()
470+
it('wait QoS 1 publish messages', function (done) {
471+
var client = connect()
472+
var messageReceived = false
445473

446-
client.on('connect', function () {
447-
client.subscribe('test')
448-
client.publish('test', 'test', { qos: 1 }, function () {
449-
client.end()
450-
})
451-
client.on('message', function () {
474+
client.on('connect', function () {
475+
client.subscribe('test')
476+
client.publish('test', 'test', { qos: 1 }, function () {
477+
client.end(false, function () {
478+
messageReceived.should.equal(true)
452479
done()
453480
})
454481
})
482+
client.on('message', function () {
483+
messageReceived = true
484+
})
485+
})
455486

456-
server.once('client', function (serverClient) {
457-
serverClient.on('subscribe', function () {
458-
serverClient.on('publish', function (packet) {
459-
serverClient.publish(packet)
460-
})
487+
server.once('client', function (serverClient) {
488+
serverClient.on('subscribe', function () {
489+
serverClient.on('publish', function (packet) {
490+
serverClient.publish(packet)
461491
})
462492
})
463493
})
494+
})
464495

465-
it('does not wait acks when force-closing', function (done) {
466-
// non-running broker
467-
var client = connect('mqtt://localhost:8993')
496+
it('does not wait acks when force-closing', function (done) {
497+
// non-running broker
498+
var client = connect('mqtt://localhost:8993')
468499

469-
client.publish('test', 'test', { qos: 1 })
470-
client.end(true, done)
471-
})
472-
}
500+
client.publish('test', 'test', { qos: 1 })
501+
client.end(true, done)
502+
})
473503
})
474504

475505
describe('publishing', function () {
@@ -480,16 +510,21 @@ module.exports = function (server, config) {
480510

481511
client.publish(topic, payload)
482512

483-
server.once('client', function (serverClient) {
513+
server.on('client', onClient)
514+
515+
function onClient (serverClient) {
516+
serverClient.once('connect', function () {
517+
server.removeListener('client', onClient)
518+
})
519+
484520
serverClient.once('publish', function (packet) {
485521
packet.topic.should.equal(topic)
486522
packet.payload.toString().should.equal(payload)
487523
packet.qos.should.equal(0)
488524
packet.retain.should.equal(false)
489-
client.end()
490-
done()
525+
client.end(true, done)
491526
})
492-
})
527+
}
493528
})
494529

495530
it('should publish a message (online)', function (done) {

test/websocket_client.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@ function attachWebsocketServer (wsServer) {
1616

1717
wss.on('connection', function (ws) {
1818
var stream = websocket(ws)
19-
stream.pause()
2019
var connection = new Connection(stream)
2120

22-
setImmediate(() => {
23-
stream.resume()
24-
})
25-
2621
wsServer.emit('client', connection)
2722
stream.on('error', function () {})
2823
connection.on('error', function () {})

0 commit comments

Comments
 (0)