Skip to content

Commit 98aa1f2

Browse files
author
Ruben Bridgewater
committed
Add failing test case for interfering parsers
1 parent c7d974f commit 98aa1f2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/parsers.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,35 @@ describe('parsers', function () {
6464

6565
parsers.forEach(function (Parser) {
6666
describe(Parser.name, function () {
67+
it('multiple parsers do not interfere', function () {
68+
var replyCount = 0
69+
var results = [1234567890, 'foo bar baz', 'hello world']
70+
function checkReply (reply) {
71+
assert.strictEqual(results[replyCount], reply)
72+
replyCount++
73+
}
74+
var parserOne = new Parser({
75+
returnReply: checkReply,
76+
returnError: returnError,
77+
returnFatalError: returnFatalError
78+
})
79+
var parserTwo = new Parser({
80+
returnReply: checkReply,
81+
returnError: returnError,
82+
returnFatalError: returnFatalError
83+
})
84+
parserOne.execute(new Buffer('+foo '))
85+
parserOne.execute(new Buffer('bar '))
86+
assert.strictEqual(replyCount, 0)
87+
parserTwo.execute(new Buffer(':1234567890\r\n+hello '))
88+
assert.strictEqual(replyCount, 1)
89+
parserTwo.execute(new Buffer('wor'))
90+
parserOne.execute(new Buffer('baz\r\n'))
91+
assert.strictEqual(replyCount, 2)
92+
parserTwo.execute(new Buffer('ld\r\n'))
93+
assert.strictEqual(replyCount, 3)
94+
})
95+
6796
it('chunks getting to big for the bufferPool', function () {
6897
// This is a edge case. Chunks should not exceed Math.pow(2, 16) bytes
6998
var lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, ' +

0 commit comments

Comments
 (0)