excon 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of excon might be problematic. Click here for more details.

data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ disable_system_gems
2
+
3
+ only :test do
4
+ gem 'shindo'
5
+ gem 'open4'
6
+ end
7
+
8
+ only :test_server do
9
+ gem 'sinatra', :require_as => 'sinatra/base'
10
+ end
11
+
12
+ only :benchmarks do
13
+ gem 'eventmachine'
14
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.7
@@ -1,3 +1,5 @@
1
+ Bundler.require_env(:benchmarks)
2
+
1
3
  require File.join(File.dirname(__FILE__), '..', 'lib/excon')
2
4
 
3
5
  require 'benchmark'
@@ -36,4 +38,25 @@ Benchmark.bmbm(25) do |bench|
36
38
  open('http://www.google.com/').read
37
39
  end
38
40
  end
41
+ bench.report('em') do
42
+ module DumbHttpClient
43
+ @@responses = 0
44
+ def post_init
45
+ send_data "GET / HTTP/1.1\r\nHost: _\r\n\r\n"
46
+ end
47
+
48
+ def receive_data(*)
49
+ @@responses += 1
50
+ if @@responses == COUNT
51
+ EM.stop
52
+ end
53
+ end
54
+ end
55
+
56
+ EM.run{
57
+ COUNT.times do
58
+ EM.connect 'www.google.com', 80, DumbHttpClient
59
+ end
60
+ }
61
+ end
39
62
  end
@@ -0,0 +1,3 @@
1
+ #!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
2
+ require File.join(File.dirname(__FILE__), "../vendor/gems/environment")
3
+ load File.join(File.dirname(__FILE__), "../vendor/gems/gems/rack-1.0.1/bin/rackup")
@@ -0,0 +1,3 @@
1
+ #!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
2
+ require File.join(File.dirname(__FILE__), "../vendor/gems/environment")
3
+ load File.join(File.dirname(__FILE__), "../vendor/gems/gems/shindo-0.0.4/bin/shindo")
@@ -5,19 +5,21 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{excon}
8
- s.version = "0.0.5"
8
+ s.version = "0.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Wesley Beary"]
12
- s.date = %q{2009-11-17}
12
+ s.date = %q{2009-11-21}
13
13
  s.description = %q{speed, persistence, http(s)}
14
14
  s.email = %q{wbeary@engineyard.com}
15
+ s.executables = ["rackup", "shindo"]
15
16
  s.extra_rdoc_files = [
16
17
  "README.rdoc"
17
18
  ]
18
19
  s.files = [
19
20
  ".document",
20
21
  ".gitignore",
22
+ "Gemfile",
21
23
  "README.rdoc",
22
24
  "Rakefile",
23
25
  "VERSION",
@@ -29,16 +31,16 @@ Gem::Specification.new do |s|
29
31
  "lib/excon/connection.rb",
30
32
  "lib/excon/errors.rb",
31
33
  "lib/excon/response.rb",
32
- "test/test.rb"
34
+ "tests/config.ru",
35
+ "tests/mock_tests.rb",
36
+ "tests/test_helper.rb",
37
+ "tests/threaded_tests.rb"
33
38
  ]
