Sha256: ab50002f51c87dca571e07838f1e45d6d5c435a0c1e48adb03d99cd45893ffd9

Contents?: true

Size: 1.93 KB

Versions: 19

Compression:

Stored size: 1.93 KB

Contents

require File.expand_path('../../test_helper', __FILE__)

module Propono
  class UdpListenerTest < Minitest::Test

    def test_intialize_sets_locals
      block = Proc.new {}
      listener = UdpListener.new(&block)
      assert_equal block, listener.instance_variable_get("@processor")
    end

    def test_socket_is_setup_correctly
      host = "my-host"
      port = 1234

      Propono.config.udp_host = host
      Propono.config.udp_port = port

      UDPSocket.any_instance.expects(:bind).with(host, port)

      listener = UdpListener.new() {}
      socket = listener.send(:socket)
    end

    def test_initialize_should_fail_without_a_block
      assert_raises(UdpListenerError) do
        UdpListener.new
      end
    end

    def test_message_is_processed
      udp_msg = "Foobar"
      processor = Proc.new {}
      server = UdpListener.new(&processor)
      socket = mock(recvfrom: [udp_msg])
      server.stubs(socket: socket)
      server.expects(:process_udp_data).with(udp_msg)
      thread = server.send(:receive_and_process)
      thread.join
    end

    def test_processor_is_called_correctly
      topic = "my-topic"
      message = "my-message"
      id = "123asd"
      processor = Proc.new {}
      udp_data = {topic: topic, message: message, id: id}.to_json
      processor.expects(:call).with(topic, message, {id: id})

      server = UdpListener.new(&processor)
      server.send(:process_udp_data, udp_data)
    end

    def test_listen_should_loop
      listener = UdpListener.new {}
      listener.expects(:loop)
      listener.listen
    end
  end

  class UdpListenerLegacyTest < Minitest::Test
    def test_processor_is_called_correctly
      topic = "my-topic"
      message = "my-message"
      processor = Proc.new {}
      udp_data = {topic: topic, message: message}.to_json
      processor.expects(:call).with(topic, message)

      server = UdpListener.new(&processor)
      server.send(:process_udp_data, udp_data)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
propono-1.7.0 test/services/udp_listener_test.rb
propono-1.6.0 test/services/udp_listener_test.rb
propono-1.5.0 test/services/udp_listener_test.rb
propono-1.4.0 test/services/udp_listener_test.rb
propono-1.3.0 test/services/udp_listener_test.rb
propono-1.2.0 test/services/udp_listener_test.rb
propono-1.1.3 test/services/udp_listener_test.rb
propono-1.1.2 test/services/udp_listener_test.rb
propono-1.1.1 test/services/udp_listener_test.rb
propono-1.1.0 test/services/udp_listener_test.rb
propono-1.0.0 test/services/udp_listener_test.rb
propono-1.0.0.rc3 test/services/udp_listener_test.rb
propono-1.0.0.rc2 test/services/udp_listener_test.rb
propono-1.0.0.rc1 test/services/udp_listener_test.rb
propono-0.11.1 test/services/udp_listener_test.rb
propono-0.11.0 test/services/udp_listener_test.rb
propono-0.10.0 test/services/udp_listener_test.rb
propono-0.9.1 test/services/udp_listener_test.rb
propono-0.9.0 test/services/udp_listener_test.rb