aboutsummaryrefslogtreecommitdiffstats
path: root/signaling-server/node_modules/socket.io/node_modules/redis/benches/hiredis_parser.js
blob: f1515b110b66c74121c966fcc7bf38f81eca6900 (plain)
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
var Parser = require('../lib/parser/hiredis').Parser;
var assert = require('assert');

/*
This test makes sure that exceptions thrown inside of "reply" event handlers
are not trapped and mistakenly emitted as parse errors.
*/
(function testExecuteDoesNotCatchReplyCallbackExceptions() {
  var parser = new Parser();
  var replies = [{}];

  parser.reader = {
    feed: function() {},
    get: function() {
      return replies.shift();
    }
  };

  var emittedError = false;
  var caughtException = false;

  parser
    .on('error', function() {
      emittedError = true;
    })
    .on('reply', function() {
      throw new Error('bad');
    });

  try {
    parser.execute();
  } catch (err) {
    caughtException = true;
  }

  assert.equal(caughtException, true);
  assert.equal(emittedError, false);
})();