resilient 0.4.0.beta1 → 0.4.0.beta2

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
  SHA1:
3
- metadata.gz: d58c0c8c5444d5e583d6667644d2309fd1d76c75
4
- data.tar.gz: 92b729571e650001c424eac22b707eabb5f02806
3
+ metadata.gz: 61b08291053b49bf75e2b32eef05a5ab4fe4b4f2
4
+ data.tar.gz: fbf4f792be70a627f6c71b587a3efc30f7ff9527
5
5
  SHA512:
6
- metadata.gz: de26fd92ca043468781a0cc18544d8904a37da9170c86f347141519e07e36304f005be212618f3dd909e379e3f694b638be480a483107a2ef9627440c70153d8
7
- data.tar.gz: 149eba99b8f5d6e3310d0ee4933d4b3ea23cdbee945730a74f4d3189665a6432fda514b1a40a43e7eb51f89c1cc16bc0368642e8e37850ad26724c18be8cd151
6
+ metadata.gz: 9ddd1cb3aa4018a638df2cb1c6b4fa75fe3b69e78b0d927f5aee0c7e5d0be9f3a217b65d11c2929420c1ef68ac77da8c824bcce7b8e57e283398bd853994ccb7
7
+ data.tar.gz: b60e16a13ae90cba9a2a76e779d50ff3167d069c98fd4cf717cd4141751d7119ce50bec1bf697b1666949ada4cfda4538c7fef87ac20b6b9449588da53838daf
data/README.md CHANGED
@@ -84,12 +84,14 @@ circuit_breaker = Resilient::CircuitBreaker.get("example", {
84
84
 
85
85
  ## Tests
86
86
 
87
- To ensure that you have a clean circuit for each test case, be sure to run the following in the setup for your tests (which resets each registered circuit breaker) either before every test case or at a minimum each test case that uses circuit breakers.
87
+ To ensure that you have clean circuit breakers for each test case, be sure to run the following in the setup for your tests (which resets the default registry and thus clears all the registered circuits) either before every test case or at a minimum each test case that uses circuit breakers.
88
88
 
89
89
  ```ruby
90
- Resilient::CircuitBreaker.reset
90
+ Resilient::CircuitBreaker::Registry.reset
91
91
  ```
92
92
 
93
+ **Note**: If you use a non-default registry, you'll need to reset that on your own. If you don't know what I'm talking about, you are fine.
94
+
93
95
  ## Development
94
96
 
95
97
  ```bash
@@ -5,13 +5,6 @@ require "resilient/circuit_breaker/registry"
5
5
 
6
6
  module Resilient
7
7
  class CircuitBreaker
8
- # Public: Resets all registered circuit breakers (and thus their state/metrics).
9
- # Useful for ensuring a clean environment between tests. If you are using a
10
- # registry other than the default, you will need to handle resets on your own.
11
- def self.reset
12
- Registry.default.reset
13
- end
14
-
15
8
  # Public: Returns an instance of circuit breaker based on key and registry.
16
9
  # Default registry is used if none is provided. If key does not exist, it is
17
10
  # registered. If key does exist, it returns registered instance instead of
@@ -11,11 +11,19 @@ module Resilient
11
11
  @default = value
12
12
  end
13
13
 
14
+ # Public: Reset the default registry. This completely wipes all instances
15
+ # by swapping out the default registry for a new one and letting the old
16
+ # one get GC'd. Useful in tests to get a completely clean slate.
17
+ def self.reset
18
+ default.reset
19
+ end
20
+
14
21
  def initialize(source = nil)
15
22
  @source = source || {}
16
23
  end
17
24
 
18
- # Setup default to new instance.
25
+ # Setup new instance as default. Needs to be after initialize so hash gets
26
+ # initialize correctly.
19
27
  @default = new
20
28
 
21
29
  # Internal: To be used by CircuitBreaker to either get an instance for a
@@ -38,7 +46,7 @@ module Resilient
38
46
  # breakers, which should only really be used for cleaning up in
39
47
  # test environment.
40
48
  def reset
41
- @source.each_value(&:reset)
49
+ @source = {}
42
50
  nil
43
51
  end
44
52
  end
@@ -20,18 +20,17 @@ module Resilient
20
20
  end
21
21
 
22
22
  def test_reset
23
- bar_value = Minitest::Mock.new
24
- wick_value = Minitest::Mock.new
25
- bar_value.expect :reset, nil, []
26
- wick_value.expect :reset, nil, []
27
-
28
- @object.fetch("foo") { bar_value }
29
- @object.fetch("baz") { wick_value }
23
+ original_foo = @object.fetch("foo") { Object.new }
24
+ original_bar = @object.fetch("bar") { Object.new }
30
25
 
31
26
  assert_nil @object.reset
32
27
 
33
- bar_value.verify
34
- wick_value.verify
28
+ foo = @object.fetch("foo") { Object.new }
29
+ bar = @object.fetch("bar") { Object.new }
30
+
31
+ # assert that the objects before and after reset are not the same object
32
+ refute original_foo.equal?(foo)
33
+ refute original_bar.equal?(bar)
35
34
  end
36
35
 
37
36
  def test_reset_empty_registry
@@ -1,3 +1,3 @@
1
1
  module Resilient
2
- VERSION = "0.4.0.beta1"
2
+ VERSION = "0.4.0.beta2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resilient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.beta1
4
+ version: 0.4.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-02 00:00:00.000000000 Z
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler