Sha256: 676d8b65fe04ea0c1a800ec62aa86bfde45b74f53910720f1d17f95d18bb9aa2

Contents?: true

Size: 1.81 KB

Versions: 5

Compression:

Stored size: 1.81 KB

Contents

require 'spec_helper'

describe 'Concurrency' do
  let(:freddy1) { Freddy.build(logger, config) }
  let(:freddy2) { Freddy.build(logger, config) }
  let(:freddy3) { Freddy.build(logger, config) }

  after { [freddy1, freddy2, freddy3].each(&:close) }

  it 'supports multiple requests in #respond_to' do
    freddy1.respond_to 'Concurrency1' do |payload, msg_handler|
      begin
        freddy1.deliver_with_response 'Concurrency2', msg: 'noop'
        result2 = freddy1.deliver_with_response 'Concurrency3', msg: 'noop'
        msg_handler.success(result2)
      rescue Freddy::InvalidRequestError => e
        msg_handler.error(e.response)
      end
    end

    freddy2.respond_to 'Concurrency2' do |payload, msg_handler|
      begin
        msg_handler.success({from: 'Concurrency2'})
      rescue Freddy::InvalidRequestError => e
        msg_handler.error(e.response)
      end
    end

    freddy3.respond_to 'Concurrency3' do |payload, msg_handler|
      msg_handler.success({from: 'Concurrency3'})
    end

    result =
      begin
        freddy1.deliver_with_response 'Concurrency1', msg: 'noop'
      rescue Freddy::InvalidRequestError => e
        e.response
      end

    expect(result).to eq(from: 'Concurrency3')
  end

  it 'supports nested calls in #tap_into' do
    received1 = false
    received2 = false

    freddy1.tap_into 'concurrency.*.queue1' do
      result = freddy1.deliver_with_response 'TapConcurrency', msg: 'noop'
      expect(result).to eq(from: 'TapConcurrency')
      received1 = true
    end

    freddy2.respond_to 'TapConcurrency' do |payload, msg_handler|
      msg_handler.success({from: 'TapConcurrency'})
      received2 = true
    end

    freddy1.deliver 'concurrency.q.queue1', msg: 'noop'

    wait_for { received1 && received2 }

    expect(received1).to be(true)
    expect(received2).to be(true)
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
freddy-0.4.7 spec/integration/concurrency_spec.rb
freddy-0.4.6 spec/integration/concurrency_spec.rb
freddy-0.4.4 spec/integration/concurrency_spec.rb
freddy-jruby-0.4.3 spec/integration/concurrency_spec.rb
freddy-0.4.3 spec/integration/concurrency_spec.rb