Skip to content

Commit

Permalink
Merge pull request mqttjs#737 from mqttjs/update
Browse files Browse the repository at this point in the history
Updated dependencies and more stable tests
  • Loading branch information
mcollina authored Dec 9, 2017
2 parents 4d51ded + 800a4dd commit 21084f5
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 80 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,23 @@
"inherits": "^2.0.3",
"minimist": "^1.2.0",
"mqtt-packet": "^5.4.0",
"pump": "^1.0.2",
"pump": "^2.0.0",
"readable-stream": "^2.3.3",
"reinterval": "^1.1.0",
"split2": "^2.1.1",
"websocket-stream": "^5.0.1",
"xtend": "^4.0.1"
},
"devDependencies": {
"@types/node": "^8.0.28",
"@types/node": "^8.0.57",
"browserify": "^14.4.0",
"codecov": "^3.0.0",
"global": "^4.3.2",
"istanbul": "^0.4.5",
"mkdirp": "^0.5.1",
"mocha": "^3.5.3",
"mqtt-connection": "^3.0.0",
"nsp": "^2.8.0",
"nsp": "^3.1.0",
"pre-commit": "^1.2.2",
"rimraf": "^2.6.2",
"should": "^13.1.3",
Expand All @@ -96,9 +96,9 @@
"through2": "^2.0.3",
"tslint": "^5.7.0",
"tslint-config-standard": "^7.0.0",
"typescript": "^2.6.1",
"uglify-js": "^3.1.6",
"ws": "^3.1.0",
"typescript": "^2.6.2",
"uglify-js": "^3.2.1",
"ws": "^3.3.2",
"zuul": "^3.11.1",
"zuul-ngrok": "^4.0.0"
},
Expand Down
173 changes: 104 additions & 69 deletions test/abstract_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,35 +291,37 @@ module.exports = function (server, config) {
'system/registry/event/new_device', 'system/+/+/new_device'
],
function (err) {
client.end()
if (err) {
return done(new Error(err))
}
done()
client.end(function () {
if (err) {
return done(new Error(err))
}
done()
})
}
)
})

it('should return an error (via callbacks) for topic #/event', function (done) {
var client = connect()
client.subscribe(['#/event', 'event#', 'event+'], function (err) {
client.end()
if (err) {
return done()
}
done(new Error('Validations do NOT work'))
client.end(false, function () {
if (err) {
return done()
}
done(new Error('Validations do NOT work'))
})
})
})

