redis-semaphore 0.2.2 → 0.2.3

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 (4) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +6 -1
  3. data/spec/semaphore_spec.rb +37 -37
  4. metadata +4 -3
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWYwZTRjNTdiNmMzYzM5MzIwNjQzNzViYTBiOWEyNTY5MmQ1MDRkYQ==
4
+ NmRjZDI2ZDcyOWE2MWM2ZjMwZDA4NjI4YmUwNjVhZjk2MzQ5OWU0Mg==
5
5
  data.tar.gz: !binary |-
6
- MjhkM2JiMDE2ZDQ5YmYzNmY3NmE0ZjViOTcxYjVjMDgxM2RmMjY3NQ==
6
+ Yjc5ZDg1MjM0MThkMTcyMDJiYjU5MThhY2JiOWExODdlMjZiMTVkYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjZlNWQzMzJiYmY4ZTM2NDdmNGNmZTY5OGM0MmU3NzQxYzkyY2UzMmQ0Y2Rj
10
- YjUzOGZhY2Q2ODA3ZGM5YzY0NTlhNTA4OGE3ZDlkODU1NDlmZGVkMWM5Mjg1
11
- MDgxZDE3NjNhNTllOGU3MTYxNTU0YjQyNWM2MjJmNDQ3MmQxYTY=
9
+ YmUxYmNjOWFhYTg3OGE4OWI2ZTZkMDM5OTcxMGI1OWY5MjcwZGY2M2ZmYzI3
10
+ N2RjMGFmMWQ3NmM2OTYyOGIyZTA2ZWJkMDc1MzlkYmU2MDc2YWUzOThhMDhm
11
+ YWUzNmY3MmU2MWM5YTBmY2UwYzFlOWIxNWRkMmJlZGVmMWJkZjQ=
12
12
  data.tar.gz: !binary |-
13
- MDQ4YTljMDAzNjRiZTI1YjI4ZjRlZDI4YmNjNzNjYjdlM2RlZWY1ZWRhOTQ2
14
- ZTUyMzIyNzhlYTJmMTU0NjQ0NjYyMGU4OGYwMzk2MDkxNmVlNWIyMTBlYmZj
15
- NjVjZGQ0NGI2ZmJlYTU0OWEzY2NkNWNlMDRjMGNhZTQ2MzJkYzk=
13
+ YzQzOTQ2ODJjMjJhYzI1MzJlZWQ5YjYxMTIyMjg5ZTgwZjk4N2M0N2I3OGQ4
14
+ ZGEwMTFhZDMyODU3NTEzY2I3OGI0Njk4YzI5ZTg1OTdjMTI1MmEzNDIyNWMw
15
+ NmZhOWUwZDg4NGJjZWZmZDNiYWIzNWI5YzkwMzQyOWZkZTFmMDI=
data/README.md CHANGED
@@ -111,7 +111,7 @@ normal_sem = Redis::Semaphore.new(:semaphore, :connection => "localhost")
111
111
 
112
112
  Thread.new do
113
113
  watchdog = Redis::Semaphore.new(:semaphore, :connection => "localhost", :stale_client_timeout => 5)
114
-
114
+
115
115
  while(true) do
116
116
  watchdog.release_stale_locks!
117
117
  sleep 1
@@ -189,6 +189,9 @@ Testing
189
189
  Changelog
190
190
  ---------
191
191
 
192
+ ###0.2.3 September 7, 2014
193
+ - Block-based locking return the value of the block (thanks frobcode!).
194
+
192
195
  ###0.2.2 June 16, 2014
193
196
  - Fixed bug in `all_tokens` (thanks presskey!).
194
197
  - Fixed bug in error message (thanks Dmitriy!).
