Skip to content
Extraits de code Groupes Projets
Valider 2db3366e rédigé par Raphael's avatar Raphael
Parcourir les fichiers

RS, MS; test FILES are now in EM run blocks, tests are in next_ticks

parent cc603a79
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
EventMachine.run{
describe SocketController do describe SocketController do
before do before do
Factory.create(:user) Factory.create(:user)
...@@ -11,26 +11,22 @@ describe SocketController do ...@@ -11,26 +11,22 @@ describe SocketController do
end end
it 'should unstub the websocket' do it 'should unstub the websocket' do
EventMachine.run { EventMachine.next_tick {
puts"hi"
WebSocket.initialize_channel WebSocket.initialize_channel
WebSocket.push_to_clients("what").should_not == "stub" WebSocket.push_to_clients("what").should_not == "stub"
WebSocket.unsubscribe(1).should_not == "stub" WebSocket.unsubscribe(1).should_not == "stub"
WebSocket.subscribe.should_not == "stub" WebSocket.subscribe.should_not == "stub"
EventMachine.stop
} }
puts "yo"
end end
it 'should add a new subscriber to the websocket channel' do it 'should add a new subscriber to the websocket channel' do
EventMachine.run { EventMachine.next_tick {
puts "foo"
WebSocket.initialize_channel WebSocket.initialize_channel
@controller.new_subscriber.should == 1 @controller.new_subscriber.should == 1
EventMachine.stop
} }
end end
end end
EventMachine.stop
}
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
EventMachine.run{
describe MessageHandler do describe MessageHandler do
before do before do
@handler = MessageHandler.new @handler = MessageHandler.new
...@@ -9,45 +10,42 @@ describe MessageHandler do ...@@ -9,45 +10,42 @@ describe MessageHandler do
describe 'GET messages' do describe 'GET messages' do
describe 'creating a GET query' do describe 'creating a GET query' do
it 'should be able to add a GET query to the queue with required destinations' 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.add_get_request(@message_urls)
@handler.size.should == @message_urls.size @handler.size.should == @message_urls.size
EventMachine.stop }
}
end end
end end
describe 'processing a GET query' do describe 'processing a GET query' do
it 'should remove sucessful http requests from the queue' do it 'should remove sucessful http requests from the queue' do
EM.next_tick{
request = FakeHttpRequest.new(:success) request = FakeHttpRequest.new(:success)
request.should_receive(:get).and_return(request) request.should_receive(:get).and_return(request)
EventMachine::HttpRequest.stub!(:new).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://www.google.com/")
@handler.size.should == 1 @handler.size.should == 1
@handler.process @handler.process
@handler.size.should == 0 @handler.size.should == 0
EventMachine.stop
} }
end end
it 'should only retry a bad request three times ' do it 'should only retry a bad request three times ' do
EM.next_tick{
request = FakeHttpRequest.new(:failure) request = FakeHttpRequest.new(:failure)
request.should_receive(:get).exactly(MessageHandler::NUM_TRIES).times.and_return(request) request.should_receive(:get).exactly(MessageHandler::NUM_TRIES).times.and_return(request)
EventMachine::HttpRequest.stub!(:new).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.add_get_request("http://asdfsdajfsdfbasdj.com/")
@handler.size.should == 1 @handler.size.should == 1
@handler.process @handler.process
@handler.size.should == 0 @handler.size.should == 0
}
EventMachine.stop
}
end end
end end
end end
...@@ -56,50 +54,45 @@ describe MessageHandler do ...@@ -56,50 +54,45 @@ describe MessageHandler do
it 'should be able to add a post message to the queue' do it 'should be able to add a post message to the queue' do
EventMachine.run { EM.next_tick{
@handler.size.should ==0 @handler.size.should ==0
@handler.add_post_request(@message_urls.first, @message_body) @handler.add_post_request(@message_urls.first, @message_body)
@handler.size.should == 1 @handler.size.should == 1
}
EventMachine.stop
}
end end
it 'should be able to insert many posts into the queue' do it 'should be able to insert many posts into the queue' do
EventMachine.run { EM.next_tick{
@handler.size.should == 0 @handler.size.should == 0
@handler.add_post_request(@message_urls, @message_body) @handler.add_post_request(@message_urls, @message_body)
@handler.size.should == @message_urls.size @handler.size.should == @message_urls.size
EventMachine.stop }
}
end end
it 'should post a single message to a given URL' do it 'should post a single message to a given URL' do
EM.next_tick{
request = FakeHttpRequest.new(:success) request = FakeHttpRequest.new(:success)
request.should_receive(:post).and_return(request) request.should_receive(:post).and_return(request)
EventMachine::HttpRequest.stub!(:new).and_return(request) EventMachine::HttpRequest.stub!(:new).and_return(request)
EventMachine.run{
@handler.add_post_request(@message_urls.first, @message_body) @handler.add_post_request(@message_urls.first, @message_body)
@handler.size.should == 1 @handler.size.should == 1
@handler.process @handler.process
@handler.size.should == 0 @handler.size.should == 0
}
EventMachine.stop
}
end end
end end
describe "Mixed Queries" do describe "Mixed Queries" do
it 'should process both POST and GET requests in the same queue' do it 'should process both POST and GET requests in the same queue' do
EM.next_tick{
request = FakeHttpRequest.new(:success) request = FakeHttpRequest.new(:success)
request.should_receive(:get).exactly(3).times.and_return(request) request.should_receive(:get).exactly(3).times.and_return(request)
request.should_receive(:post).exactly(3).times.and_return(request) request.should_receive(:post).exactly(3).times.and_return(request)
EventMachine::HttpRequest.stub!(:new).and_return(request) EventMachine::HttpRequest.stub!(:new).and_return(request)
EventMachine.run{
@handler.add_post_request(@message_urls,@message_body) @handler.add_post_request(@message_urls,@message_body)
@handler.size.should == 3 @handler.size.should == 3
@handler.add_get_request(@message_urls) @handler.add_get_request(@message_urls)
...@@ -107,25 +100,21 @@ describe MessageHandler do ...@@ -107,25 +100,21 @@ describe MessageHandler do
@handler.process @handler.process
#timer = EventMachine::Timer.new(1) do #timer = EventMachine::Timer.new(1) do
@handler.size.should == 0 @handler.size.should == 0
EventMachine.stop
#end #end
} }
end end
it 'should be able to have seperate POST and GET have different callbacks' do it 'should be able to have seperate POST and GET have different callbacks' do
EM.next_tick{
request = FakeHttpRequest.new(:success) request = FakeHttpRequest.new(:success)
request.should_receive(:get).exactly(1).times.and_return(request) request.should_receive(:get).exactly(1).times.and_return(request)
request.should_receive(:post).exactly(1).times.and_return(request) request.should_receive(:post).exactly(1).times.and_return(request)
@handler.should_receive(:send_to_seed).once @handler.should_receive(:send_to_seed).once
EventMachine::HttpRequest.stub!(:new).and_return(request) EventMachine::HttpRequest.stub!(:new).and_return(request)
EventMachine.run{
@handler.add_post_request(@message_urls.first,@message_body) @handler.add_post_request(@message_urls.first,@message_body)
@handler.add_get_request(@message_urls.first) @handler.add_get_request(@message_urls.first)
@handler.process @handler.process
EventMachine.stop
} }
end end
...@@ -136,6 +125,7 @@ class FakeHttpRequest ...@@ -136,6 +125,7 @@ class FakeHttpRequest
def initialize(callback_wanted) def initialize(callback_wanted)
@callback = callback_wanted @callback = callback_wanted
end end
def response def response
"NOTE YOU ARE IN FAKE HTTP" "NOTE YOU ARE IN FAKE HTTP"
end end
...@@ -149,4 +139,5 @@ class FakeHttpRequest ...@@ -149,4 +139,5 @@ class FakeHttpRequest
b.call if @callback == :failure b.call if @callback == :failure
end end
end end
EventMachine.stop
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter