em_aws 0.3.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -1
- data/.travis.yml +14 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +51 -34
- data/HISTORY.md +17 -2
- data/LICENSE.txt +1 -1
- data/README.md +11 -25
- data/Rakefile +4 -0
- data/em_aws.gemspec +8 -6
- data/lib/aws/core/http/em_http_handler.rb +2 -199
- data/lib/em-aws.rb +17 -0
- data/lib/em-aws/http_handler.rb +188 -0
- data/lib/{em_aws → em-aws}/patches.rb +0 -0
- data/lib/em-aws/version.rb +5 -0
- data/lib/em_aws.rb +1 -12
- data/spec/em-aws/http_handler_spec.rb +297 -0
- data/spec/{patches_spec.rb → em-aws/patches_spec.rb} +11 -10
- data/spec/integration/dynamo_db_spec.rb +53 -0
- data/spec/integration/s3_spec.rb +55 -0
- data/spec/spec_helper.rb +12 -3
- metadata +71 -49
- data/lib/em_aws/version.rb +0 -3
- data/spec/em_http_handler_spec.rb +0 -250
@@ -1,35 +1,36 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'aws'
|
3
2
|
describe Mutex do
|
4
|
-
|
3
|
+
around(:each) do |example|
|
5
4
|
EM.synchrony do
|
6
|
-
|
5
|
+
example.run
|
7
6
|
EM.stop
|
8
7
|
end
|
9
8
|
end
|
10
9
|
|
11
10
|
it "should be a fiber safe mutex" do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
expect(AWS::Mutex.new).to be_kind_of(EM::Synchrony::Thread::Mutex)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be a fiber safe mutex" do
|
15
|
+
expect(AWS.mutex.new).to be_kind_of(EM::Synchrony::Thread::Mutex)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should not affect Mutex outside AWS" do
|
19
|
-
Mutex.new.
|
19
|
+
expect(Mutex.new).to be_kind_of(Mutex)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe Kernel, '#sleep' do
|
24
|
+
|
24
25
|
it "should be a fiber safe sleep from with AWS module" do
|
25
26
|
EM.synchrony do
|
26
27
|
EM::Synchrony.stub(:sleep).and_return("fiber safe")
|
27
|
-
Kernel.sleep(1).
|
28
|
+
expect(Kernel.sleep(1)).to eql("fiber safe")
|
28
29
|
EM.stop
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
33
|
it "should not affect normal Kernel.sleep if not in EM" do
|
33
|
-
Kernel.sleep(1).
|
34
|
+
expect(Kernel.sleep(1)).to eql(1)
|
34
35
|
end
|
35
36
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'aws-sdk-v1'
|
3
|
+
require 'aws/core/http/em_http_handler'
|
4
|
+
|
5
|
+
describe AWS::DynamoDB do
|
6
|
+
if ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY']
|
7
|
+
|
8
|
+
around(:each) do |example|
|
9
|
+
EM.synchrony do
|
10
|
+
example.run
|
11
|
+
EM.stop
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should work" do
|
16
|
+
begin
|
17
|
+
AWS.config( :http_handler => AWS::Http::EMHttpHandler.new(:pool_size => 20))
|
18
|
+
dynamo_db = AWS::DynamoDB.new
|
19
|
+
dynamo_db.tables['mytable'].delete if dynamo_db.tables['mytable'].exists?
|
20
|
+
|
21
|
+
# Create table
|
22
|
+
dynamo_db.tables.create('mytable', 10, 5) unless dynamo_db.tables['mytable'].exists?
|
23
|
+
table = dynamo_db.tables['mytable']
|
24
|
+
|
25
|
+
sleep 1 while table.status == :creating
|
26
|
+
|
27
|
+
expect(table).to be_exists
|
28
|
+
|
29
|
+
# Concurrent writes
|
30
|
+
fibers = []
|
31
|
+
5.times.each do |i|
|
32
|
+
fiber = Fiber.new do
|
33
|
+
table.batch_put([{ :id => "id#{i}"}])
|
34
|
+
end
|
35
|
+
fiber.resume
|
36
|
+
fibers << fiber
|
37
|
+
end
|
38
|
+
|
39
|
+
# Wait until work is done
|
40
|
+
while fibers.detect(&:alive?)
|
41
|
+
EM::Synchrony.sleep(0.01)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Read our results
|
45
|
+
items = %w(id0 id1 id2 id3 id4)
|
46
|
+
expect(table.batch_get('id',items).to_a.collect{ |h| h['id']}.sort).to eql(['id0','id1','id2','id3','id4'])
|
47
|
+
ensure
|
48
|
+
table.delete if table && table.status != :deleting && table.exists? #clean up
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'aws-sdk-v1'
|
3
|
+
require 'aws/core/http/em_http_handler'
|
4
|
+
|
5
|
+
describe AWS::S3 do
|
6
|
+
if ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY']
|
7
|
+
|
8
|
+
around(:each) do |example|
|
9
|
+
EM.synchrony do
|
10
|
+
example.run
|
11
|
+
EM.stop
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should work" do
|
16
|
+
begin
|
17
|
+
AWS.config( :http_handler => AWS::Http::EMHttpHandler.new )
|
18
|
+
s3 = AWS::S3.new
|
19
|
+
|
20
|
+
# Create bucket
|
21
|
+
s3.buckets.create('em_test_bucket')
|
22
|
+
bucket = s3.buckets['em_test_bucket']
|
23
|
+
expect(bucket).to be_exists
|
24
|
+
|
25
|
+
# Concurrent writes
|
26
|
+
filler = '1'*1048576
|
27
|
+
|
28
|
+
fibers = []
|
29
|
+
5.times.each do |i|
|
30
|
+
fiber = Fiber.new do
|
31
|
+
bucket.objects["test#{i}"].write(filler)
|
32
|
+
end
|
33
|
+
fiber.resume
|
34
|
+
fibers << fiber
|
35
|
+
end
|
36
|
+
|
37
|
+
# Wait until work is done
|
38
|
+
while fibers.detect(&:alive?)
|
39
|
+
EM::Synchrony.sleep(0.01)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Streaming/Read
|
43
|
+
streamed = []
|
44
|
+
bucket.objects["test1"].read do |chunk|
|
45
|
+
streamed << chunk
|
46
|
+
end
|
47
|
+
expect(streamed.length).to be > 1 # make sure streaming took place
|
48
|
+
expect(streamed.join).to eql(filler)
|
49
|
+
ensure
|
50
|
+
bucket.delete! if bucket # clean up
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
#$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
#$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
require '
|
4
|
-
require 'aws/core/http/em_http_handler'
|
3
|
+
require 'em-aws'
|
5
4
|
require 'rspec'
|
6
5
|
require 'bundler/setup'
|
7
6
|
require 'logger'
|
8
|
-
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'byebug'
|
10
|
+
rescue LoadError
|
11
|
+
end
|
9
12
|
|
10
13
|
# Requires supporting files with custom matchers and macros, etc,
|
11
14
|
# in ./support/ and its subdirectories.
|
@@ -15,7 +18,13 @@ class StubLogger
|
|
15
18
|
#we don't care
|
16
19
|
end
|
17
20
|
end
|
21
|
+
|
22
|
+
|
18
23
|
AWS.config(:logger => StubLogger.new)
|
19
24
|
|
25
|
+
# EM::HotTub.logger = Logger.new(STDOUT)
|
26
|
+
# EM::HotTub.trace = true
|
27
|
+
|
20
28
|
RSpec.configure do |config|
|
29
|
+
|
21
30
|
end
|
metadata
CHANGED
@@ -1,121 +1,138 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em_aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Joshua Mckinney
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-12-28 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name: aws-sdk
|
14
|
+
name: aws-sdk-v1
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: em-synchrony
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: em-http-request
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
|
-
name: hot_tub
|
56
|
+
name: em-hot_tub
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- - ~>
|
59
|
+
- - "~>"
|
68
60
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
61
|
+
version: 1.1.0
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
76
81
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
82
|
+
version: '1.7'
|
78
83
|
- !ruby/object:Gem::Dependency
|
79
84
|
name: rspec
|
80
85
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
86
|
requirements:
|
83
|
-
- -
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-autotest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
84
102
|
- !ruby/object:Gem::Version
|
85
103
|
version: '0'
|
86
104
|
type: :development
|
87
105
|
prerelease: false
|
88
106
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
107
|
requirements:
|
91
|
-
- -
|
108
|
+
- - ">="
|
92
109
|
- !ruby/object:Gem::Version
|
93
110
|
version: '0'
|
94
111
|
- !ruby/object:Gem::Dependency
|
95
|
-
name:
|
112
|
+
name: autotest
|
96
113
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
114
|
requirements:
|
99
|
-
- -
|
115
|
+
- - ">="
|
100
116
|
- !ruby/object:Gem::Version
|
101
117
|
version: '0'
|
102
118
|
type: :development
|
103
119
|
prerelease: false
|
104
120
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
121
|
requirements:
|
107
|
-
- -
|
122
|
+
- - ">="
|
108
123
|
- !ruby/object:Gem::Version
|
109
124
|
version: '0'
|
110
|
-
description:
|
125
|
+
description: An em-http-request handler for the aws-sdk for Fiber based asynchronous
|
126
|
+
ruby application using EM-Synchrony
|
111
127
|
email:
|
112
128
|
- joshmckin@gmail.com
|
113
129
|
executables: []
|
114
130
|
extensions: []
|
115
131
|
extra_rdoc_files: []
|
116
132
|
files:
|
117
|
-
- .gitignore
|
118
|
-
- .rspec
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".travis.yml"
|
119
136
|
- Gemfile
|
120
137
|
- Gemfile.lock
|
121
138
|
- HISTORY.md
|
@@ -124,38 +141,43 @@ files:
|
|
124
141
|
- Rakefile
|
125
142
|
- em_aws.gemspec
|
126
143
|
- lib/aws/core/http/em_http_handler.rb
|
144
|
+
- lib/em-aws.rb
|
145
|
+
- lib/em-aws/http_handler.rb
|
146
|
+
- lib/em-aws/patches.rb
|
147
|
+
- lib/em-aws/version.rb
|
127
148
|
- lib/em_aws.rb
|
128
|
-
-
|
129
|
-
-
|
130
|
-
- spec/
|
131
|
-
- spec/
|
149
|
+
- spec/em-aws/http_handler_spec.rb
|
150
|
+
- spec/em-aws/patches_spec.rb
|
151
|
+
- spec/integration/dynamo_db_spec.rb
|
152
|
+
- spec/integration/s3_spec.rb
|
132
153
|
- spec/spec_helper.rb
|
133
154
|
homepage: https://github.com/JoshMcKin/em_aws
|
134
155
|
licenses:
|
135
156
|
- MIT
|
157
|
+
metadata: {}
|
136
158
|
post_install_message:
|
137
159
|
rdoc_options: []
|
138
160
|
require_paths:
|
139
161
|
- lib
|
140
162
|
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
-
none: false
|
142
163
|
requirements:
|
143
|
-
- -
|
164
|
+
- - ">="
|
144
165
|
- !ruby/object:Gem::Version
|
145
166
|
version: '0'
|
146
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
-
none: false
|
148
168
|
requirements:
|
149
|
-
- -
|
169
|
+
- - ">="
|
150
170
|
- !ruby/object:Gem::Version
|
151
171
|
version: '0'
|
152
172
|
requirements: []
|
153
173
|
rubyforge_project: em_aws
|
154
|
-
rubygems_version:
|
174
|
+
rubygems_version: 2.5.1
|
155
175
|
signing_key:
|
156
|
-
specification_version:
|
176
|
+
specification_version: 4
|
157
177
|
summary: Adds EM-Synchrony support to AWS-SDK gem
|
158
178
|
test_files:
|
159
|
-
- spec/
|
160
|
-
- spec/patches_spec.rb
|
179
|
+
- spec/em-aws/http_handler_spec.rb
|
180
|
+
- spec/em-aws/patches_spec.rb
|
181
|
+
- spec/integration/dynamo_db_spec.rb
|
182
|
+
- spec/integration/s3_spec.rb
|
161
183
|
- spec/spec_helper.rb
|
data/lib/em_aws/version.rb
DELETED
@@ -1,250 +0,0 @@
|
|
1
|
-
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
4
|
-
# may not use this file except in compliance with the License. A copy of
|
5
|
-
# the License is located at
|
6
|
-
#
|
7
|
-
# http://aws.amazon.com/apache2.0/
|
8
|
-
#
|
9
|
-
# or in the "license" file accompanying this file. This file is
|
10
|
-
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11
|
-
# ANY KIND, either express or implied. See the License for the specific
|
12
|
-
# language governing permissions and limitations under the License.
|
13
|
-
|
14
|
-
require 'spec_helper'
|
15
|
-
require 'eventmachine'
|
16
|
-
require 'evma_httpserver'
|
17
|
-
module AWS::Core
|
18
|
-
module Http
|
19
|
-
class EMFooIO
|
20
|
-
def path
|
21
|
-
"/my_path/test.text"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# A slow server for testing timeout,
|
26
|
-
# borrowed from: http://www.igvita.com/2008/05/27/ruby-eventmachine-the-speed-demon/
|
27
|
-
class SlowServer < EventMachine::Connection
|
28
|
-
include EventMachine::HttpServer
|
29
|
-
|
30
|
-
def process_http_request
|
31
|
-
resp = EventMachine::DelegatedHttpResponse.new( self )
|
32
|
-
|
33
|
-
sleep 2 # Simulate a long running request
|
34
|
-
|
35
|
-
resp.status = 200
|
36
|
-
resp.content = "Hello World!"
|
37
|
-
resp.send_response
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe EMHttpHandler do
|
42
|
-
let(:handler) { EMHttpHandler.new(default_request_options) }
|
43
|
-
|
44
|
-
let(:default_request_options) { Hash.new }
|
45
|
-
|
46
|
-
let(:req) do
|
47
|
-
r = Http::Request.new
|
48
|
-
r.host = "foo.bar.com"
|
49
|
-
r.uri = "/my_path/?foo=bar"
|
50
|
-
r.body_stream = StringIO.new("myStringIO")
|
51
|
-
r
|
52
|
-
end
|
53
|
-
|
54
|
-
let(:resp) { Http::Response.new }
|
55
|
-
|
56
|
-
let(:em_http_options) do
|
57
|
-
options = nil
|
58
|
-
EMHttpHandler.should_receive(:fetch_response).with do |url, _, opts|
|
59
|
-
options = opts
|
60
|
-
double("http response",
|
61
|
-
:response => "<foo/>",
|
62
|
-
:code => 200,
|
63
|
-
:to_hash => {})
|
64
|
-
end
|
65
|
-
|
66
|
-
handler.handle(req, resp)
|
67
|
-
|
68
|
-
options
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should be accessible from AWS as well as AWS::Core' do
|
72
|
-
AWS::Http::EMHttpHandler.new
|
73
|
-
.should be_an(AWS::Core::Http::EMHttpHandler)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should not timeout" do
|
77
|
-
EM.synchrony do
|
78
|
-
response = Http::Response.new
|
79
|
-
request = Http::Request.new
|
80
|
-
request.host = "127.0.0.1"
|
81
|
-
request.port = "8081"
|
82
|
-
request.uri = "/"
|
83
|
-
request.body_stream = StringIO.new("myStringIO")
|
84
|
-
|
85
|
-
# turn on our test server
|
86
|
-
EventMachine::run do
|
87
|
-
EventMachine::start_server request.host, request.port, SlowServer
|
88
|
-
end
|
89
|
-
|
90
|
-
handler.stub(:fetch_url).and_return("http://127.0.0.1:8081")
|
91
|
-
|
92
|
-
handler.handle(request,response)
|
93
|
-
|
94
|
-
response.network_error.should be_nil
|
95
|
-
|
96
|
-
EM.stop
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should timeout after 0.1 seconds" do
|
101
|
-
EM.synchrony do
|
102
|
-
response = Http::Response.new
|
103
|
-
request = Http::Request.new
|
104
|
-
request.host = "127.0.0.1"
|
105
|
-
request.port = "8081"
|
106
|
-
request.uri = "/"
|
107
|
-
request.body_stream = StringIO.new("myStringIO")
|
108
|
-
|
109
|
-
# turn on our test server
|
110
|
-
EventMachine::run do
|
111
|
-
EventMachine::start_server request.host, request.port, SlowServer
|
112
|
-
end
|
113
|
-
|
114
|
-
handler.stub(:fetch_url).and_return("http://127.0.0.1:8081")
|
115
|
-
request.stub(:read_timeout).and_return(0.01)
|
116
|
-
handler.stub(:connect_timeout).and_return(1) #just to speed up the test
|
117
|
-
|
118
|
-
handler.handle(request,response)
|
119
|
-
|
120
|
-
response.network_error.should be_a(Timeout::Error)
|
121
|
-
|
122
|
-
EM.stop
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe '#handle' do
|
127
|
-
context 'timeouts' do
|
128
|
-
it 'should rescue Timeout::Error' do
|
129
|
-
handler
|
130
|
-
.stub(:fetch_response)
|
131
|
-
.and_raise(Timeout::Error)
|
132
|
-
|
133
|
-
expect {
|
134
|
-
handler.handle(req, resp)
|
135
|
-
}.to_not raise_error
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'should rescue Errno::ETIMEDOUT' do
|
139
|
-
handler
|
140
|
-
.stub(:fetch_response)
|
141
|
-
.and_raise(Errno::ETIMEDOUT)
|
142
|
-
|
143
|
-
expect {
|
144
|
-
handler.handle(req, resp)
|
145
|
-
}.to_not raise_error
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'should indicate that there was a network_error' do
|
149
|
-
handler
|
150
|
-
.stub(:fetch_response)
|
151
|
-
.and_raise(Errno::ETIMEDOUT)
|
152
|
-
|
153
|
-
handler.handle(req, resp)
|
154
|
-
|
155
|
-
resp.network_error?.should be_true
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
context 'default request options' do
|
160
|
-
before(:each) do
|
161
|
-
handler
|
162
|
-
.stub(:default_request_options)
|
163
|
-
.and_return(:foo => "BAR", :private_key_file => "blarg")
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'passes extra options through to synchrony' do
|
167
|
-
handler.default_request_options[:foo].should == "BAR"
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'uses the default when the request option is not set' do
|
171
|
-
#puts handler.default_request_options
|
172
|
-
handler.default_request_options[:private_key_file].should == "blarg"
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
describe '#fetch_request_options' do
|
178
|
-
it "should set :query and :body to request.querystring" do
|
179
|
-
opts = handler.send(:fetch_request_options, req)
|
180
|
-
opts[:query].should eql(req.querystring)
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should set :path to request.path" do
|
184
|
-
opts = handler.send(:fetch_request_options, req)
|
185
|
-
opts[:path].should eql(req.path)
|
186
|
-
end
|
187
|
-
|
188
|
-
context "request.body_stream is a StringIO" do
|
189
|
-
it "should set :body to request.body_stream" do
|
190
|
-
opts = handler.send(:fetch_request_options, req)
|
191
|
-
opts[:body].should eql("myStringIO")
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
context "request.body_stream is an object that responds to :path" do
|
196
|
-
let(:io_object) { EMFooIO.new }
|
197
|
-
|
198
|
-
before(:each) do
|
199
|
-
req
|
200
|
-
.stub(:body_stream)
|
201
|
-
.and_return(io_object)
|
202
|
-
end
|
203
|
-
|
204
|
-
it "should set :file to object.path " do
|
205
|
-
opts = handler.send(:fetch_request_options, req)
|
206
|
-
opts[:file].should eql(io_object.path)
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
describe '#fetch_client_options' do
|
212
|
-
it "should remove pool related options" do
|
213
|
-
opts = handler.send(:fetch_client_options)
|
214
|
-
|
215
|
-
opts.has_key?(:size).should be_false
|
216
|
-
opts.has_key?(:never_block).should be_false
|
217
|
-
opts.has_key?(:blocking_timeout).should be_false
|
218
|
-
end
|
219
|
-
|
220
|
-
context "when with_pool is true" do
|
221
|
-
before(:each) do
|
222
|
-
handler
|
223
|
-
.stub(:with_pool?)
|
224
|
-
.and_return(true)
|
225
|
-
end
|
226
|
-
|
227
|
-
it "should set keepalive as true" do
|
228
|
-
opts = handler.send(:fetch_client_options)
|
229
|
-
|
230
|
-
opts[:keepalive].should be_true
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
context "when with_pool is false" do
|
235
|
-
before(:each) do
|
236
|
-
handler
|
237
|
-
.stub(:with_pool?)
|
238
|
-
.and_return(false)
|
239
|
-
end
|
240
|
-
|
241
|
-
it "should keepalive be false" do
|
242
|
-
opts = handler.send(:fetch_client_options)
|
243
|
-
|
244
|
-
opts[:keepalive].should_not be_true
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|