typhoeus 0.6.8 → 0.6.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.travis.yml +1 -1
- data/CHANGELOG.md +2 -1
- data/README.md +9 -0
- data/lib/typhoeus/easy_factory.rb +2 -2
- data/lib/typhoeus/hydra.rb +1 -1
- data/lib/typhoeus/hydra/queueable.rb +16 -0
- data/lib/typhoeus/hydra/runnable.rb +1 -7
- data/lib/typhoeus/request/stubbable.rb +2 -2
- data/lib/typhoeus/response/informations.rb +4 -0
- data/lib/typhoeus/version.rb +1 -1
- data/spec/rack/typhoeus/middleware/params_decoder/helper_spec.rb +4 -4
- data/spec/rack/typhoeus/middleware/params_decoder_spec.rb +2 -2
- data/spec/typhoeus/adapters/faraday_spec.rb +6 -6
- data/spec/typhoeus/easy_factory_spec.rb +8 -8
- data/spec/typhoeus/expectation_spec.rb +18 -18
- data/spec/typhoeus/hydra/addable_spec.rb +6 -6
- data/spec/typhoeus/hydra/before_spec.rb +9 -9
- data/spec/typhoeus/hydra/cacheable_spec.rb +6 -6
- data/spec/typhoeus/hydra/memoizable_spec.rb +5 -5
- data/spec/typhoeus/hydra/queueable_spec.rb +49 -0
- data/spec/typhoeus/hydra/runnable_spec.rb +11 -30
- data/spec/typhoeus/hydra/stubbable_spec.rb +1 -1
- data/spec/typhoeus/hydra_spec.rb +1 -1
- data/spec/typhoeus/pool_spec.rb +4 -4
- data/spec/typhoeus/request/before_spec.rb +9 -9
- data/spec/typhoeus/request/block_connection_spec.rb +5 -5
- data/spec/typhoeus/request/cacheable_spec.rb +4 -4
- data/spec/typhoeus/request/callbacks_spec.rb +3 -3
- data/spec/typhoeus/request/operations_spec.rb +7 -7
- data/spec/typhoeus/request/stubbable_spec.rb +1 -1
- data/spec/typhoeus/request_spec.rb +3 -3
- data/spec/typhoeus/response/header_spec.rb +2 -2
- data/spec/typhoeus/response/informations_spec.rb +9 -1
- data/spec/typhoeus/response/status_spec.rb +10 -10
- data/spec/typhoeus/response_spec.rb +4 -4
- data/spec/typhoeus_spec.rb +4 -4
- data/typhoeus.gemspec +1 -1
- metadata +7 -14
@@ -6,17 +6,17 @@ describe Typhoeus::Hydra::Addable do
|
|
6
6
|
|
7
7
|
it "asks easy factory for an easy" do
|
8
8
|
multi = double
|
9
|
-
Typhoeus::EasyFactory.
|
10
|
-
hydra.
|
11
|
-
multi.
|
9
|
+
expect(Typhoeus::EasyFactory).to receive(:new).with(request, hydra).and_return(double(:get => 1))
|
10
|
+
expect(hydra).to receive(:multi).and_return(multi)
|
11
|
+
expect(multi).to receive(:add).with(1)
|
12
12
|
hydra.add(request)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "adds easy to multi" do
|
16
16
|
multi = double
|
17
|
-
Typhoeus::EasyFactory.
|
18
|
-
hydra.
|
19
|
-
multi.
|
17
|
+
expect(Typhoeus::EasyFactory).to receive(:new).with(request, hydra).and_return(double(:get => 1))
|
18
|
+
expect(hydra).to receive(:multi).and_return(multi)
|
19
|
+
expect(multi).to receive(:add).with(1)
|
20
20
|
hydra.add(request)
|
21
21
|
end
|
22
22
|
end
|
@@ -9,14 +9,14 @@ describe Typhoeus::Hydra::Before do
|
|
9
9
|
context "when one" do
|
10
10
|
it "executes" do
|
11
11
|
Typhoeus.before { |r| String.new(r.base_url) }
|
12
|
-
String.
|
12
|
+
expect(String).to receive(:new).and_return("")
|
13
13
|
hydra.add(request)
|
14
14
|
end
|
15
15
|
|
16
16
|
context "when true" do
|
17
17
|
it "calls super" do
|
18
18
|
Typhoeus.before { true }
|
19
|
-
Typhoeus::Expectation.
|
19
|
+
expect(Typhoeus::Expectation).to receive(:response_for)
|
20
20
|
hydra.add(request)
|
21
21
|
end
|
22
22
|
end
|
@@ -37,7 +37,7 @@ describe Typhoeus::Hydra::Before do
|
|
37
37
|
context "when false" do
|
38
38
|
it "doesn't call super" do
|
39
39
|
Typhoeus.before { false }
|
40
|
-
Typhoeus::Expectation.
|
40
|
+
expect(Typhoeus::Expectation).to receive(:response_for).never
|
41
41
|
hydra.add(request)
|
42
42
|
end
|
43
43
|
end
|
@@ -45,7 +45,7 @@ describe Typhoeus::Hydra::Before do
|
|
45
45
|
context "when response" do
|
46
46
|
it "doesn't call super" do
|
47
47
|
Typhoeus.before { Typhoeus::Response.new }
|
48
|
-
Typhoeus::Expectation.
|
48
|
+
expect(Typhoeus::Expectation).to receive(:response_for).never
|
49
49
|
hydra.add(request)
|
50
50
|
end
|
51
51
|
end
|
@@ -57,12 +57,12 @@ describe Typhoeus::Hydra::Before do
|
|
57
57
|
before { 3.times { Typhoeus.before { |r| String.new(r.base_url) } } }
|
58
58
|
|
59
59
|
it "calls super" do
|
60
|
-
Typhoeus::Expectation.
|
60
|
+
expect(Typhoeus::Expectation).to receive(:response_for)
|
61
61
|
hydra.add(request)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "executes all" do
|
65
|
-
String.
|
65
|
+
expect(String).to receive(:new).exactly(3).times.and_return("")
|
66
66
|
hydra.add(request)
|
67
67
|
end
|
68
68
|
end
|
@@ -75,12 +75,12 @@ describe Typhoeus::Hydra::Before do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it "doesn't call super" do
|
78
|
-
Typhoeus::Expectation.
|
78
|
+
expect(Typhoeus::Expectation).to receive(:response_for).never
|
79
79
|
hydra.add(request)
|
80
80
|
end
|
81
81
|
|
82
82
|
it "executes only two" do
|
83
|
-
String.
|
83
|
+
expect(String).to receive(:new).exactly(2).times.and_return("")
|
84
84
|
hydra.add(request)
|
85
85
|
end
|
86
86
|
end
|
@@ -89,7 +89,7 @@ describe Typhoeus::Hydra::Before do
|
|
89
89
|
|
90
90
|
context "when no before" do
|
91
91
|
it "calls super" do
|
92
|
-
Typhoeus::Expectation.
|
92
|
+
expect(Typhoeus::Expectation).to receive(:response_for)
|
93
93
|
hydra.add(request)
|
94
94
|
end
|
95
95
|
end
|
@@ -18,7 +18,7 @@ describe Typhoeus::Hydra::Cacheable do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "doesn't call complete" do
|
21
|
-
request.
|
21
|
+
expect(request).to receive(:complete).never
|
22
22
|
hydra.add(request)
|
23
23
|
end
|
24
24
|
end
|
@@ -29,14 +29,14 @@ describe Typhoeus::Hydra::Cacheable do
|
|
29
29
|
|
30
30
|
it "returns response with cached status" do
|
31
31
|
hydra.add(request)
|
32
|
-
expect(response.cached?).to
|
32
|
+
expect(response.cached?).to be_truthy
|
33
33
|
end
|
34
34
|
|
35
35
|
context "when no queued requests" do
|
36
36
|
it "finishes request" do
|
37
|
-
request.
|
37
|
+
expect(request).to receive(:finish).with(response)
|
38
38
|
hydra.add(request)
|
39
|
-
expect(response.cached?).to
|
39
|
+
expect(response.cached?).to be_truthy
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -47,8 +47,8 @@ describe Typhoeus::Hydra::Cacheable do
|
|
47
47
|
|
48
48
|
it "finishes both requests" do
|
49
49
|
hydra.queue(queued_request)
|
50
|
-
request.
|
51
|
-
queued_request.
|
50
|
+
expect(request).to receive(:finish).with(response)
|
51
|
+
expect(queued_request).to receive(:finish).with(response)
|
52
52
|
hydra.add(request)
|
53
53
|
end
|
54
54
|
end
|
@@ -16,7 +16,7 @@ describe Typhoeus::Hydra::Memoizable do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "doesn't call complete" do
|
19
|
-
request.
|
19
|
+
expect(request).to receive(:complete).never
|
20
20
|
hydra.add(request)
|
21
21
|
end
|
22
22
|
end
|
@@ -26,7 +26,7 @@ describe Typhoeus::Hydra::Memoizable do
|
|
26
26
|
before { hydra.memory[request] = response }
|
27
27
|
|
28
28
|
it "finishes request" do
|
29
|
-
request.
|
29
|
+
expect(request).to receive(:finish).with(response, true)
|
30
30
|
hydra.add(request)
|
31
31
|
end
|
32
32
|
|
@@ -35,8 +35,8 @@ describe Typhoeus::Hydra::Memoizable do
|
|
35
35
|
|
36
36
|
it "dequeues" do
|
37
37
|
hydra.queue(queued_request)
|
38
|
-
request.
|
39
|
-
queued_request.
|
38
|
+
expect(request).to receive(:finish).with(response, true)
|
39
|
+
expect(queued_request).to receive(:finish).with(response, true)
|
40
40
|
hydra.add(request)
|
41
41
|
end
|
42
42
|
end
|
@@ -46,7 +46,7 @@ describe Typhoeus::Hydra::Memoizable do
|
|
46
46
|
|
47
47
|
describe "#run" do
|
48
48
|
it "clears memory before starting" do
|
49
|
-
hydra.memory.
|
49
|
+
expect(hydra.memory).to receive(:clear)
|
50
50
|
hydra.run
|
51
51
|
end
|
52
52
|
end
|
@@ -36,4 +36,53 @@ describe Typhoeus::Hydra::Queueable do
|
|
36
36
|
expect(hydra.queued_requests).to be_empty
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
describe "#dequeue_many" do
|
41
|
+
before do
|
42
|
+
requests.each { |r| hydra.queue r }
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when no request queued" do
|
46
|
+
let(:requests) { [] }
|
47
|
+
|
48
|
+
it "does nothing" do
|
49
|
+
expect(hydra).to_not receive(:add)
|
50
|
+
hydra.dequeue_many
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when request queued" do
|
55
|
+
let(:first) { Typhoeus::Request.new("localhost:3001/first") }
|
56
|
+
let(:requests) { [first] }
|
57
|
+
|
58
|
+
it "adds request from queue to multi" do
|
59
|
+
expect(hydra).to receive(:add).with(first)
|
60
|
+
hydra.dequeue_many
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when three request queued" do
|
65
|
+
let(:first) { Typhoeus::Request.new("localhost:3001/first") }
|
66
|
+
let(:second) { Typhoeus::Request.new("localhost:3001/second") }
|
67
|
+
let(:third) { Typhoeus::Request.new("localhost:3001/third") }
|
68
|
+
let(:requests) { [first, second, third] }
|
69
|
+
|
70
|
+
it "adds requests from queue to multi" do
|
71
|
+
expect(hydra).to receive(:add).with(first)
|
72
|
+
expect(hydra).to receive(:add).with(second)
|
73
|
+
expect(hydra).to receive(:add).with(third)
|
74
|
+
hydra.dequeue_many
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when max_concurrency is two" do
|
78
|
+
let(:options) { {:max_concurrency => 2} }
|
79
|
+
it "adds requests from queue to multi" do
|
80
|
+
expect(hydra).to receive(:add).with(first)
|
81
|
+
expect(hydra).to receive(:add).with(second)
|
82
|
+
expect(hydra).to_not receive(:add).with(third)
|
83
|
+
hydra.dequeue_many
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
39
88
|
end
|
@@ -6,33 +6,26 @@ describe Typhoeus::Hydra::Runnable do
|
|
6
6
|
let(:hydra) { Typhoeus::Hydra.new(options) }
|
7
7
|
|
8
8
|
describe "#run" do
|
9
|
+
let(:requests) { [] }
|
10
|
+
|
9
11
|
before do
|
10
12
|
requests.each { |r| hydra.queue r }
|
11
13
|
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
+
it "runs multi#dequeue_many" do
|
16
|
+
expect(hydra).to receive(:dequeue_many)
|
17
|
+
hydra.run
|
18
|
+
end
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
+
it "runs multi#perform" do
|
21
|
+
expect(hydra.multi).to receive(:perform)
|
22
|
+
hydra.run
|
20
23
|
end
|
21
24
|
|
22
25
|
context "when request queued" do
|
23
26
|
let(:first) { Typhoeus::Request.new("localhost:3001/first") }
|
24
27
|
let(:requests) { [first] }
|
25
28
|
|
26
|
-
it "adds request from queue to multi" do
|
27
|
-
hydra.should_receive(:add).with(first)
|
28
|
-
hydra.run
|
29
|
-
end
|
30
|
-
|
31
|
-
it "runs multi#perform" do
|
32
|
-
hydra.multi.should_receive(:perform)
|
33
|
-
hydra.run
|
34
|
-
end
|
35
|
-
|
36
29
|
it "sends" do
|
37
30
|
hydra.run
|
38
31
|
expect(first.response).to be
|
@@ -45,18 +38,6 @@ describe Typhoeus::Hydra::Runnable do
|
|
45
38
|
let(:third) { Typhoeus::Request.new("localhost:3001/third") }
|
46
39
|
let(:requests) { [first, second, third] }
|
47
40
|
|
48
|
-
it "adds requests from queue to multi" do
|
49
|
-
hydra.should_receive(:add).with(first)
|
50
|
-
hydra.should_receive(:add).with(second)
|
51
|
-
hydra.should_receive(:add).with(third)
|
52
|
-
hydra.run
|
53
|
-
end
|
54
|
-
|
55
|
-
it "runs multi#perform" do
|
56
|
-
hydra.multi.should_receive(:perform)
|
57
|
-
hydra.run
|
58
|
-
end
|
59
|
-
|
60
41
|
it "sends first" do
|
61
42
|
hydra.run
|
62
43
|
expect(first.response).to be
|
@@ -134,7 +115,7 @@ describe Typhoeus::Hydra::Runnable do
|
|
134
115
|
let(:options) { {} }
|
135
116
|
|
136
117
|
it "calls on_complete callback once for every response" do
|
137
|
-
String.
|
118
|
+
expect(String).to receive(:new).exactly(2).times
|
138
119
|
hydra.run
|
139
120
|
end
|
140
121
|
end
|
@@ -145,7 +126,7 @@ describe Typhoeus::Hydra::Runnable do
|
|
145
126
|
before { Typhoeus.before{ |request| request.finish(Typhoeus::Response.new) } }
|
146
127
|
|
147
128
|
it "simulates real multi run and adds and finishes both requests" do
|
148
|
-
String.
|
129
|
+
expect(String).to receive(:new).exactly(2).times
|
149
130
|
hydra.run
|
150
131
|
end
|
151
132
|
end
|
data/spec/typhoeus/hydra_spec.rb
CHANGED
data/spec/typhoeus/pool_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe Typhoeus::Pool do
|
|
12
12
|
|
13
13
|
describe "#release" do
|
14
14
|
it "resets easy" do
|
15
|
-
easy.
|
15
|
+
expect(easy).to receive(:reset)
|
16
16
|
Typhoeus::Pool.release(easy)
|
17
17
|
end
|
18
18
|
|
@@ -28,7 +28,7 @@ describe Typhoeus::Pool do
|
|
28
28
|
Typhoeus::Pool.release(Ethon::Easy.new)
|
29
29
|
end
|
30
30
|
end.map(&:join)
|
31
|
-
expect(Typhoeus::Pool.send(:easies)).to
|
31
|
+
expect(Typhoeus::Pool.send(:easies).size).to eq(10)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -55,7 +55,7 @@ describe Typhoeus::Pool do
|
|
55
55
|
array << Typhoeus::Pool.get
|
56
56
|
end
|
57
57
|
end.map(&:join)
|
58
|
-
expect(array.uniq).to
|
58
|
+
expect(array.uniq.size).to eq(10)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -73,7 +73,7 @@ describe Typhoeus::Pool do
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
76
|
-
expect(array.uniq).to
|
76
|
+
expect(array.uniq.size).to eq(3)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -8,14 +8,14 @@ describe Typhoeus::Request::Before do
|
|
8
8
|
context "when one" do
|
9
9
|
it "executes" do
|
10
10
|
Typhoeus.before { |r| String.new(r.base_url) }
|
11
|
-
String.
|
11
|
+
expect(String).to receive(:new).and_return("")
|
12
12
|
request.run
|
13
13
|
end
|
14
14
|
|
15
15
|
context "when true" do
|
16
16
|
it "calls super" do
|
17
17
|
Typhoeus.before { true }
|
18
|
-
Typhoeus::Expectation.
|
18
|
+
expect(Typhoeus::Expectation).to receive(:response_for)
|
19
19
|
request.run
|
20
20
|
end
|
21
21
|
end
|
@@ -23,7 +23,7 @@ describe Typhoeus::Request::Before do
|
|
23
23
|
context "when false" do
|
24
24
|
it "doesn't call super" do
|
25
25
|
Typhoeus.before { false }
|
26
|
-
Typhoeus::Expectation.
|
26
|
+
expect(Typhoeus::Expectation).to receive(:response_for).never
|
27
27
|
request.run
|
28
28
|
end
|
29
29
|
|
@@ -36,7 +36,7 @@ describe Typhoeus::Request::Before do
|
|
36
36
|
context "when a response" do
|
37
37
|
it "doesn't call super" do
|
38
38
|
Typhoeus.before { Typhoeus::Response.new }
|
39
|
-
Typhoeus::Expectation.
|
39
|
+
expect(Typhoeus::Expectation).to receive(:response_for).never
|
40
40
|
request.run
|
41
41
|
end
|
42
42
|
|
@@ -52,12 +52,12 @@ describe Typhoeus::Request::Before do
|
|
52
52
|
before { 3.times { Typhoeus.before { |r| String.new(r.base_url) } } }
|
53
53
|
|
54
54
|
it "calls super" do
|
55
|
-
Typhoeus::Expectation.
|
55
|
+
expect(Typhoeus::Expectation).to receive(:response_for)
|
56
56
|
request.run
|
57
57
|
end
|
58
58
|
|
59
59
|
it "executes all" do
|
60
|
-
String.
|
60
|
+
expect(String).to receive(:new).exactly(3).times.and_return("")
|
61
61
|
request.run
|
62
62
|
end
|
63
63
|
end
|
@@ -70,12 +70,12 @@ describe Typhoeus::Request::Before do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it "doesn't call super" do
|
73
|
-
Typhoeus::Expectation.
|
73
|
+
expect(Typhoeus::Expectation).to receive(:response_for).never
|
74
74
|
request.run
|
75
75
|
end
|
76
76
|
|
77
77
|
it "executes only two" do
|
78
|
-
String.
|
78
|
+
expect(String).to receive(:new).exactly(2).times.and_return("")
|
79
79
|
request.run
|
80
80
|
end
|
81
81
|
end
|
@@ -84,7 +84,7 @@ describe Typhoeus::Request::Before do
|
|
84
84
|
|
85
85
|
context "when no before" do
|
86
86
|
it "calls super" do
|
87
|
-
Typhoeus::Expectation.
|
87
|
+
expect(Typhoeus::Expectation).to receive(:response_for)
|
88
88
|
request.run
|
89
89
|
end
|
90
90
|
end
|
@@ -28,7 +28,7 @@ describe Typhoeus::Request::BlockConnection do
|
|
28
28
|
before { request.block_connection = true }
|
29
29
|
|
30
30
|
it "returns true" do
|
31
|
-
expect(request.blocked?).to
|
31
|
+
expect(request.blocked?).to be_truthy
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -36,7 +36,7 @@ describe Typhoeus::Request::BlockConnection do
|
|
36
36
|
before { request.block_connection = false }
|
37
37
|
|
38
38
|
it "returns false" do
|
39
|
-
expect(request.blocked?).to
|
39
|
+
expect(request.blocked?).to be_falsey
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -47,7 +47,7 @@ describe Typhoeus::Request::BlockConnection do
|
|
47
47
|
after { Typhoeus::Config.block_connection = false }
|
48
48
|
|
49
49
|
it "returns true" do
|
50
|
-
expect(request.blocked?).to
|
50
|
+
expect(request.blocked?).to be_truthy
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -55,7 +55,7 @@ describe Typhoeus::Request::BlockConnection do
|
|
55
55
|
before { Typhoeus::Config.block_connection = false }
|
56
56
|
|
57
57
|
it "returns false" do
|
58
|
-
expect(request.blocked?).to
|
58
|
+
expect(request.blocked?).to be_falsey
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -68,7 +68,7 @@ describe Typhoeus::Request::BlockConnection do
|
|
68
68
|
after { Typhoeus::Config.block_connection = false }
|
69
69
|
|
70
70
|
it "takes local" do
|
71
|
-
expect(request.blocked?).to
|
71
|
+
expect(request.blocked?).to be_falsey
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|