From 2db3366ef42a795bfc364d161f43ece93239c78b Mon Sep 17 00:00:00 2001 From: Raphael <raphael@joindiaspora.com> Date: Wed, 7 Jul 2010 16:04:31 -0700 Subject: [PATCH] RS, MS; test FILES are now in EM run blocks, tests are in next_ticks --- spec/controllers/socket_controller_spec.rb | 14 +++--- spec/lib/message_handler_spec.rb | 51 +++++++++------------- 2 files changed, 26 insertions(+), 39 deletions(-) diff --git a/spec/controllers/socket_controller_spec.rb b/spec/controllers/socket_controller_spec.rb index b2c8e723a2..483583d126 100644 --- a/spec/controllers/socket_controller_spec.rb +++ b/spec/controllers/socket_controller_spec.rb @@ -1,5 +1,5 @@ require File.dirname(__FILE__) + '/../spec_helper' - +EventMachine.run{ describe SocketController do before do Factory.create(:user) @@ -11,26 +11,22 @@ describe SocketController do end it 'should unstub the websocket' do - EventMachine.run { - puts"hi" + EventMachine.next_tick { WebSocket.initialize_channel WebSocket.push_to_clients("what").should_not == "stub" WebSocket.unsubscribe(1).should_not == "stub" WebSocket.subscribe.should_not == "stub" - EventMachine.stop } - puts "yo" end it 'should add a new subscriber to the websocket channel' do - EventMachine.run { - puts "foo" + EventMachine.next_tick { WebSocket.initialize_channel @controller.new_subscriber.should == 1 - - EventMachine.stop } end end +EventMachine.stop +} diff --git a/spec/lib/message_handler_spec.rb b/spec/lib/message_handler_spec.rb index d2ffddb6a3..6c69406da9 100644 --- a/spec/lib/message_handler_spec.rb +++ b/spec/lib/message_handler_spec.rb @@ -1,5 +1,6 @@ require File.dirname(__FILE__) + '/../spec_helper' +EventMachine.run{ describe MessageHandler do before do @handler = MessageHandler.new @@ -9,45 +10,42 @@ describe MessageHandler do describe 'GET messages' do describe 'creating a GET query' do + it 'should be able to add a GET query to the queue with required destinations' do - EventMachine.run{ + EM.next_tick{ @handler.add_get_request(@message_urls) @handler.size.should == @message_urls.size - EventMachine.stop - } + } end end describe 'processing a GET query' do it 'should remove sucessful http requests from the queue' do + EM.next_tick{ request = FakeHttpRequest.new(:success) request.should_receive(:get).and_return(request) EventMachine::HttpRequest.stub!(:new).and_return(request) - - EventMachine.run { @handler.add_get_request("http://www.google.com/") @handler.size.should == 1 @handler.process @handler.size.should == 0 - EventMachine.stop } end it 'should only retry a bad request three times ' do + EM.next_tick{ request = FakeHttpRequest.new(:failure) request.should_receive(:get).exactly(MessageHandler::NUM_TRIES).times.and_return(request) EventMachine::HttpRequest.stub!(:new).and_return(request) - EventMachine.run { + @handler.add_get_request("http://www.google.com/") @handler.add_get_request("http://asdfsdajfsdfbasdj.com/") @handler.size.should == 1 @handler.process @handler.size.should == 0 - - EventMachine.stop - } + } end end end @@ -56,50 +54,45 @@ describe MessageHandler do it 'should be able to add a post message to the queue' do - EventMachine.run { + EM.next_tick{ @handler.size.should ==0 @handler.add_post_request(@message_urls.first, @message_body) @handler.size.should == 1 - - EventMachine.stop - } + } end it 'should be able to insert many posts into the queue' do - EventMachine.run { + EM.next_tick{ @handler.size.should == 0 @handler.add_post_request(@message_urls, @message_body) @handler.size.should == @message_urls.size - EventMachine.stop - } + } end it 'should post a single message to a given URL' do + EM.next_tick{ request = FakeHttpRequest.new(:success) request.should_receive(:post).and_return(request) EventMachine::HttpRequest.stub!(:new).and_return(request) - EventMachine.run{ @handler.add_post_request(@message_urls.first, @message_body) @handler.size.should == 1 @handler.process @handler.size.should == 0 - - EventMachine.stop - - } + } end end describe "Mixed Queries" do it 'should process both POST and GET requests in the same queue' do + EM.next_tick{ + request = FakeHttpRequest.new(:success) request.should_receive(:get).exactly(3).times.and_return(request) request.should_receive(:post).exactly(3).times.and_return(request) EventMachine::HttpRequest.stub!(:new).and_return(request) - EventMachine.run{ @handler.add_post_request(@message_urls,@message_body) @handler.size.should == 3 @handler.add_get_request(@message_urls) @@ -107,25 +100,21 @@ describe MessageHandler do @handler.process #timer = EventMachine::Timer.new(1) do @handler.size.should == 0 - EventMachine.stop #end - } + } end it 'should be able to have seperate POST and GET have different callbacks' do + EM.next_tick{ request = FakeHttpRequest.new(:success) request.should_receive(:get).exactly(1).times.and_return(request) request.should_receive(:post).exactly(1).times.and_return(request) @handler.should_receive(:send_to_seed).once EventMachine::HttpRequest.stub!(:new).and_return(request) - - EventMachine.run{ @handler.add_post_request(@message_urls.first,@message_body) @handler.add_get_request(@message_urls.first) @handler.process - - EventMachine.stop } end @@ -136,6 +125,7 @@ class FakeHttpRequest def initialize(callback_wanted) @callback = callback_wanted end + def response "NOTE YOU ARE IN FAKE HTTP" end @@ -149,4 +139,5 @@ class FakeHttpRequest b.call if @callback == :failure end end - +EventMachine.stop +} -- GitLab