-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop ingesting packets after the client has errored
Fixed #21.
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict' | ||
|
||
var test = require('tape').test | ||
var helper = require('./helper') | ||
var setup = helper.setup | ||
var connect = helper.connect | ||
|
||
test('after an error, outstanding packets are discarded', function (t) { | ||
t.plan(1) | ||
var s = connect(setup(), { | ||
keepalive: 1000 | ||
}) | ||
var packet = { | ||
cmd: 'publish', | ||
topic: 'hello', | ||
payload: 'world' | ||
} | ||
|
||
s.broker.mq.on('hello', function (msg, cb) { | ||
t.pass('first msg received') | ||
s.inStream.emit('error', new Error('something went wrong')) | ||
setImmediate(cb) | ||
}) | ||
|
||
s.inStream.write(packet) | ||
setImmediate(function () { | ||
s.inStream.write(packet) | ||
s.inStream.write(packet) | ||
}) | ||
}) |