muxer 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cbe8738783f06b32d10471723bb67a93db7d4b2
4
- data.tar.gz: 1f84ad1ec573791317e96fdd2fc499a88774fe10
3
+ metadata.gz: b73dfc85ba92609e00c19e7e986454e2d9cc5183
4
+ data.tar.gz: 4e74fa3753b1d28ea499a8d49b795c2ae96ad834
5
5
  SHA512:
6
- metadata.gz: f5c63ae1b19c7d41b2abdb00d12824c2980939c0fdbec3584b5a79cb7bac2e11dcda357a2751273ab2b6d007c2d942d7ecd2f612a1a45ccf3a7520c52876bf08
7
- data.tar.gz: a8c372bea209d0524b67c01d0409089d85a90b4afac42057cdbd588f3cd935fac5b482d628a91a0a46b4721b2ba0729b204d5577d4ddf3147b6b2976a66534b4
6
+ metadata.gz: 5d2086c7940d70b2527d15dff7f442c9f7dfdf3b2255e06e8973bbd0f19b63def4b3a26a211c66c66ae8777e06a7ad827496e851e6915112c3f70f479ad33d53
7
+ data.tar.gz: 6302923a3fa091c6f79cdecffb60994f498acc28083a3207aa412a9f9f8a9ede6a87464940dbc8a171e5ea99c0e8f563f7d64020abb9af9b88cf109ffa2c3ca1
data/README.md CHANGED
@@ -5,7 +5,11 @@
5
5
  [![Build](https://img.shields.io/travis-ci/ChrisMacNaughton/muxer.svg?style=flat-square)](https://travis-ci.org/ChrisMacNaughton/muxer)
6
6
  [![Dependencies](https://img.shields.io/gemnasium/ChrisMacNaughton/muxer.svg?style=flat-square)](https://gemnasium.com/ChrisMacNaughton/muxer)
7
7
  [![Downloads](https://img.shields.io/gem/dtv/muxer.svg?style=flat-square)](https://rubygems.org/gems/muxer)
8
- [![Tags](https://img.shields.io/github/tag/ChrisMacNaughton/muxer.svg?style=flat-square)](https://github.com/ChrisMacNaughton/muxer/tags)[![Releases](https://img.shields.io/github/release/ChrisMacNaughton/muxer.svg?style=flat-square)](https://github.com/ChrisMacNaughton/muxer/releases)[![Issues](https://img.shields.io/github/issues/ChrisMacNaughton/muxer.svg?style=flat-square)](https://github.com/ChrisMacNaughton/muxer/issues)[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://opensource.org/licenses/MIT)[![Version](https://img.shields.io/gem/v/muxer.svg?style=flat-square)](https://rubygems.org/gems/muxer)
8
+ [![Tags](https://img.shields.io/github/tag/ChrisMacNaughton/muxer.svg?style=flat-square)](https://github.com/ChrisMacNaughton/muxer/tags)
9
+ [![Releases](https://img.shields.io/github/release/ChrisMacNaughton/muxer.svg?style=flat-square)](https://github.com/ChrisMacNaughton/muxer/releases)
10
+ [![Issues](https://img.shields.io/github/issues/ChrisMacNaughton/muxer.svg?style=flat-square)](https://github.com/ChrisMacNaughton/muxer/issues)
11
+ [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://opensource.org/licenses/MIT)
12
+ [![Version](https://img.shields.io/gem/v/muxer.svg?style=flat-square)](https://rubygems.org/gems/muxer)
9
13
 
10
14
  Muxer is a gem to allow web requests to run in parallel with seperate timeouts per request, in addition to an optional global timeout for all of the requests.
11
15
 
@@ -41,7 +45,10 @@ response = Muxer.execute do |muxer|
41
45
  end
42
46
 
43
47
  response[:failed] == []
44
- response[:succeeded] == [Muxer::Request(url: "http://www.rubydoc.info"), Muxer::Request(url: "https://www.google.com")]
48
+ response[:succeeded] == [
49
+ Muxer::Request(url: "http://www.rubydoc.info"),
50
+ Muxer::Request(url: "https://www.google.com")
51
+ ]
45
52
  ```
46
53
  ## Contributing
47
54
 
@@ -55,7 +55,7 @@ module Muxer
55
55
  end
56
56
 
57
57
  def process_timeouts
58
- if @timeout && Time.now >= finish
58
+ if @timeout && (@start + @timeout <= Time.now)
59
59
  finish_timeouts
60
60
  return
61
61
  end
data/lib/muxer/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Muxer
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -0,0 +1,20 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://www.google.com/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 0
13
+ message:
14
+ headers: {}
15
+ body:
16
+ encoding: UTF-8
17
+ string: ''
18
+ http_version:
19
+ recorded_at: Tue, 07 Apr 2015 13:45:55 GMT
20
+ recorded_with: VCR 2.9.3
@@ -16,11 +16,34 @@ RSpec.describe Muxer::Multiplexer do
16
16
  it 'lets a request wait on the longer one' do
17
17
  VCR.use_cassette('muxer/multiplexer/with_one_timeout') do
18
18
  multiplexer.add_url('https://github.com/', 0.0001)
19
- multiplexer.add_url('https://github.com/', 2)
19
+ multiplexer.add_url('https://codeclimate.com/', 2)
20
20
  response = multiplexer.execute
21
21
 
22
22
  expect(response[:succeeded].count).to eq(2)
23
23
  expect(response[:failed].count).to eq(0)
24
24
  end
25
25
  end
26
+
27
+ it 'kills requests with a global timeout' do
28
+ VCR.use_cassette('muxer/multiplexer/with_a_global_timeout') do
29
+ multiplexer.add_url('https://github.com/')
30
+ multiplexer.timeout = 0.0001
31
+ response = multiplexer.execute
32
+
33
+ expect(response[:succeeded].count).to eq(0)
34
+ expect(response[:failed].count).to eq(1)
35
+ end
36
+ end
37
+
38
+ it 'kills one of two requests with a global timeout' do
39
+ VCR.use_cassette('muxer/multiplexer/with_global_timeout') do
40
+ multiplexer.add_url('https://github.com/')
41
+ multiplexer.add_url('https://www.google.com/')
42
+ multiplexer.timeout = 0.2
43
+ response = multiplexer.execute
44
+
45
+ expect(response[:succeeded].count).to eq(1)
46
+ expect(response[:failed].count).to eq(1)
47
+ end
48
+ end
26
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muxer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris MacNaughton
@@ -159,6 +159,7 @@ files:
159
159
  - spec/cassettes/muxer/can_have_a_request_fail.yml
160
160
  - spec/cassettes/muxer/makes_a_web_request.yml
161
161
  - spec/cassettes/muxer/makes_multiple_web_requests.yml
162
+ - spec/cassettes/muxer/multiplexer/with_global_timeout.yml
162
163
  - spec/muxer/multiplexer_spec.rb
163
164
  - spec/muxer/request_spec.rb
164
165
  - spec/muxer_spec.rb
@@ -191,6 +192,7 @@ test_files:
191
192
  - spec/cassettes/muxer/can_have_a_request_fail.yml
192
193
  - spec/cassettes/muxer/makes_a_web_request.yml
193
194
  - spec/cassettes/muxer/makes_multiple_web_requests.yml
195
+ - spec/cassettes/muxer/multiplexer/with_global_timeout.yml
194
196
  - spec/muxer/multiplexer_spec.rb
195
197
  - spec/muxer/request_spec.rb
196
198
  - spec/muxer_spec.rb