Sha256: f338d8904dc05299c21619358f68fd58a716b83dc29013861ee1b6e5890f928f

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

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

class TestChannel < MiniTest::Unit::TestCase

  def test_channel
    ## client1(comet, channel "aaa") ---> server --> client3(websocket, channel "aaa")
    ## client2(websocket, channel "bbb") not receive data from channel "aaa"
    post_data = {:time => Time.now.to_s, :msg => 'hello!!'}
    res = nil
    res2 = nil
    res3 = nil
    EM::run do
      client = EM::RocketIO::Client.new(App.url, :type => :comet, :channel => "aaa").connect
      client.on :to_channel do |data|
        res = data
      end

      client.on :connect do
        client2 = EM::RocketIO::Client.new(App.url, :type => :websocket, :channel => "bbb").connect
        client2.on :connect do
          client3 = EM::RocketIO::Client.new(App.url, :type => :websocket, :channel => "aaa").connect
          client3.on :connect do
            client.push :to_channel, post_data
          end
          client3.on :to_channel do |data|
            res3 = data
            client3.close
          end
        end
        client2.on :to_channel do |data|
          res2 = data
          client2.close
        end
      end

      EM::defer do
        50.times do
          break if res != nil and res3 != nil
          sleep 0.1
        end
        client.close
        EM::stop
      end
    end
    assert res != nil, 'server not respond'
    assert res["time"] == post_data[:time]
    assert res["msg"] == post_data[:msg]
    assert res3 != nil, 'server not respond'
    assert res3["time"] == post_data[:time]
    assert res3["msg"] == post_data[:msg]
    assert res2 == nil, 'channel error'
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
em-rocketio-client-0.1.1 test/test_channel.rb
em-rocketio-client-0.1.0 test/test_channel.rb