get parallel tests running on net/http (parallel methods are a no-op)

This commit is contained in:
rick 2009-12-11 18:25:31 -08:00
parent 75bec559d6
commit 376e9bd863
6 changed files with 36 additions and 12 deletions

View File

@ -19,7 +19,7 @@ module Faraday
end
def self.loaded_adapters
adapters.map { |c| const_get(c) }.select { |a| a.loaded }
adapters.map { |c| const_get(c) }.select { |a| a.loaded? }
end
end
end

View File

@ -2,7 +2,8 @@ require 'net/http'
module Faraday
module Adapter
module NetHttp
def self.loaded() true end
extend Faraday::Connection::Options
self.loaded = true
def _get(uri, request_headers)
http = Net::HTTP.new(uri.host, uri.port)

View File

@ -2,9 +2,7 @@
module Faraday
module Adapter
module Typhoeus
class << self
attr_accessor :loaded
end
extend Faraday::Connection::Options
begin
require 'typhoeus'

View File

@ -1,6 +1,15 @@
require 'addressable/uri'
module Faraday
class Connection
module Options
def loaded() @loaded end
def loaded=(v) @loaded = v end
def supports_async() @supports_async end
def supports_async=(v) @supports_async = v end
alias loaded? loaded
alias supports_async? supports_async
end
include Addressable
attr_accessor :host, :port, :scheme
@ -31,6 +40,22 @@ module Faraday
@response_class || Response
end
def in_parallel?
!!@parallel_manager
end
def in_parallel(options = {})
@parallel_manager = true
yield
@parallel_manager = false
end
def setup_parallel_manager(options = {})
end
def run_parallel_requests
end
def path_prefix=(value)
if value
value.chomp! "/"

View File

@ -1,6 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
if Faraday::Adapter::Typhoeus.loaded
if Faraday::Adapter::Typhoeus.loaded?
class TyphoeusTest < Faraday::TestCase
describe "#parse_response_headers" do
before do

View File

@ -24,12 +24,10 @@ class AdapterTest < Faraday::TestCase
assert_equal 'text/html', @connection.get('hello_world').headers['content-type']
end
end
end
if Faraday::Adapter::Typhoeus.loaded
describe "async Typhoeus requests" do
describe "async requests" do
before do
@connection.extend Faraday::Adapter::Typhoeus
@connection.extend adapter
end
it "clears parallel manager after running a single request" do
@ -47,8 +45,10 @@ class AdapterTest < Faraday::TestCase
resp1 = @connection.get('json')
resp2 = @connection.get('json')
assert @connection.in_parallel?
assert_nil resp1.body
assert_nil resp2.body
if adapter.supports_async?
assert_nil resp1.body
assert_nil resp2.body
end
end
assert !@connection.in_parallel?
assert_equal [1,2,3], resp1.body