test/test_rocketio.rb in sinatra-rocketio-0.0.9 vs test/test_rocketio.rb in sinatra-rocketio-0.1.0

- old
+ new

@@ -13,41 +13,33 @@ def test_websocket_to_comet ## websocket --> server --> comet post_data = {:time => Time.now.to_s, :msg => 'hello!!', :to => nil} res = nil res2 = nil - EM::run do - client = EM::WebSocketIO::Client.new(App.websocketio_url).connect - client.on :message do |data| - res = data - end + client = Sinatra::RocketIO::Client.new(App.url, :type => :websocket).connect + client.on :message do |data| + res = data + end - client.on :disconnect do - EM.stop_event_loop + client.on :connect do |session| + client2 = Sinatra::RocketIO::Client.new(App.url, :type => :comet).connect + client2.on :connect do |session2| + post_data['to'] = session2 + client.push :message, post_data end - - client.on :connect do |session| - client2 = EM::CometIO::Client.new(App.cometio_url).connect - client2.on :connect do |session2| - post_data['to'] = session2 - client.push :message, post_data - end - client2.on :message do |data| - res2 = data - client2.close - client.close - end - end - - EM::defer do - 50.times do - break if res != nil - sleep 0.1 - end + client2.on :message do |data| + res2 = data + client2.close client.close end end + + 50.times do + break if res != nil + sleep 0.1 + end + client.close assert res2 != nil, 'server not respond' assert res2["time"] == post_data[:time] assert res2["msg"] == post_data[:msg] assert res == nil end @@ -55,43 +47,32 @@ def test_comet_to_websocket ## comet --> server --> websocket post_data = {:time => Time.now.to_s, :msg => 'hello!!', :to => nil} res = nil res2 = nil - EM::run do - client = EM::CometIO::Client.new(App.cometio_url).connect - client.on :message do |data| - res = data - end + client = Sinatra::RocketIO::Client.new(App.url, :type => :comet).connect + client.on :message do |data| + res = data + end - client.on :disconnect do - EM.stop_event_loop + client.on :connect do |session| + client2 = Sinatra::RocketIO::Client.new(App.url, :type => :websocket).connect + client2.on :connect do |session2| + post_data['to'] = session2 + client.push :message, post_data end - - client.on :connect do |session| - client2 = EM::WebSocketIO::Client.new(App.websocketio_url).connect - client2.on :connect do |session2| - post_data['to'] = session2 - client.push :message, post_data - end - client2.on :message do |data| - res2 = data - client2.close - client.close - end - client2.on :disconnect do - EM.stop_event_loop - end - end - - EM::defer do - 50.times do - break if res != nil - sleep 0.1 - end + client2.on :message do |data| + res2 = data + client2.close client.close end end + + 50.times do + break if res != nil + sleep 0.1 + end + client.close assert res2 != nil, 'server not respond' assert res2["time"] == post_data[:time] assert res2["msg"] == post_data[:msg] assert res == nil end