Skip to content
Browse files

well, eventmachine didn't really work on jruby.. skip em tests for jruby

  • Loading branch information...
1 parent 318594b commit bfb69407f50b826b9746e4c437abedd06c4dcb6a @godfat godfat committed Aug 14, 2012
Showing with 128 additions and 108 deletions.
  1. +0 −36 test/test_cache.rb
  2. +127 −1 test/test_em_http_request.rb
  3. +0 −4 test/test_simple.rb
  4. +1 −67 test/test_timeout.rb
View
36 test/test_cache.rb
@@ -77,42 +77,6 @@ def call env
c.get(path).should.eq('body')
end
- should 'cancel timeout for fiber' do
- any_instance_of(RC::Timeout::TimerEm) do |timer|
- proxy.mock(timer).cancel.times(2)
- end
- path = 'http://example.com/'
- stub_request(:get, path).to_return(:body => 'response')
- c = RC::Builder.client do
- use RC::Timeout, 10
- use RC::Cache, {}, 3600
- run RC::EmHttpRequest
- end.new
- EM.run{ Fiber.new{
- c.request(RC::REQUEST_PATH => path).should.eq 'response'
- c.request(RC::REQUEST_PATH => path).should.eq 'response'
- EM.stop }.resume }
- c.cache.size.should.eq 1
- end
-
- should 'cancel timeout for async' do
- path = 'http://example.com/'
- any_instance_of(RC::Timeout::TimerEm) do |timer|
- mock(timer).cancel.times(2)
- end
- stub_request(:get, path).to_return(:body => 'response')
- c = RC::Builder.client do
- use RC::Timeout, 10
- use RC::Cache, {}, 3600
- run RC::EmHttpRequest
- end.new
- EM.run{
- c.request_full(RC::REQUEST_PATH => path){
- c.request_full(RC::REQUEST_PATH => path){
- EM.stop }}}
- c.cache.size.should.eq 1
- end
-
should 'only [] and []= should be implemented' do
cache = Class.new do
def initialize ; @h = {} ; end
View
128 test/test_em_http_request.rb
@@ -17,4 +17,130 @@
RC::Simple.new.get('http://localhost:1').no_such_method
}.resume}
end
-end
+
+ # ----------------------------------------------------------------------
+
+ describe RC::Simple do
+ before do
+ @path = 'http://example.com'
+ stub_request(:get, @path).to_return(:body => 'OK')
+ end
+
+ should 'work with EM' do
+ EM.run{Fiber.new{
+ RC::Simple.new.get(@path).should.eq 'OK'; EM.stop}.resume}
+ end
+ end
+
+ # ----------------------------------------------------------------------
+
+ describe RC::Timeout do
+ after do
+ WebMock.reset!
+ RR.verify
+ end
+
+ should 'cancel timeout for fiber' do
+ any_instance_of(RC::Timeout::TimerEm) do |timer|
+ proxy.mock(timer).cancel.times(2)
+ end
+ path = 'http://example.com/'
+ stub_request(:get, path).to_return(:body => 'response')
+ c = RC::Builder.client do
+ use RC::Timeout, 10
+ use RC::Cache, {}, 3600
+ run RC::EmHttpRequest
+ end.new
+ EM.run{ Fiber.new{
+ c.request(RC::REQUEST_PATH => path).should.eq 'response'
+ c.request(RC::REQUEST_PATH => path).should.eq 'response'
+ EM.stop }.resume }
+ c.cache.size.should.eq 1
+ end
+
+ should 'cancel timeout for async' do
+ path = 'http://example.com/'
+ any_instance_of(RC::Timeout::TimerEm) do |timer|
+ mock(timer).cancel.times(2)
+ end
+ stub_request(:get, path).to_return(:body => 'response')
+ c = RC::Builder.client do
+ use RC::Timeout, 10
+ use RC::Cache, {}, 3600
+ run RC::EmHttpRequest
+ end.new
+ EM.run{
+ c.request_full(RC::REQUEST_PATH => path){
+ c.request_full(RC::REQUEST_PATH => path){
+ EM.stop }}}
+ c.cache.size.should.eq 1
+ end
+
+ should 'return correct result for futures' do
+ path = 'http://example.com/'
+ stub_request(:get, path).to_return(:body => 'response')
+
+ c = RC::Builder.client do
+ use RC::Timeout, 10
+ run RC::EmHttpRequest
+ end.new
+ EM.run{Fiber.new{c.get(path).should.eq('response');EM.stop}.resume}
+ end
+
+ describe 'raise exception' do
+ should 'default timeout' do
+ c = RC::Builder.client do
+ use RC::Timeout, 0.00001
+ run Class.new{
+ def call env
+ sleep 1
+ yield(env)
+ end
+ }
+ end.new
+ lambda{ c.get('') }.should.raise ::Timeout::Error
+ end
+
+ should 'future timeout' do
+ port = 35795
+ path = "http://localhost:#{port}/"
+
+ c = RC::Builder.client do
+ use RC::Timeout, 0.00001
+ run RC::EmHttpRequest
+ end.new
+
+ EM.run{
+ EM.start_server '127.0.0.1', port, Module.new{
+ def receive_data data; end
+ }
+ Fiber.new{
+ begin
+ c.get(path).tap{}
+ rescue => e
+ e.should.kind_of ::Timeout::Error
+ EM.stop
+ end
+ }.resume}
+ end
+
+ should 'async timeout' do
+ port = 35795
+ path = "http://localhost:#{port}/"
+
+ c = RC::Builder.client do
+ use RC::Timeout, 0.00001
+ use RC::ErrorHandler
+ run RC::EmHttpRequest
+ end.new
+
+ EM.run{
+ EM.start_server '127.0.0.1', port, Module.new{
+ def receive_data data; end
+ }
+ c.get(path){ |e| e.should.kind_of ::Timeout::Error; EM.stop }
+ }
+ end
+ end
+ end
+end unless RUBY_ENGINE == 'jruby'
View
4 test/test_simple.rb
@@ -7,10 +7,6 @@
stub_request(:get, @path).to_return(:body => 'OK')
end
- should 'work with EM' do
- EM.run{Fiber.new{RC::Simple.new.get(@path).should.eq 'OK';EM.stop}.resume}
- end
-
should 'work with RC' do
RC::Simple.new.get(@path).should.eq 'OK'
end
View
68 test/test_timeout.rb
@@ -4,6 +4,7 @@
describe RC::Timeout do
after do
WebMock.reset!
+ RR.verify
end
def setup_app
@@ -22,71 +23,4 @@ def setup_app
mock.proxy(app).monitor(env).times(1)
app.call(env){|e| e[RC::TIMER].should.kind_of?(RC::Timeout::TimerThread)}
end
-
- should 'return correct result for futures' do
- path = 'http://example.com/'
- stub_request(:get, path).to_return(:body => 'response')
-
- c = RC::Builder.client do
- use RC::Timeout, 10
- run RC::EmHttpRequest
- end.new
- EM.run{Fiber.new{c.get(path).should.eq('response');EM.stop}.resume}
- end
-
- describe 'raise exception' do
- should 'default timeout' do
- c = RC::Builder.client do
- use RC::Timeout, 0.00001
- run Class.new{
- def call env
- sleep 1
- yield(env)
- end
- }
- end.new
- lambda{ c.get('') }.should.raise ::Timeout::Error
- end
-
- should 'future timeout' do
- port = 35795
- path = "http://localhost:#{port}/"
-
- c = RC::Builder.client do
- use RC::Timeout, 0.00001
- run RC::EmHttpRequest
- end.new
-
- EM.run{
- EM.start_server '127.0.0.1', port, Module.new{
- def receive_data data; end
- }
- Fiber.new{
- begin
- c.get(path).tap{}
- rescue => e
- e.should.kind_of ::Timeout::Error
- EM.stop
- end
- }.resume}
- end
-
- should 'async timeout' do
- port = 35795
- path = "http://localhost:#{port}/"
-
- c = RC::Builder.client do
- use RC::Timeout, 0.00001
- use RC::ErrorHandler
- run RC::EmHttpRequest
- end.new
-
- EM.run{
- EM.start_server '127.0.0.1', port, Module.new{
- def receive_data data; end
- }
- c.get(path){ |e| e.should.kind_of ::Timeout::Error; EM.stop }
- }
- end
- end
end

0 comments on commit bfb6940

Please sign in to comment.
Something went wrong with that request. Please try again.