zk 1.9.6 → 1.10.0

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.
Files changed (40) hide show
  1. checksums.yaml +5 -13
  2. data/.github/workflows/build.yml +55 -0
  3. data/Gemfile +15 -6
  4. data/README.markdown +9 -9
  5. data/RELEASES.markdown +10 -1
  6. data/lib/zk/client.rb +1 -1
  7. data/lib/zk/event_handler.rb +15 -7
  8. data/lib/zk/fork_hook.rb +2 -2
  9. data/lib/zk/locker/locker_base.rb +13 -0
  10. data/lib/zk/locker/semaphore.rb +1 -3
  11. data/lib/zk/node_deletion_watcher.rb +3 -4
  12. data/lib/zk/pool.rb +11 -11
  13. data/lib/zk/version.rb +1 -1
  14. data/spec/event_catcher_spec.rb +1 -1
  15. data/spec/message_queue_spec.rb +6 -6
  16. data/spec/shared/client_examples.rb +81 -81
  17. data/spec/shared/locker_examples.rb +13 -13
  18. data/spec/spec_helper.rb +10 -11
  19. data/spec/zk/00_forked_client_integration_spec.rb +3 -3
  20. data/spec/zk/client/locking_and_session_death_spec.rb +2 -2
  21. data/spec/zk/client_spec.rb +19 -19
  22. data/spec/zk/election_spec.rb +44 -44
  23. data/spec/zk/extensions_spec.rb +2 -2
  24. data/spec/zk/locker/exclusive_locker_spec.rb +41 -41
  25. data/spec/zk/locker/locker_basic_spec.rb +55 -33
  26. data/spec/zk/locker/semaphore_spec.rb +39 -32
  27. data/spec/zk/locker/shared_exclusive_integration_spec.rb +37 -37
  28. data/spec/zk/locker/shared_locker_spec.rb +43 -43
  29. data/spec/zk/locker_spec.rb +2 -2
  30. data/spec/zk/module_spec.rb +25 -25
  31. data/spec/zk/mongoid_spec.rb +47 -47
  32. data/spec/zk/node_deletion_watcher_spec.rb +39 -31
  33. data/spec/zk/pool_spec.rb +56 -65
  34. data/spec/zk/threaded_callback_spec.rb +10 -10
  35. data/spec/zk/threadpool_spec.rb +25 -25
  36. data/spec/zk/watch_spec.rb +67 -79
  37. data/spec/zk/zookeeper_spec.rb +31 -31
  38. data/zk.gemspec +1 -1
  39. metadata +23 -24
  40. data/.travis.yml +0 -30
