berater 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1a54a65428bf73c9a8840d95900215411a7320d87af5297cbc75039976e182c
4
- data.tar.gz: 5804acf97ae46ab33bf8366438304a301d183fb0b8da48f4b872252769e79a54
3
+ metadata.gz: 3452315467fe2c079071179703283dd9ea92eb8e6abcc959905f40e16f3e2414
4
+ data.tar.gz: 90d783190f15f57c3ac44dc2afc89fb5a000a392163ab9a8351ff498e323901a
5
5
  SHA512:
6
- metadata.gz: c4f2f7002db193351b915c0f21b4ff6a704c20e90e7ff5815a5bfef3f38064608a367e7e150cf430e2d87a8b7b10420a3ec00a1c211bc4edcd04d0c479af3eb8
7
- data.tar.gz: '06489eb2f8769e349b163d49b9a6e6a0f1a8d55b97ded73fcdeb01652b0048e4dd3d940fc71075041129b1f280120d44eec906d258056d720c1f07ac23089cb7'
6
+ metadata.gz: 228f67adfb24027a6ea3c7b090c64aecee1a38e64ed00f7272b0c1af273dbcc73bbec8112fbb15595133cd450b45ac10f603e30ad252218d41e66d5206cc549d
7
+ data.tar.gz: 9068fd600128bb11f718318fa41f1030d17cd5ad36b9ce5884cbdc5f105fe56f92da73568dc60f12f6e1c7a64402652381259a64524c80889465d4c794a91e69
@@ -1,7 +1,7 @@
1
1
  module Berater
2
2
  class BaseLimiter
3
3
 
4
- class Overloaded < RuntimeError; end
4
+ class Overloaded < StandardError; end
5
5
 
6
6
  attr_reader :options
7
7
 
@@ -33,11 +33,12 @@ module Berater
33
33
  end
34
34
 
35
35
  class Lock
36
- attr_reader :limiter, :id
36
+ attr_reader :limiter, :id, :contention
37
37
 
38
- def initialize(limiter, id)
38
+ def initialize(limiter, id, contention)
39
39
  @limiter = limiter
40
40
  @id = id
41
+ @contention = contention
41
42
  @released = false
42
43
  @locked_at = Time.now
43
44
  end
@@ -127,11 +128,11 @@ module Berater
127
128
 
128
129
  raise Incapacitated unless lock_id
129
130
 
130
- lock = Lock.new(self, lock_id)
131
+ lock = Lock.new(self, lock_id, count)
131
132
 
132
133
  if block_given?
133
134
  begin
134
- yield
135
+ yield lock
135
136
  ensure
136
137
  release(lock)
137
138
  end
@@ -142,7 +143,7 @@ module Berater
142
143
 
143
144
  def release(lock)
144
145
  res = redis.zrem(key, lock.id)
145
- res == true || res == 1
146
+ res == true || res == 1 # depending on which version of Redis
146
147
  end
147
148
 
148
149
  end
@@ -1,3 +1,3 @@
1
1
  module Berater
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -31,4 +31,20 @@ describe Berater::ConcurrencyLimiter::Lock do
31
31
  it { expect(subject.released?).to be false }
32
32
  end
33
33
 
34
+ describe '#contention' do
35
+ let(:limiter) { Berater.new(:concurrency, 3) }
36
+
37
+ it 'tracks contention' do
38
+ lock_1 = limiter.limit
39
+ expect(lock_1.contention).to eq 1
40
+
41
+ lock_2 = limiter.limit
42
+ expect(lock_2.contention).to eq 2
43
+
44
+ limiter.limit do |lock_3|
45
+ expect(lock_3.contention).to eq 3
46
+ end
47
+ end
48
+ end
49
+
34
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Pepper