infopark-politics 0.2.11 → 0.2.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -158,7 +158,11 @@ module Politics
158
158
  end
159
159
 
160
160
  def next_bucket(requestor_uri)
161
- [@buckets.pop, until_next_iteration]
161
+ [@buckets.pop, sleep_until_next_bucket_time]
162
+ end
163
+
164
+ def sleep_until_next_bucket_time
165
+ [[until_next_iteration / 2, 1].max, iteration_length / 2].min
162
166
  end
163
167
 
164
168
  def until_next_iteration
@@ -224,4 +224,32 @@ describe Worker do
224
224
  @worker.until_next_iteration.should == 6
225
225
  end
226
226
  end
227
+
228
+ describe "when creating next bucket" do
229
+ it "should set the sleep time to sleep_until_next_bucket_time" do
230
+ @worker.should_receive(:sleep_until_next_bucket_time).and_return 'the sleep time'
231
+ @worker.next_bucket('')[1].should == 'the sleep time'
232
+ end
233
+ end
234
+
235
+ describe "when computing the sleep_until_next_bucket_time" do
236
+ before do
237
+ @worker.stub!(:iteration_length).and_return 10
238
+ @worker.stub!(:until_next_iteration).and_return 6
239
+ end
240
+
241
+ it "should set the sleep time to half the time until_next_iteration" do
242
+ @worker.sleep_until_next_bucket_time.should == 3
243
+ end
244
+
245
+ it "should set the sleep time to at least 1 second" do
246
+ @worker.stub!(:until_next_iteration).and_return 0.6
247
+ @worker.sleep_until_next_bucket_time.should == 1
248
+ end
249
+
250
+ it "should set the sleep time to at most a half of the interation_length" do
251
+ @worker.stub!(:until_next_iteration).and_return 60
252
+ @worker.sleep_until_next_bucket_time.should == 5
253
+ end
254
+ end
227
255
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark-politics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Perham
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-06-29 00:00:00 -07:00
13
+ date: 2009-07-01 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency