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 end
def self.loaded_adapters 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 end
end end

View File

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

View File

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

View File

@ -1,6 +1,15 @@
require 'addressable/uri' require 'addressable/uri'
module Faraday module Faraday
class Connection 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 include Addressable
attr_accessor :host, :port, :scheme attr_accessor :host, :port, :scheme
@ -31,6 +40,22 @@ module Faraday
@response_class || Response @response_class || Response
end 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) def path_prefix=(value)
if value if value
value.chomp! "/" value.chomp! "/"

View File

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

View File

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