@@ -243,3 +246,5 @@ Thanks to these awesome peeps for their contributions:
243
246
  - [dubdromic](https://github.com/dubdromic)
244
247
  - [Dmitriy Kiriyenko](https://github.com/dmitriy-kiriyenko)
245
248
  - [presskey](https://github.com/presskey)
249
+ - [Stephen Bussey](https://github.com/sb8244)
250
+ - [frobcode](https://github.com/frobcode)
@@ -18,56 +18,56 @@ describe "redis" do
18
18
 
19
19
  it "has the correct amount of available resources" do
20
20
  semaphore.lock
21
- semaphore.unlock.should == 1
22
- semaphore.available_count.should == 1
21
+ expect(semaphore.unlock).to eq(1)
22
+ expect(semaphore.available_count).to eq(1)
23
23
  end
24
24
 
25
25
  it "should not exist from the start" do
26
- semaphore.exists?.should == false
26
+ expect(semaphore.exists?).to eq(false)
27
27
  semaphore.lock
28
- semaphore.exists?.should == true
28
+ expect(semaphore.exists?).to eq(true)
29
29
  end
30
30
 
31
31
  it "should be unlocked from the start" do
32
- semaphore.locked?.should == false
32
+ expect(semaphore.locked?).to eq(false)
33
33
  end
34
34
 
35
35
  it "should lock and unlock" do
36
36
  semaphore.lock(1)
37
- semaphore.locked?.should == true
37
+ expect(semaphore.locked?).to eq(true)
38
38
  semaphore.unlock
39
- semaphore.locked?.should == false
39
+ expect(semaphore.locked?).to eq(false)
40
40
  end
41
41
 
42
42
  it "should not lock twice as a mutex" do
43
- semaphore.lock(1).should_not == false
44
- semaphore.lock(1).should == false
43
+ expect(semaphore.lock(1)).not_to eq(false)
44
+ expect(semaphore.lock(1)).to eq(false)
45
45
  end
46
46
 
47
47
  it "should not lock three times when only two available" do
48
- multisem.lock(1).should_not == false
49
- multisem.lock(1).should_not == false
50
- multisem.lock(1).should == false
48
+ expect(multisem.lock(1)).not_to eq(false)
49
+ expect(multisem.lock(1)).not_to eq(false)
50
+ expect(multisem.lock(1)).to eq(false)
51
51
  end
52
52
 
53
53
  it "should always have the correct lock-status" do
54
54
  multisem.lock(1)
55
55
  multisem.lock(1)
56
56
 
57
- multisem.locked?.should == true
57
+ expect(multisem.locked?).to eq(true)
58
58
  multisem.unlock
59
- multisem.locked?.should == true
59
+ expect(multisem.locked?).to eq(true)
60
60
  multisem.unlock
61
- multisem.locked?.should == false
61
+ expect(multisem.locked?).to eq(false)
62
62
  end
63
63
 
64
64
  it "should get all different tokens when saturating" do
65
65
  ids = []
66
- 2.times do
66
+ 2.times do
67
67
  ids << multisem.lock(1)
68
68
  end
69
69
 
70
- ids.should == %w(0 1)
70
+ expect(ids).to eq(%w(0 1))
71
71
  end
72
72
 
73
73
  it "should execute the given code block" do
@@ -75,25 +75,25 @@ describe "redis" do
75
75
  semaphore.lock(1) do
76
76
  code_executed = true
77
77
  end
78
- code_executed.should == true
78
+ expect(code_executed).to eq(true)
79
79
  end
80
80
 
81
81
  it "should pass an exception right through" do
82
- lambda do
82
+ expect {
83
83
  semaphore.lock(1) do
84
84
  raise Exception, "redis semaphore exception"
85
85
  end
86
- end.should raise_error(Exception, "redis semaphore exception")
86
+ }.to raise_error(Exception, "redis semaphore exception")
87
87
  end
88
88
 
89
89
  it "should not leave the semaphore locked after raising an exception" do
90
- lambda do
90
+ expect {
91
91
  semaphore.lock(1) do
92
92
  raise Exception
93
93
  end
94
- end.should raise_error
94
+ }.to raise_error
95
95
 
96
- semaphore.locked?.should == false
96
+ expect(semaphore.locked?).to eq(false)
97
97
  end
98
98
  end
99
99
 
@@ -110,28 +110,28 @@ describe "redis" do
110
110
  semaphore.signal
111
111
  end
112
112
 
113
- semaphore.available_count.should == 4
113
+ expect(semaphore.available_count).to eq(4)
114
114
 
115
115
  semaphore.wait(1)
116
116
  semaphore.wait(1)
117
117
  semaphore.wait(1)
118
118
 
119
- semaphore.available_count.should == 1
119
+ expect(semaphore.available_count).to eq(1)
120
120
  end
121
121
 
122
- it "can have stale locks released by a third process" do
122
+ it "can have stale locks released by a third process" do
123
123
  watchdog = Redis::Semaphore.new(:my_semaphore, :redis => @redis, :stale_client_timeout => 1)
124
124
  semaphore.lock
125
-
125
+
126
126
  sleep 0.5
127
127
 
128
128
  watchdog.release_stale_locks!
129
- semaphore.locked?.should == true
129
+ expect(semaphore.locked?).to eq(true)
130
130
 
131
131
  sleep 0.6
132
132
 
133
133
  watchdog.release_stale_locks!
134
- semaphore.locked?.should == false
134
+ expect(semaphore.locked?).to eq(false)
135
135
  end
136
136
  end
137
137
 
@@ -144,9 +144,9 @@ describe "redis" do
144
144
  it "should restore resources of stale clients" do
145
145
  hyper_aggressive_sem = Redis::Semaphore.new(:hyper_aggressive_sem, :resources => 1, :redis => @redis, :stale_client_timeout => 1)
146
146
 
147
- hyper_aggressive_sem.lock(1).should_not == false
148
- hyper_aggressive_sem.lock(1).should == false
149
- hyper_aggressive_sem.lock(1).should_not == false
147
+ expect(hyper_aggressive_sem.lock(1)).not_to eq(false)
148
+ expect(hyper_aggressive_sem.lock(1)).to eq(false)
149
+ expect(hyper_aggressive_sem.lock(1)).not_to eq(false)
150
150
  end
151
151
  end
152
152
 
@@ -158,17 +158,17 @@ describe "redis" do
158
158
  end
159
159
 
160
160
  it "with time support should return a different time than frozen time" do
161
- semaphore.send(:current_time).should_not == Time.now
161
+ expect(semaphore.send(:current_time)).not_to eq(Time.now)
162
162
  end
163
163
 
164
164
  it "with use_local_time should return the same time as frozen time" do
165
165
  semaphore = Redis::Semaphore.new(:my_semaphore, :redis => @redis, :stale_client_timeout => 5, :use_local_time => true)
166
- semaphore.send(:current_time).should == Time.now
166
+ expect(semaphore.send(:current_time)).to eq(Time.now)
167
167
  end
168
168
 
169
169
  it "without time support should return the same time as frozen time" do
170
- @redis.stub(:time) { raise Redis::CommandError }
171
- semaphore.send(:current_time).should == Time.now
170
+ expect(@redis).to receive(:time).and_raise(Redis::CommandError)
171
+ expect(semaphore.send(:current_time)).to eq(Time.now)
172
172
  end
173
173
  end
174
174
 
@@ -181,7 +181,7 @@ describe "redis" do
181
181
  semaphore.lock(1)
182
182
  grabbed_keys = semaphore.all_tokens
183
183
 
184
- available_keys.should == grabbed_keys
184
+ expect(available_keys).to eq(grabbed_keys)
185
185
  end
186
186
  end
187
187
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-semaphore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Verhasselt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-16 00:00:00.000000000 Z
11
+ date: 2014-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -40,7 +40,8 @@ files:
40
40
  - spec/semaphore_spec.rb
41
41
  - spec/spec_helper.rb
42
42
  homepage: http://github.com/dv/redis-semaphore
43
- licenses: []
43
+ licenses:
44
+ - MIT
44
45
  metadata: {}
45
46
  post_install_message:
46
47
  rdoc_options: []