<commit_before>'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.destroy(new Error('something went wrong'))
    setImmediate(cb)
  })

  process.nextTick(function () {
    s.inStream.write(packet)
    setImmediate(function () {
      s.inStream.write(packet)
      s.inStream.write(packet)
    })
  })
})<commit_msg>More reliable regr-21 test if we use external mq (#280)<commit_after>'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.destroy(new Error('something went wrong'))
    cb()
    setImmediate(() => {
      packet.topic = 'foo'
      s.inStream.write(packet)
      s.inStream.write(packet)
    })
  })
  s.broker.mq.on('foo', function (msg, cb) {
    t.fail('msg received')
  })
  s.inStream.write(packet)
})
{'fraction_non_alphanumeric': 0.15976331360946747, 'fraction_numerical': 0.009861932938856016, 'mean_word_length': 3.21606648199446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '865921', 'n_tokens_mistral': 530, 'n_tokens_neox': 511, 'n_words': 124}