Sha256: 0f7d3d09dda6ae80c9df8a2a983b66b6a40500155728b3599284cb77d0155b59

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

require_relative '../../spec_helper'

module Kamerling describe Server::UDP do
  let(:addr) { Addr['localhost', 1979, :UDP] }

  describe '#start' do
    it 'listens on an UDP port and passes received inputs to the handler' do
      server = Server::UDP.new addr: addr, handler: handler = fake(:handler)
      server.start
      foo = UDPSocket.new
      bar = UDPSocket.new
      foo.send 'foo', 0, *server.addr
      bar.send 'bar', 0, *server.addr
      foo_addr = Addr['127.0.0.1', foo.addr[1], :UDP]
      bar_addr = Addr['127.0.0.1', bar.addr[1], :UDP]
      run_all_threads
      server.stop
      handler.must_have_received :handle, ['foo', foo_addr]
      handler.must_have_received :handle, ['bar', bar_addr]
    end

    it 'doesn’t blow up on unknown inputs' do
      server = Server::UDP.new addr: addr, handler: handler = fake(:handler)
      server.start
      stub(handler).handle('foo', any(Addr)) { raise Handler::UnknownInput }
      UDPSocket.new.send 'foo', 0, *server.addr
      run_all_threads
      server.stop
    end
  end

  describe '#stop' do
    it 'closes the socket (and thus allows rebinding to it)' do
      Server::UDP.new(addr: addr).start.stop
      UDPSocket.new.tap { |socket| socket.bind(*addr) }.close
    end
  end

  describe '#addr' do
    it 'returns the server’s host + port as an UDP addr' do
      Server::UDP.new(addr: addr).addr.must_equal addr
    end
  end
end end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kamerling-0.0.1 spec/kamerling/server/udp_spec.rb