infopark-politics 0.2.10 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -125,9 +125,9 @@ module Politics
125
125
  seize_leadership
126
126
  end
127
127
 
128
- def seize_leadership(duration = nil)
129
- @memcache_client.set(token, uri, duration || iteration_length)
130
- @nominated_at = Time.now
128
+ def seize_leadership(duration = iteration_length)
129
+ @memcache_client.set(token, uri, duration)
130
+ @nominated_at = Time.now + duration - iteration_length
131
131
  end
132
132
 
133
133
  def perform_leader_duties
@@ -181,4 +181,47 @@ describe Worker do
181
181
  end
182
182
  end
183
183
  end
184
+
185
+ describe "when seizing leadership" do
186
+ before do
187
+ @worker.stub!(:uri).and_return('myself')
188
+ @worker.stub!(:iteration_length).and_return 123
189
+ @worker.stub!(:token).and_return('dcc-group')
190
+ end
191
+
192
+ it "should set itself to leader" do
193
+ @@memcache_client.should_receive(:set).with(anything(), 'myself', anything())
194
+ @worker.seize_leadership
195
+ end
196
+
197
+ it "should seize the leadership for the amount of seconds given" do
198
+ @@memcache_client.should_receive(:set).with(anything(), anything(), 666)
199
+ @worker.seize_leadership 666
200
+ end
201
+
202
+ it "should seize the leadership for iteration_length if no duration is given" do
203
+ @@memcache_client.should_receive(:set).with(anything(), anything(), 123)
204
+ @worker.seize_leadership
205
+ end
206
+
207
+ it "should seize the leadership for the worker's group" do
208
+ @@memcache_client.should_receive(:set).with('dcc-group', anything(), anything())
209
+ @worker.seize_leadership
210
+ end
211
+
212
+ it "should have the next iteration exactly when the seized leadership ends" do
213
+ now = Time.now
214
+ Time.stub!(:now).and_return now
215
+ end_of_leadership = now + 666
216
+
217
+ @worker.seize_leadership 666
218
+ @worker.until_next_iteration.should == 666
219
+
220
+ @worker.seize_leadership
221
+ @worker.until_next_iteration.should == 123
222
+
223
+ @worker.seize_leadership 6
224
+ @worker.until_next_iteration.should == 6
225
+ end
226
+ end
184
227
  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.10
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Perham