Sha256: c13daabdc333ae44a4d9eda2ce8139b0ae8a629e07f54509c629b9cf1bdae6e1

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

context 'Paired sockets' do
  setup do
    @bound, @connected = EZMQ.create_linked_pair
  end

  should 'initialize properly' do
    assert_kind_of EZMQ::Socket, @bound
    assert_kind_of EZMQ::Socket, @connected
  end

  should 'return the length of messages they send' do
    assert_equal 7, @connected.send('message')
  end

  should 'return the contents of messages they receive' do
    @connected.send 'message'
    assert_equal 'message', @bound.receive
  end

  should 'pass Hash messages to the encode method' do
    @connected.encode = -> m { assert_equal({message: 'test'}, m) }
    @connected.send message: 'test'
    @connected.encode = -> m { m }
  end

  should 'yield the contents of messages they receive, if given a block' do
    @bound.send 'message'
    assert_equal 'message', @connected.receive { |m| m }
  end

  should 'block if no message is present' do
    assert_raises Timeout::Error do
      Timeout.timeout(0.1) do
        @connected.receive
      end
    end
  end

  should 'receive multiple messages if listening' do
    3.times { @bound.send 'message' }
    messages = []
    begin
      Timeout.timeout(0.1) do
        @connected.listen do |message|
          messages << message
        end
      end
    rescue Timeout::Error
      assert_equal 3, messages.size
    end
  end
end

context 'Paired sockets with encoding/decoding' do
  setup do
    e = -> message { JSON.dump message }
    d = -> message { JSON.load message }
    @bound, @connected = EZMQ.create_linked_pair encoding: e, decoding: d
  end

  should 'return the length of messages they send' do
    assert_equal 7, @connected.send('message')
  end

  should 'return the contents of messages they receive' do
    @connected.send 'message'
    assert_equal 'message', @bound.receive
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ezmq-0.4.3 tests/ezmq/pair.rb