<commit_before>'use strict'

describe('reconnect', function () {
  var a, b, receiver
  var Hub = require('../../lib')
  var Mock = require('../../lib/protocol/mock')

  it('can create multiple hubs', function () {
    a = new Hub({
      key: 'server-reconnect-a',
      adapter: {
        id: 'server-reconnect-a',
        mock: new Mock()
      }
    })
    b = new Hub({
      key: 'server-reconnect-b',
      adapter: {
        id: 'server-reconnect-b',
        mock: new Mock()
      }
    })
    receiver = new Hub({
      key: 'receiver-reconnect',
      adapter: {
        id: 'receiver-reconnect',
        mock: new Mock()
      }
    })
    a.adapter.mock.set({ server: 'server-reconnect-a' })
    b.adapter.mock.set({ server: 'server-reconnect-b' })
  })

  it('can connect to server-a', function (done) {
    receiver.adapter.mock.val = 'server-reconnect-a'
    receiver.adapter.mock.once('connect', function () {
      expect(a.clients).to.have.property('receiver-reconnect')
      done()
    })
  })

  it('can connect to another server server-b', function (done) {
    receiver.adapter.mock.val = 'server-reconnect-b'
    receiver.adapter.mock.once('connect', function () {
      expect(b.clients).to.have.property('receiver-reconnect').which.is.ok
      expect(a.clients['receiver-reconnect']).to.not.be.ok
      done()
    })
  })

  it('can connect to another server server-a', function (done) {
    receiver.adapter.mock.val = 'server-reconnect-a'
    receiver.adapter.mock.once('connect', function () {
      expect(a.clients).to.have.property('receiver-reconnect').which.is.ok
      expect(b.clients['receiver-reconnect']).to.not.be.ok
      done()
    })
  })

  it('server connections gets removed, client reconnects after 1 attempt', function (done) {
    // nested callbacks to test order
    receiver.adapter.mock.once('close', function () {
      this.once('reconnect', function () {
        this.once('connect', done)
      })
    })
    a.clients['receiver-reconnect'].connection.origin.remove()
  })
})<commit_msg>added expects for protocol.connected<commit_after>'use strict'

describe('reconnect', function () {
  var a, b, receiver
  var Hub = require('../../lib')
  var Mock = require('../../lib/protocol/mock')

  it('can create multiple hubs', function () {
    a = new Hub({
      key: 'server-reconnect-a',
      adapter: {
        id: 'server-reconnect-a',
        mock: new Mock()
      }
    })
    b = new Hub({
      key: 'server-reconnect-b',
      adapter: {
        id: 'server-reconnect-b',
        mock: new Mock()
      }
    })
    receiver = new Hub({
      key: 'receiver-reconnect',
      adapter: {
        id: 'receiver-reconnect',
        mock: new Mock()
      }
    })
    a.adapter.mock.set({ server: 'server-reconnect-a' })
    b.adapter.mock.set({ server: 'server-reconnect-b' })
  })

  it('can connect to server-a', function (done) {
    receiver.adapter.mock.val = 'server-reconnect-a'
    receiver.adapter.mock.once('connect', function () {
      expect(a.clients).to.have.property('receiver-reconnect')
      done()
    })
  })

  it('connected should be true', function () {
    expect(receiver.adapter.mock.connected.val).to.equal(true)
  })

  it('can connect to another server server-b', function (done) {
    receiver.adapter.mock.val = 'server-reconnect-b'
    receiver.adapter.mock.once('connect', function () {
      expect(b.clients).to.have.property('receiver-reconnect').which.is.ok
      expect(a.clients['receiver-reconnect']).to.not.be.ok
      done()
    })
  })

  it('can connect to another server server-a', function (done) {
    receiver.adapter.mock.val = 'server-reconnect-a'
    receiver.adapter.mock.once('connect', function () {
      expect(a.clients).to.have.property('receiver-reconnect').which.is.ok
      expect(b.clients['receiver-reconnect']).to.not.be.ok
      done()
    })
  })

  it('server connections gets removed, client reconnects after 1 attempt', function (done) {
    // nested callbacks to test order
    receiver.adapter.mock.once('close', function () {
      expect(receiver.adapter.mock.connected.val).to.equal(false)
      this.once('reconnect', function () {
        this.once('connect', done)
      })
    })
    a.clients['receiver-reconnect'].connection.origin.remove()
  })
})
{'fraction_non_alphanumeric': 0.16996507566938301, 'fraction_numerical': 0.00046565774155995343, 'mean_word_length': 2.6780821917808217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2850470', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1386, 'n_words': 256}