@@ -6,29 +6,29 @@ shared_examples_for 'client' do
6
6
  @path_ary = %W[#{base} test mkdir_p path creation]
7
7
  @bogus_path = File.join('', *@path_ary)
8
8
  end
9
-
9
+
10
10
  it %[should create all intermediate paths for the path givem] do
11
- @zk.should_not be_exists(@bogus_path)
12
- @zk.should_not be_exists(File.dirname(@bogus_path))
11
+ expect(@zk.exists?(@bogus_path)).to be(false)
12
+ expect(@zk.exists?(File.dirname(@bogus_path))).to be(false)
13
13
  @zk.mkdir_p(@bogus_path)
14
- @zk.should be_exists(@bogus_path)
14
+ expect(@zk.exists?(@bogus_path)).to be(true)
15
15
  end
16
16
 
17
17
  it %[should place the data only at the leaf node] do
18
18
  @zk.mkdir_p(@bogus_path, :data => 'foobar')
19
- @zk.get(@bogus_path).first.should == 'foobar'
19
+ expect(@zk.get(@bogus_path).first).to eq('foobar')
20
20
 
21
21
  path = ''
22
22
  @path_ary[0..-2].each do |el|
23
23
  path = File.join(path, el)
24
- @zk.get(path).first.should == ''
24
+ expect(@zk.get(path).first).to eq('')
25
25
  end
26
26
  end
27
27
 
28
28
  it %[should replace the data at the leaf node if it already exists] do
29
29
  @zk.mkdir_p(@bogus_path, :data => 'blahfoo')
30
30
  @zk.mkdir_p(@bogus_path, :data => 'foodink')
31
- @zk.get(@bogus_path).first.should == 'foodink'
31
+ expect(@zk.get(@bogus_path).first).to eq('foodink')
32
32
  end
33
33
  end
34
34
 
@@ -37,14 +37,14 @@ shared_examples_for 'client' do
37
37
  describe 'only path given' do
38
38
  it %[should create a node with blank data] do
39
39
  @zk.create(@base_path)
40
- @zk.get(@base_path).first.should == ''
40
+ expect(@zk.get(@base_path).first).to eq('')
41
41
  end
42
42
  end
43
43
 
44
44
  describe 'path and data given' do
45
45
  it %[should create a node with the path and data] do
46
46
  @zk.create(@base_path, 'blah')
47
- @zk.get(@base_path).first.should == 'blah'
47
+ expect(@zk.get(@base_path).first).to eq('blah')
48
48
  end
49
49
  end
50
50
 
@@ -52,37 +52,37 @@ shared_examples_for 'client' do
52
52
  it %[should create a sequential node with blank data] do
53
53
  @zk.create(@base_path)
54
54
  path = @zk.create("#{@base_path}/v", :sequential => true)
55
- path.start_with?(@base_path).should be_true
55
+ expect(path.start_with?(@base_path)).to be(true)
56
56
 
57
- File.basename(path).should match(/v\d+/)
57
+ expect(File.basename(path)).to match(/v\d+/)
58
58
 
59
- @zk.get(path).first.should == ''
59
+ expect(@zk.get(path).first).to eq('')
60
60
  end
61
61
 
62
62
  it %[should create a sequential node with given data] do
63
63
  @zk.create(@base_path)
64
64
  path = @zk.create("#{@base_path}/v", 'thedata', :sequential => true)
65
- path.start_with?(@base_path).should be_true
65
+ expect(path.start_with?(@base_path)).to be(true)
66
66
 
67
- File.basename(path).should match(/v\d+/)
67
+ expect(File.basename(path)).to match(/v\d+/)
68
68
 
69
69
  data, st = @zk.get(path)
70
- data.should == 'thedata'
71
- st.should_not be_ephemeral
70
+ expect(data).to eq('thedata')
71
+ expect(st).not_to be_ephemeral
72
72
  end
73
73
  end
74
74
 
75
75
  describe 'path and ephemeral' do
76
76
  it %[should create an ephemeral node with blank data] do
77
77
  @zk.create(@base_path, :ephemeral => true)
78
- @zk.get(@base_path).last.should be_ephemeral
78
+ expect(@zk.get(@base_path).last).to be_ephemeral
79
79
  end
80
80
 
81
81
  it %[should create an ephemeral node with given data] do
82
82
  @zk.create(@base_path, 'thedata', :ephemeral => true)
83
83
  data, stat = @zk.get(@base_path)
84
- data.should == 'thedata'
85
- stat.should be_ephemeral
84
+ expect(data).to eq('thedata')
85
+ expect(stat).to be_ephemeral
86
86
  end
87
87
  end
88
88
 
@@ -90,45 +90,45 @@ shared_examples_for 'client' do
90
90
  it %[should create a sequential ephemeral node with blank data] do
91
91
  @zk.create(@base_path)
92
92
  path = @zk.create("#{@base_path}/v", :sequential => true, :ephemeral => true)
93
- path.start_with?(@base_path).should be_true
93
+ expect(path.start_with?(@base_path)).to be(true)
94
94
 
95
- File.basename(path).should match(/v\d+/)
95
+ expect(File.basename(path)).to match(/v\d+/)
96
96
 
97
97
  data, st = @zk.get(path)
98
- data.should == ''
99
- st.should be_ephemeral
98
+ expect(data).to eq('')
99
+ expect(st).to be_ephemeral
100
100
  end
101
101
 
102
102
  it %[should create a sequential ephemeral node with given data] do
103
103
  @zk.create(@base_path)
104
104
  path = @zk.create("#{@base_path}/v", 'thedata', :sequential => true, :ephemeral => true)
105
- path.start_with?(@base_path).should be_true
105
+ expect(path.start_with?(@base_path)).to be(true)
106
106
 
107
- File.basename(path).should match(/v\d+/)
107
+ expect(File.basename(path)).to match(/v\d+/)
108
108
 
109
109
  data, st = @zk.get(path)
110
- data.should == 'thedata'
111
- st.should be_ephemeral
110
+ expect(data).to eq('thedata')
111
+ expect(st).to be_ephemeral
112
112
  end
113
113
  end
114
114
 
115
115
  it %[should barf if someone hands 3 params] do
116
- lambda { @zk.create(@base_path, 'data', :sequence) }.should raise_error(ArgumentError)
116
+ expect { @zk.create(@base_path, 'data', :sequence) }.to raise_error(ArgumentError)
117
117
  end
118
118
 
119
119
  it %[should barf if both :sequence and :sequential are given] do
120
- lambda { @zk.create(@base_path, 'data', :sequence => true, :sequential => true) }.should raise_error(ArgumentError)
120
+ expect { @zk.create(@base_path, 'data', :sequence => true, :sequential => true) }.to raise_error(ArgumentError)
121
121
  end
122
122
 
123
123
  describe %[:ignore option] do
124
124
  it %[should squelch node_exists] do
125
125
  @zk.create(@base_path)
126
126
 
127
- proc { @zk.create(@base_path, :ignore => :node_exists).should be_nil }.should_not raise_error(ZK::Exceptions::NoNode)
127
+ expect { expect(@zk.create(@base_path, :ignore => :node_exists)).to be_nil }.not_to raise_error
128
128
  end
129
129
 
130
130
  it %[should squelch no_node] do
131
- proc { @zk.create("#{@base_path}/foo/bar/baz", :ignore => :no_node).should be_nil }.should_not raise_error(ZK::Exceptions::NoNode)
131
+ expect { expect(@zk.create("#{@base_path}/foo/bar/baz", :ignore => :no_node)).to be_nil }.not_to raise_error
132
132
  end
133
133
  end
134
134
 
@@ -136,11 +136,11 @@ shared_examples_for 'client' do
136
136
  let(:path) { "#{@base_path}/foo/bar" }
137
137
 
138
138
  it %[should barf if anything but the the :set value is given] do
139
- proc { @zk.create(path, :or => :GFY) }.should raise_error(ArgumentError)
139
+ expect { @zk.create(path, :or => :GFY) }.to raise_error(ArgumentError)
140
140
  end
141
141
 
142
142
  def create_args(opts={})
143
- proc do
143
+ proc do
144
144
  begin
145
145
  @zk.create(path, opts.merge(:or => :set))
146
146
  ensure
@@ -150,24 +150,24 @@ shared_examples_for 'client' do
150
150
  end
151
151
 
152
152
  it %[should barf if any node option besides 'persistent' is given] do
153
- create_args(:persistent => true).should_not raise_error
154
- create_args(:sequential => true).should raise_error(ArgumentError)
155
- create_args(:mode => :ephemeral).should raise_error(ArgumentError)
156
- create_args(:mode => :ephemeral_sequential).should raise_error(ArgumentError)
157
- create_args(:mode => :sequential).should raise_error(ArgumentError)
153
+ expect(create_args(:persistent => true)).not_to raise_error
154
+ expect(create_args(:sequential => true)).to raise_error(ArgumentError)
155
+ expect(create_args(:mode => :ephemeral)).to raise_error(ArgumentError)
156
+ expect(create_args(:mode => :ephemeral_sequential)).to raise_error(ArgumentError)
157
+ expect(create_args(:mode => :sequential)).to raise_error(ArgumentError)
158
158
  end
159
159
 
160
160
  it %[should replace the data at the leaf node if it already exists] do
161
161
  @zk.mkdir_p(path, :data => 'foodink')
162
162
  @zk.create(path, 'blahfoo', :or => :set)
163
- @zk.get(path).first.should == 'blahfoo'
163
+ expect(@zk.get(path).first).to eq('blahfoo')
164
164
  end
165
165
 
166
166
  it %[should create the intermediate paths] do
167
- proc { @zk.create(path, 'foobar', :or => :set) }.should_not raise_error
167
+ expect { @zk.create(path, 'foobar', :or => :set) }.not_to raise_error
168
168
 
169
- @zk.stat(@base_path).should exist
170
- @zk.stat("#{@base_path}/foo").should exist
169
+ expect(@zk.stat(@base_path)).to exist
170
+ expect(@zk.stat("#{@base_path}/foo")).to exist
171
171
  end
172
172
  end
173
173
  end
@@ -178,16 +178,16 @@ shared_examples_for 'client' do
178
178
  @zk.create(@base_path)
179
179
  @zk.create("#{@base_path}/blah")
180
180
 
181
- proc { @zk.delete(@base_path, :ignore => :not_empty).should be_nil }.should_not raise_error
181
+ expect { expect(@zk.delete(@base_path, :ignore => :not_empty)).to be_nil }.not_to raise_error
182
182
  end
183
183
 
184
184
  it %[should squelch no_node] do
185
- proc { @zk.delete("#{@base_path}/foo/bar/baz", :ignore => :no_node).should be_nil }.should_not raise_error
185
+ expect { expect(@zk.delete("#{@base_path}/foo/bar/baz", :ignore => :no_node)).to be_nil }.not_to raise_error
186
186
  end
187
187
 
188
188
  it %[should squelch bad_version] do
189
189
  @zk.create(@base_path)
190
- proc { @zk.delete("#{@base_path}", :version => 7, :ignore => :bad_version).should be_nil }.should_not raise_error
190
+ expect { expect(@zk.delete("#{@base_path}", :version => 7, :ignore => :bad_version)).to be_nil }.not_to raise_error
191
191
  end
192
192
  end
193
193
  end
@@ -197,21 +197,21 @@ shared_examples_for 'client' do
197
197
  before do
198
198
  @missing_path = '/thispathdoesnotexist'
199
199
  begin
200
- @zk.delete(@missing_path)
200
+ @zk.delete(@missing_path)
201
201
  rescue ZK::Exceptions::NoNode
202
202
  end
203
203
  end
204
204
 
205
205
  it %[should not raise any error] do
206
- lambda { @zk.stat(@missing_path) }.should_not raise_error
206
+ expect { @zk.stat(@missing_path) }.not_to raise_error
207
207
  end
208
208
 
209
209
  it %[should return a Stat object] do
210
- @zk.stat(@missing_path).should be_kind_of(Zookeeper::Stat)
210
+ expect(@zk.stat(@missing_path)).to be_kind_of(Zookeeper::Stat)
211
211
  end
212
212
 
213
213
  it %[should return a stat that not exists?] do
214
- @zk.stat(@missing_path).should_not be_exists
214
+ expect(@zk.stat(@missing_path)).not_to be_exists
215
215
  end
216
216
  end
217
217
  end
@@ -219,12 +219,12 @@ shared_examples_for 'client' do
219
219
  describe :set do
220
220
  describe %[:ignore option] do
221
221
  it %[should squelch no_node] do
222
- proc { @zk.set("#{@base_path}/foo/bar/baz", '', :ignore => :no_node).should be_nil }.should_not raise_error
222
+ expect { expect(@zk.set("#{@base_path}/foo/bar/baz", '', :ignore => :no_node)).to be_nil }.not_to raise_error
223
223
  end
224
224
 
225
225
  it %[should squelch bad_version] do
226
226
  @zk.create(@base_path)
227
- proc { @zk.set("#{@base_path}", '', :version => 7, :ignore => :bad_version).should be_nil }.should_not raise_error
227
+ expect { expect(@zk.set("#{@base_path}", '', :version => 7, :ignore => :bad_version)).to be_nil }.not_to raise_error
228
228
  end
229
229
  end
230
230
  end
@@ -236,7 +236,7 @@ shared_examples_for 'client' do
236
236
 
237
237
  describe 'no node initially' do
238
238
  before do
239
- @zk.exists?(@path).should be_false
239
+ expect(@zk.exists?(@path)).to be(false)
240
240
  end
241
241
 
242
242
  it %[should not block] do
@@ -248,42 +248,42 @@ shared_examples_for 'client' do
248
248
  end
249
249
 
250
250
  th.join(2)
251
- @a.should be_true
251
+ expect(@a).to be(true)
252
252
  end
253
253
  end
254
254
 
255
255
  describe 'node exists initially' do
256
256
  before do
257
257
  @zk.create(@path, :mode => :ephemeral)
258
- @zk.exists?(@path).should be_true
258
+ expect(@zk.exists?(@path)).to be(true)
259
259
  end
260
260
 
261
261
  it %[should block until the node is deleted] do
262
262
  @a = false
263
263
 
264
- th = Thread.new do
264
+ Thread.new do
265
265
  @zk.block_until_node_deleted(@path)
266
266
  @a = true
267
267
  end
268
268
 
269
269
  Thread.pass
270
- @a.should be_false
270
+ expect(@a).to be(false)
271
271
 
272
272
  @zk.delete(@path)
273
273
 
274
274
  wait_until(2) { @a }
275
- @a.should be_true
275
+ expect(@a).to be(true)
276
276
  end
277
277
  end
278
278
  end
279
279
 
280
280
  describe 'session_id and session_passwd' do
281
281
  it %[should expose the underlying session_id] do
282
- @zk.session_id.should be_kind_of(Integer)
282
+ expect(@zk.session_id).to be_kind_of(Integer)
283
283
  end
284
284
 
285
285
  it %[should expose the underlying session_passwd] do
286
- @zk.session_passwd.should be_kind_of(String)
286
+ expect(@zk.session_passwd).to be_kind_of(String)
287
287
  end
288
288
  end
289
289
 
@@ -296,22 +296,22 @@ shared_examples_for 'client' do
296
296
  end
297
297
 
298
298
  # after do
299
- # logger.info { "AFTER EACH" }
299
+ # logger.info { "AFTER EACH" }
300
300
  # @zk.delete(@path)
301
301
  # end
302
302
 
303
303
  def ensure_event_delivery!
304
304
  @sub ||= @zk.event_handler.register(@path) do |event|
305
- logger.debug { "got event: #{event.inspect}" }
305
+ logger.debug { "got event: #{event.inspect}" }
306
306
  @queue << event
307
307
  end
308
308
 
309
- @zk.exists?(@path, :watch => true).should be_false
309
+ expect(@zk.exists?(@path, :watch => true)).to be(false)
310
310
  @zk.create(@path)
311
311
 
312
- logger.debug { "waiting for event delivery" }
312
+ logger.debug { "waiting for event delivery" }
313
313
 
314
- wait_until(2) do
314
+ wait_until(2) do
315
315
  begin
316
316
  event = @queue.pop(true)
317
317
  logger.debug { "got event: #{event}" }
@@ -323,7 +323,7 @@ shared_examples_for 'client' do
323
323
  end
324
324
 
325
325
  # first watch delivered correctly
326
- @events.length.should > 0
326
+ expect(@events.length).to be > 0
327
327
  end
328
328
 
329
329
  it %[should fire re-registered watchers after reopen (#9)] do
@@ -357,14 +357,14 @@ shared_examples_for 'client' do
357
357
  # note: we can't trust the events to be delivered in any particular order
358
358
  # since they're happening on two different threads. if we see we're connected
359
359
  # in the beginning, that there was a disconnection, then a reopen, that's
360
- # probably fine.
360
+ # probably fine.
361
361
  #
362
362
  # we also check that the session_id was changed, which is the desired effect
363
363
 
364
364
  orig_session_id = @zk.session_id
365
- @zk.should be_connected
365
+ expect(@zk).to be_connected
366
366
 
367
- props = {
367
+ props = {
368
368
  :session_event? => true,
369
369
  :node_event? => false,
370
370
  :client_invalid? => true,
@@ -372,8 +372,8 @@ shared_examples_for 'client' do
372
372
  :state => Zookeeper::ZOO_EXPIRED_SESSION_STATE,
373
373
  }
374
374
 
375
- bogus_event = flexmock(:expired_session_event, props)
376
- bogus_event.should_receive(:zk=).with(@zk).once
375
+ bogus_event = instance_double(Zookeeper::Callbacks::WatcherCallback, props)
376
+ expect(bogus_event).to receive(:zk=).with(@zk).once
377
377
 
378
378
  mutex = Monitor.new
379
379
  cond = mutex.new_cond
@@ -388,20 +388,20 @@ shared_examples_for 'client' do
388
388
  end
389
389
 
390
390
  mutex.synchronize do
391
- events.should be_empty
391
+ expect(events).to be_empty
392
392
  @zk.event_handler.process(bogus_event)
393
393
  end
394
394
 
395
- logger.debug { "events: #{events.inspect}" }
395
+ logger.debug { "events: #{events.inspect}" }
396
396
 
397
397
  mutex.synchronize do
398
398
  time_to_stop = Time.now + 2
399
399
  cond.wait_while { (events.length < 2 ) && (Time.now < time_to_stop) }
400
400
  end
401
401
 
402
- events.should include(Zookeeper::ZOO_EXPIRED_SESSION_STATE)
403
- events.should include(Zookeeper::ZOO_CONNECTED_STATE)
404
- @zk.session_id.should_not == orig_session_id
402
+ expect(events).to include(Zookeeper::ZOO_EXPIRED_SESSION_STATE)
403
+ expect(events).to include(Zookeeper::ZOO_CONNECTED_STATE)
404
+ expect(@zk.session_id).not_to eq(orig_session_id)
405
405
  end
406
406
  end # reconnection
407
407
 
@@ -410,17 +410,17 @@ shared_examples_for 'client' do
410
410
  @ary = []
411
411
 
412
412
  @zk.on_exception { |exc| @ary << exc }
413
-
413
+
414
414
  @zk.defer { raise "ZOMG!" }
415
415
 
416
416
  wait_while(2) { @ary.empty? }
417
417
 
418
- @ary.length.should == 1
418
+ expect(@ary.length).to eq(1)
419
419
 
420
420
  e = @ary.shift
421
421
 
422
- e.should be_kind_of(RuntimeError)
423
- e.message.should == 'ZOMG!'
422
+ expect(e).to be_kind_of(RuntimeError)
423
+ expect(e.message).to eq('ZOMG!')
424
424
  end
425
425
  end
426
426
 
@@ -431,8 +431,8 @@ shared_examples_for 'client' do
431
431
  @zk.defer { @ary << @zk.on_threadpool? }
432
432
 
433
433
  wait_while(2) { @ary.empty? }
434
- @ary.length.should == 1
435
- @ary.first.should be_true
434
+ expect(@ary.length).to eq(1)
435
+ expect(@ary.first).to be(true)
436
436
  end
437
437
  end
438
438
  end
@@ -6,50 +6,50 @@
6
6
  shared_examples_for 'LockerBase#assert!' do
7
7
  it %[should raise LockAssertionFailedError if its connection is no longer connected?] do
8
8
  zk.close!
9
- lambda { locker.assert! }.should raise_error(ZK::Exceptions::LockAssertionFailedError)
9
+ expect { locker.assert! }.to raise_error(ZK::Exceptions::LockAssertionFailedError)
10
10
  end
11
11
 
12
12
  it %[should raise LockAssertionFailedError if locked? is false] do
13
- locker.should_not be_locked
14
- lambda { locker.assert! }.should raise_error(ZK::Exceptions::LockAssertionFailedError)
13
+ expect(locker).not_to be_locked
14
+ expect { locker.assert! }.to raise_error(ZK::Exceptions::LockAssertionFailedError)
15
15
  end
16
16
 
17
17
  it %[should raise LockAssertionFailedError lock_path does not exist] do
18
18
  locker.lock
19
- lambda { locker.assert! }.should_not raise_error
19
+ expect { locker.assert! }.not_to raise_error
20
20
 
21
21
  zk.delete(locker.lock_path)
22
- lambda { locker.assert! }.should raise_error(ZK::Exceptions::LockAssertionFailedError)
22
+ expect { locker.assert! }.to raise_error(ZK::Exceptions::LockAssertionFailedError)
23
23
  end
24
24
 
25
25
  it %[should raise LockAssertionFailedError if our parent node's ctime is different than what we think it should be] do
26
- locker.lock.should be_true
26
+ expect(locker.lock).to be(true)
27
27
 
28
28
  zk.rm_rf(File.dirname(locker.lock_path)) # remove the parent node
29
29
  zk.mkdir_p(locker.lock_path)
30
30
 
31
- lambda { locker.assert! }.should raise_error(ZK::Exceptions::LockAssertionFailedError)
31
+ expect { locker.assert! }.to raise_error(ZK::Exceptions::LockAssertionFailedError)
32
32
  end
33
33
  end
34
34
 
35
35
  shared_examples_for 'LockerBase#unlock' do
36
36
  it %[should not delete a lock path it does not own] do
37
- locker.lock.should be_true
37
+ expect(locker.lock).to be(true)
38
38
 
39
39
  zk.rm_rf(File.dirname(locker.lock_path)) # remove the parent node
40
40
  zk.mkdir_p(File.dirname(locker.lock_path))
41
41
 
42
- locker2.lock.should be_true
42
+ expect(locker2.lock).to be(true)
43
43
 
44
- locker2.lock_path.should == locker.lock_path
44
+ expect(locker2.lock_path).to eq(locker.lock_path)
45
45
 
46
- lambda { locker2.assert! }.should_not raise_error
46
+ expect { locker2.assert! }.not_to raise_error
47
47
 
48
48
  lock_path = locker.lock_path
49
49
 
50
- locker.unlock.should be_false
50
+ expect(locker.unlock).to be(false)
51
51
 
52
- zk.stat(lock_path).should exist
52
+ expect(zk.stat(lock_path)).to exist
53
53
  end
54
54
  end
55
55
 
data/spec/spec_helper.rb CHANGED
@@ -9,11 +9,11 @@ if File.exists?(release_ops_path)
9
9
  ReleaseOps::SimpleCov.maybe_start
10
10
  end
11
11
 
12
-
13
12
  Bundler.require(:development, :test)
14
13
 
15
14
  require 'zk'
16
15
  require 'benchmark'
16
+ require 'pry'
17
17
 
18
18
  # Requires supporting ruby files with custom matchers and macros, etc,
19
19
  # in spec/support/ and its subdirectories.
@@ -21,11 +21,10 @@ Dir[File.expand_path("../{support,shared}/**/*.rb", __FILE__)].sort.each {|f| re
21
21
 
22
22
  $stderr.sync = true
23
23
 
24
- require 'flexmock'
25
-
26
24
  RSpec.configure do |config|
27
- config.mock_with :flexmock
28
- config.include(FlexMock::ArgumentTypes)
25
+ config.expect_with :rspec do |c|
26
+ c.syntax = :expect
27
+ end
29
28
 
30
29
  [WaitWatchers, SpecGlobalLogger, Pendings].each do |mod|
31
30
  config.include(mod)
@@ -48,7 +47,7 @@ RSpec.configure do |config|
48
47
  if ZK.spawn_zookeeper?
49
48
  require 'zk-server'
50
49
 
51
- config.before(:suite) do
50
+ config.before(:suite) do
52
51
  SpecGlobalLogger.logger.debug { "Starting zookeeper service" }
53
52
  ZK::Server.run do |c|
54
53
  c.client_port = ZK.test_port
@@ -68,24 +67,24 @@ RSpec.configure do |config|
68
67
  count = 0
69
68
  ObjectSpace.each_object(klass) { |o| count += 1 if tester.call(o) }
70
69
  unless count.zero?
71
- raise "There were #{count} leaked #{klass} objects after #{example.full_description.inspect}"
70
+ raise "There were #{count} leaked #{klass} objects after #{example.full_description.inspect}"
72
71
  end
73
72
  end
74
73
 
75
74
  # these make tests run slow
76
75
  if ENV['ZK_LEAK_CHECK']
77
- config.after do
76
+ config.after do
78
77
  leak_check(ZK::Client::Threaded) { |o| !o.closed? }
79
78
  leak_check(ZK::ThreadedCallback, &:alive?)
80
79
  leak_check(ZK::Threadpool, &:alive?)
81
80
  leak_check(Thread) { |th| Thread.current != th && th.alive? }
82
- ZK::ForkHook.hooks.values.flatten.should be_empty
81
+ expect(ZK::ForkHook.hooks.values.flatten).to be_empty
83
82
  end
84
83
  end
85
84
  end
86
85
 
87
86
  class ::Thread
88
- # join with thread until given block is true, the thread joins successfully,
87
+ # join with thread until given block is true, the thread joins successfully,
89
88
  # or timeout seconds have passed
90
89
  #
91
90
  def join_until(timeout=2)
@@ -97,7 +96,7 @@ class ::Thread
97
96
  Thread.pass
98
97
  end
99
98
  end
100
-
99
+
101
100
  def join_while(timeout=2)
102
101
  time_to_stop = Time.now + timeout
103
102
 
@@ -23,9 +23,9 @@ describe 'forked client integration' do
23
23
  it %[should deliver callbacks in the child] do
24
24
  10.times do
25
25
  ClientForker.run(@cnx_args, @base_path) do |forker|
26
- forker.stat.should_not be_signaled
27
- forker.stat.should be_exited
28
- forker.stat.should be_success
26
+ expect(forker.stat).not_to be_signaled
27
+ expect(forker.stat).to be_exited
28
+ expect(forker.stat).to be_success
29
29
  end
30
30
  end
31
31
  end # should deliver callbacks in the child
@@ -42,9 +42,9 @@ shared_examples_for 'session death' do
42
42
  deliver_session_event_to(zoo_state, @other_zk)
43
43
 
44
44
  # ditto, this is probably happening synchrnously
45
- wait_until(2) { @a }.should be_true
45
+ expect(wait_until(2) { @a }).to be(true)
46
46
 
47
- lambda { th.join(2) }.should raise_error(zoo_error_class)
47
+ expect { th.join(2) }.to raise_error(zoo_error_class)
48
48
  end
49
49
  end # session death
50
50