it('should return an empty array for duplicate subs', function (done) {
var client = connect()
client.subscribe('event', function (err, granted1) {
if (err) {
return done()
return done(err)
}
client.subscribe('event', function (err, granted2) {
if (err) {
return done()
return done(err)
}
granted2.should.Array()
granted2.should.be.empty()
Expand All @@ -331,33 +333,36 @@ module.exports = function (server, config) {
it('should return an error (via callbacks) for topic #/event', function (done) {
var client = connect()
client.subscribe('#/event', function (err) {
client.end()
if (err) {
return done()
}
done(new Error('Validations do NOT work'))
client.end(function () {
if (err) {
return done()
}
done(new Error('Validations do NOT work'))
})
})
})

it('should return an error (via callbacks) for topic event#', function (done) {
var client = connect()
client.subscribe('event#', function (err) {
client.end()
if (err) {
return done()
}
done(new Error('Validations do NOT work'))
client.end(function () {
if (err) {
return done()
}
done(new Error('Validations do NOT work'))
})
})
})

it('should return an error (via callbacks) for topic system/#/event', function (done) {
var client = connect()
client.subscribe('system/#/event', function (err) {
client.end()
if (err) {
return done()
}
done(new Error('Validations do NOT work'))
client.end(function () {
if (err) {
return done()
}
done(new Error('Validations do NOT work'))
})
})
})

Expand All @@ -375,11 +380,12 @@ module.exports = function (server, config) {
it('should return an error (via callbacks) for topic system/+/#/event', function (done) {
var client = connect()
client.subscribe('system/+/#/event', function (err) {
client.end()
if (err) {
return done()
}
done(new Error('Validations do NOT work'))
client.end(true, function () {
if (err) {
return done()
}
done(new Error('Validations do NOT work'))
})
})
})
})
Expand All @@ -395,7 +401,9 @@ module.exports = function (server, config) {

client.once('connect', function () {
client.queue.length.should.equal(0)
client.end(true, done)
setTimeout(function () {
client.end(true, done)
}, 10)
})
})

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

client.publish('test', 'test', {qos: 0})
client.queue.length.should.equal(0)
client.end(true, done)
client.on('connect', function () {
setTimeout(function () {
client.end(true, done)
}, 10)
})
})

it('should not queue qos != 0 messages', function (done) {
it('should queue qos != 0 messages', function (done) {
var client = connect({queueQoSZero: false})

client.publish('test', 'test', {qos: 1})
client.publish('test', 'test', {qos: 2})
client.subscribe('test')
client.unsubscribe('test')
client.queue.length.should.equal(2)
client.end(true, done)
client.on('connect', function () {
setTimeout(function () {
client.end(true, done)
}, 10)
})
})

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

client.publish('test', 'test', {qos: 0}, function () {
client.end(true, done)
called = true
})

client.on('connect', function () {
called.should.equal(true)
setTimeout(function () {
client.end(true, done)
}, 10)
})
})

if (!process.env.TRAVIS) {
it('should delay ending up until all inflight messages are delivered', function (done) {
var client = connect()
it('should delay ending up until all inflight messages are delivered', function (done) {
var client = connect()
var subscribeCalled = false

client.on('connect', function () {
client.subscribe('test', function () {
client.on('connect', function () {
client.subscribe('test', function () {
subscribeCalled = true
})
client.publish('test', 'test', function () {
client.end(false, function () {
subscribeCalled.should.be.equal(true)
done()
})
client.publish('test', 'test', function () {
client.end()
})
})
})
})

it('wait QoS 1 publish messages', function (done) {
var client = connect()
it('wait QoS 1 publish messages', function (done) {
var client = connect()
var messageReceived = false

client.on('connect', function () {
client.subscribe('test')
client.publish('test', 'test', { qos: 1 }, function () {
client.end()
})
client.on('message', function () {
client.on('connect', function () {
client.subscribe('test')
client.publish('test', 'test', { qos: 1 }, function () {
client.end(false, function () {
messageReceived.should.equal(true)
done()
})
})
client.on('message', function () {
messageReceived = true
})
})

server.once('client', function (serverClient) {
serverClient.on('subscribe', function () {
serverClient.on('publish', function (packet) {
serverClient.publish(packet)
})
server.once('client', function (serverClient) {
serverClient.on('subscribe', function () {
serverClient.on('publish', function (packet) {
serverClient.publish(packet)
})
})
})
})

it('does not wait acks when force-closing', function (done) {
// non-running broker
var client = connect('mqtt://localhost:8993')
it('does not wait acks when force-closing', function (done) {
// non-running broker
var client = connect('mqtt://localhost:8993')

client.publish('test', 'test', { qos: 1 })
client.end(true, done)
})
}
client.publish('test', 'test', { qos: 1 })
client.end(true, done)
})
})

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

client.publish(topic, payload)

server.once('client', function (serverClient) {
server.on('client', onClient)

function onClient (serverClient) {
serverClient.once('connect', function () {
server.removeListener('client', onClient)
})

serverClient.once('publish', function (packet) {
packet.topic.should.equal(topic)
packet.payload.toString().should.equal(payload)
packet.qos.should.equal(0)
packet.retain.should.equal(false)
client.end()
done()
client.end(true, done)
})
})
}
})

it('should publish a message (online)', function (done) {
Expand Down
5 changes: 0 additions & 5 deletions test/websocket_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ function attachWebsocketServer (wsServer) {

wss.on('connection', function (ws) {
var stream = websocket(ws)
stream.pause()
var connection = new Connection(stream)

setImmediate(() => {
stream.resume()
})

wsServer.emit('client', connection)
stream.on('error', function () {})
connection.on('error', function () {})
Expand Down

0 comments on commit 21084f5

Please sign in to comment.