<commit_before>'use strict'

const expect = require('chai').expect
const Qpc = require('../')

describe('qpc', function() {
  it('should send/recieve message', function(done) {
    let rpc = new Qpc({
      url: 'amqp://guest:guest@localhost:5672',
    })

    rpc.on('foo', function(args) {
      expect(args[0]).to.eq(1)
      expect(args[1]).to.eq(2)
      done()
    })

    rpc.call('foo', [1, 2])
  })

  it('should send response', function(done) {
    let rpc = new Qpc({
      url: 'amqp://guest:guest@localhost:5672',
    })

    rpc.on('sum', function(args, cb) {
      cb(args[0] + args[1])
    })

    rpc.call('sum', [1, 2], function(res) {
      expect(res).to.eq(3)
      done()
    })
  })

  it('should recieve message when subscribe after publish', function(done) {
    let rpc = new Qpc({
      url: 'amqp://guest:guest@localhost:5672',
    })

    rpc.call('foo2', [1, 2])

    setTimeout(function() {
      rpc.on('foo2', function(args) {
        expect(args[0]).to.eq(1)
        expect(args[1]).to.eq(2)
        done()
      })
    }, 1500)
  })
})<commit_msg>New test added for timeout<commit_after>'use strict'

const expect = require('chai').expect
const Qpc = require('../')

describe('qpc', function() {
  it('should send/recieve message', function(done) {
    let rpc = new Qpc({
      url: 'amqp://guest:guest@localhost:5672',
    })

    rpc.on('foo', function(args) {
      expect(args[0]).to.eq(1)
      expect(args[1]).to.eq(2)
      done()
    })

    rpc.call('foo', [1, 2])
  })

  it('should send response', function(done) {
    let rpc = new Qpc({
      url: 'amqp://guest:guest@localhost:5672',
    })

    rpc.on('sum', function(args, cb) {
      cb(args[0] + args[1])
    })

    rpc.call('sum', [1, 2], function(res) {
      expect(res).to.eq(3)
      done()
    })
  })

  it('should respond with an error in case of timout', function(done) {
    let rpc = new Qpc({
      url: 'amqp://guest:guest@localhost:5672',
      ttl: 100,
    })

    rpc.call('timeout', [1, 2], function(res) {
      expect(res).to.be.instanceOf(Error)
      done()
    })
  })

  it('should recieve message when subscribe after publish', function(done) {
    let rpc = new Qpc({
      url: 'amqp://guest:guest@localhost:5672',
    })

    rpc.call('foo2', [1, 2])

    setTimeout(function() {
      rpc.on('foo2', function(args) {
        expect(args[0]).to.eq(1)
        expect(args[1]).to.eq(2)
        done()
      })
    }, 1500)
  })
})
{'fraction_non_alphanumeric': 0.20032507110930517, 'fraction_numerical': 0.0321007720438846, 'mean_word_length': 2.5629522431259044, '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': '1299859', 'n_tokens_mistral': 972, 'n_tokens_neox': 906, 'n_words': 174}