File: test_object_protocol.rb

package info (click to toggle)
ruby-eventmachine 1.0.3-6%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,000 kB
  • ctags: 3,178
  • sloc: ruby: 8,641; cpp: 5,217; java: 827; makefile: 5
file content (36 lines) | stat: -rw-r--r-- 689 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'em_test_helper'

class TestObjectProtocol < Test::Unit::TestCase
  module Server
    include EM::P::ObjectProtocol
    def post_init
      send_object :hello=>'world'
    end
    def receive_object obj
      $server = obj
      EM.stop
    end
  end

  module Client
    include EM::P::ObjectProtocol
    def receive_object obj
      $client = obj
      send_object 'you_said'=>obj
    end
  end

  def setup
    @port = next_port
  end

  def test_send_receive
    EM.run{
      EM.start_server "127.0.0.1", @port, Server
      EM.connect "127.0.0.1", @port, Client
    }

    assert($client == {:hello=>'world'})
    assert($server == {'you_said'=>{:hello=>'world'}})
  end
end