34
39
  s.homepage = %q{http://github.com/geemus/excon}
35
40
  s.rdoc_options = ["--charset=UTF-8"]
36
41
  s.require_paths = ["lib"]
37
42
  s.rubygems_version = %q{1.3.5}
38
43
  s.summary = %q{EXtended http(s) CONnections}
39
- s.test_files = [
40
- "test/test.rb"
41
- ]
42
44
 
43
45
  if s.respond_to? :specification_version then
44
46
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -92,19 +92,25 @@ unless Excon.mocking?
92
92
  private
93
93
 
94
94
  def connection
95
- if !@connection || @connection.closed?
96
- @connection = TCPSocket.open(@uri.host, @uri.port)
97
- if @uri.scheme == 'https'
98
- @ssl_context = OpenSSL::SSL::SSLContext.new
99
- @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
100
- @connection = OpenSSL::SSL::SSLSocket.new(@connection, @ssl_context)
101
- @connection.sync_close = true
102
- @connection.connect
103
- end
95
+ if !Thread.current[:_excon_connection] || Thread.current[:_excon_connection].closed?
96
+ Thread.current[:_excon_connection] = establish_connection
104
97
  end
105
- @connection
98
+ Thread.current[:_excon_connection]
106
99
  end
107
100
 
101
+ def establish_connection
102
+ connection = TCPSocket.open(@uri.host, @uri.port)
103
+
104
+ if @uri.scheme == 'https'
105
+ @ssl_context = OpenSSL::SSL::SSLContext.new
106
+ @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
107
+ connection = OpenSSL::SSL::SSLSocket.new(connection, @ssl_context)
108
+ connection.sync_close = true
109
+ connection.connect
110
+ end
111
+
112
+ connection
113
+ end
108
114
  end
109
115
  end
110
116
 
@@ -0,0 +1,10 @@
1
+ Bundler.require_env(:test_server)
2
+
3
+ class App < Sinatra::Base
4
+ get '/id/:id/wait/:wait' do |id, wait|
5
+ sleep wait.to_i
6
+ id.to_s
7
+ end
8
+ end
9
+
10
+ run App
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
2
+
3
+ Excon.mock!
4
+
5
+ request = {
6
+ :host => 'www.google.com',
7
+ :method => 'GET',
8
+ :path => '/'
9
+ }
10
+ response = Excon::Response.new({
11
+ :status => 200,
12
+ :headers => { 'Content-Length' => '11' },
13
+ :body => 'Hello World'
14
+ })
15
+ Excon.mocks[request] = response
16
+
17
+ Shindo.tests do
18
+
19
+ before do
20
+ @connection = Excon.new('http://www.google.com')
21
+ @response = @connection.request({
22
+ :host => 'www.google.com',
23
+ :method => 'GET',
24
+ :path => '/'
25
+ })
26
+ end
27
+
28
+ test("status => 200") do
29
+ @response.status == 200
30
+ end
31
+
32
+ test("headers => { 'Content-Length' => '11' }") do
33
+ @response.headers == { 'Content-Length' => '11' }
34
+ end
35
+
36
+ test("body => 'Hello World") do
37
+ @response.body == 'Hello World'
38
+ end
39
+
40
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/excon'))
2
+
3
+ Bundler.require_env(:test)
4
+
5
+ def local_file(*parts)
6
+ File.expand_path(File.join(File.dirname(__FILE__), *parts))
7
+ end
8
+
9
+ def with_rackup(configru = local_file('config.ru'), rackup = local_file('..', 'bin', 'rackup'))
10
+ pid, w, r, e = Open4.popen4("#{rackup} #{configru}")
11
+ while `lsof -p #{pid} -P -i | grep ruby | grep TCP`.chomp.empty?; end
12
+ yield
13
+ Process.kill(9, pid)
14
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
2
+
3
+ with_rackup do
4
+ Shindo.tests do
5
+ test('threaded requests') do
6
+ connection = Excon.new('http://127.0.0.1:9292')
7
+
8
+ long_thread = Thread.new {
9
+ response = connection.request(:method => 'GET', :path => '/id/1/wait/2')
10
+ Thread.current[:success] = response.body == '1'
11
+ }
12
+
13
+ short_thread = Thread.new {
14
+ response = connection.request(:method => 'GET', :path => '/id/2/wait/1')
15
+ Thread.current[:success] = response.body == '2'
16
+ }
17
+
18
+ long_thread.join
19
+ short_thread.join
20
+
21
+ long_thread[:success] && short_thread[:success]
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wesley Beary
@@ -9,14 +9,15 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-17 00:00:00 -08:00
12
+ date: 2009-11-21 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description: speed, persistence, http(s)
17
17
  email: wbeary@engineyard.com
18
- executables: []
19
-
18
+ executables:
19
+ - rackup
20
+ - shindo
20
21
  extensions: []
21
22
 
22
23
  extra_rdoc_files:
@@ -24,6 +25,7 @@ extra_rdoc_files:
24
25
  files:
25
26
  - .document
26
27
  - .gitignore
28
+ - Gemfile
27
29
  - README.rdoc
28
30
  - Rakefile
29
31
  - VERSION
@@ -35,7 +37,10 @@ files:
35
37
  - lib/excon/connection.rb
36
38
  - lib/excon/errors.rb
37
39
  - lib/excon/response.rb
38
- - test/test.rb
40
+ - tests/config.ru
41
+ - tests/mock_tests.rb
42
+ - tests/test_helper.rb
43
+ - tests/threaded_tests.rb
39
44
  has_rdoc: true
40
45
  homepage: http://github.com/geemus/excon
41
46
  licenses: []
@@ -64,5 +69,5 @@ rubygems_version: 1.3.5
64
69
  signing_key:
65
70
  specification_version: 3
66
71
  summary: EXtended http(s) CONnections
67
- test_files:
68
- - test/test.rb
72
+ test_files: []
73
+
@@ -1,30 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'lib/excon')
2
-
3
- Excon.mock!
4
-
5
- request = {
6
- :host => 'www.google.com',
7
- :method => 'GET',
8
- :path => '/'
9
- }
10
- response = {
11
- :status => 200,
12
- :headers => { 'Content-Length' => '11' },
13
- :body => 'Hello World'
14
- }
15
- Excon.mocks[request] = response
16
-
17
- x = Excon.new('http://www.google.com')
18
-
19
- 10.times do
20
- p x.request(
21
- :host => 'www.google.com',
22
- :method => 'GET',
23
- :path => '/'
24
- )
25
- end
26
-
27
- # require 'open-uri'
28
- # 10.times do
29
- # p open('http://www.google.com').read
30
- # end