carbon 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 2.0.2 / 2012-03-13
2
+
3
+ * Bug fixes
4
+
5
+ * Don't hang up on Carbon.multi if 0 queries are passed
6
+
1
7
  2.0.1 / 2012-03-12
2
8
 
3
9
  * Bug fixes
@@ -81,6 +81,7 @@ module Carbon
81
81
  # ]
82
82
  # Carbon.multi(queries)
83
83
  def self.multi(queries)
84
+ return [] if queries.empty?
84
85
  require 'em-http-request'
85
86
  unsorted = {}
86
87
  multi = ::EventMachine::MultiRequest.new
@@ -1,3 +1,3 @@
1
1
  module Carbon
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
@@ -91,55 +91,56 @@ describe Carbon do
91
91
  end
92
92
  end
93
93
  end
94
- unless ENV['SKIP_MULTI'] == 'true'
95
- describe :multi do
96
- before do
97
- @queries = []
98
- 10.times do
99
- @queries << ['Flight', {:origin_airport => 'LAX', :destination_airport => 'SFO', :segments_per_trip => 1, :trips => 1}]
100
- @queries << ['RailTrip', {:distance => 25}]
101
- @queries << ['AutomobileTrip', {:make => 'Nissan', :model => 'Altima'}]
102
- @queries << ['Residence']
103
- @queries << ['Monkey']
104
- end
105
- @queries = @queries.sort_by { rand }
94
+ describe :multi do
95
+ before do
96
+ @queries = []
97
+ 3.times do
98
+ @queries << ['Flight', {:origin_airport => 'LAX', :destination_airport => 'SFO', :segments_per_trip => 1, :trips => 1}]
99
+ @queries << ['RailTrip', {:distance => 25}]
100
+ @queries << ['AutomobileTrip', {:make => 'Nissan', :model => 'Altima'}]
101
+ @queries << ['Residence']
102
+ @queries << ['Monkey']
106
103
  end
107
- it "runs multiple queries at once" do
108
- responses = Carbon.multi(@queries)
109
- error_count = 0
110
- responses.each do |response|
111
- if response.success
112
- response.decisions.carbon.object.value.must_be :>, 0
113
- response.decisions.carbon.object.value.must_be :<, 10_000
114
- else
115
- error_count += 1
116
- end
104
+ @queries = @queries.sort_by { rand }
105
+ end
106
+ it "doesn't hang up on 0 queries" do
107
+ Timeout.timeout(0.5) { Carbon.multi([]) }.must_equal []
108
+ end
109
+ it "runs multiple queries at once" do
110
+ responses = Carbon.multi(@queries)
111
+ error_count = 0
112
+ responses.each do |response|
113
+ if response.success
114
+ response.decisions.carbon.object.value.must_be :>, 0
115
+ response.decisions.carbon.object.value.must_be :<, 10_000
116
+ else
117
+ error_count += 1
117
118
  end
118
- error_count.must_equal 10
119
- @queries.each_with_index do |query, i|
120
- reference_response = Carbon.query(*query)
121
- if reference_response.success
122
- responses[i].decisions.must_equal reference_response.decisions
123
- end
119
+ end
120
+ error_count.must_equal 3
121
+ @queries.each_with_index do |query, i|
122
+ reference_response = Carbon.query(*query)
123
+ if reference_response.success
124
+ responses[i].decisions.must_equal reference_response.decisions
124
125
  end
125
126
  end
126
- it "is faster than just calling #query over and over" do
127
- # dry run
127
+ end
128
+ it "is faster than just calling #query over and over" do
129
+ # dry run
130
+ @queries.each { |query| Carbon.query(*query) }
131
+ # --
132
+ single_threaded_time = ::Benchmark.realtime do
128
133
  @queries.each { |query| Carbon.query(*query) }
129
- # --
130
- single_threaded_time = ::Benchmark.realtime do
131
- @queries.each { |query| Carbon.query(*query) }
132
- end
133
- multi_threaded_time = ::Benchmark.realtime do
134
- Carbon.multi(@queries)
135
- end
136
- # Carbon::#multi
137
- # PASS test_0001_runs_multiple_queries_at_once (12.10s)
138
- # Multi-threaded was 95% faster
139
- # PASS test_0002_is_faster_than_just_calling_query_over_and_over (23.73s)
140
- $stderr.puts " Multi-threaded was #{((single_threaded_time - multi_threaded_time) / single_threaded_time * 100).round}% faster"
141
- multi_threaded_time.must_be :<, single_threaded_time
142
134
  end
135
+ multi_threaded_time = ::Benchmark.realtime do
136
+ Carbon.multi(@queries)
137
+ end
138
+ # Carbon::#multi
139
+ # PASS test_0001_runs_multiple_queries_at_once (12.10s)
140
+ # Multi-threaded was 95% faster
141
+ # PASS test_0002_is_faster_than_just_calling_query_over_and_over (23.73s)
142
+ $stderr.puts " Multi-threaded was #{((single_threaded_time - multi_threaded_time) / single_threaded_time * 100).round}% faster"
143
+ multi_threaded_time.must_be :<, single_threaded_time
143
144
  end
144
145
  end
145
146
  describe "mixin" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carbon
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: em-http-request
16
- requirement: &2153238540 !ruby/object:Gem::Requirement
16
+ requirement: &2153871340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153238540
24
+ version_requirements: *2153871340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &2153260780 !ruby/object:Gem::Requirement
27
+ requirement: &2153870880 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2153260780
35
+ version_requirements: *2153870880
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: multi_json
38
- requirement: &2153260300 !ruby/object:Gem::Requirement
38
+ requirement: &2153870440 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2153260300
46
+ version_requirements: *2153870440
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: hashie
49
- requirement: &2153259860 !ruby/object:Gem::Requirement
49
+ requirement: &2153869980 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2153259860
57
+ version_requirements: *2153869980
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bombshell
60
- requirement: &2153259340 !ruby/object:Gem::Requirement
60
+ requirement: &2153869540 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *2153259340
68
+ version_requirements: *2153869540
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: conversions
71
- requirement: &2153258840 !ruby/object:Gem::Requirement
71
+ requirement: &2153869080 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *2153258840
79
+ version_requirements: *2153869080
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: brighter_planet_metadata
82
- requirement: &2153258380 !ruby/object:Gem::Requirement
82
+ requirement: &2153868640 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *2153258380
90
+ version_requirements: *2153868640
91
91
  description: Brighter Planet API client for Ruby
92
92
  email:
93
93
  - seamus@abshere.net