Skip to content

Commit b2797ba

Browse files
committed
Must be able to access name without a bulkhead
1 parent ca00770 commit b2797ba

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

lib/semian/circuit_breaker.rb

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module Semian
22
class CircuitBreaker #:nodoc:
33
extend Forwardable
44

5+
attr_reader :name
6+
57
def_delegators :@state, :closed?, :open?, :half_open?
68

79
def initialize(name, exceptions:, success_threshold:, error_threshold:, error_timeout:, implementation:)

lib/semian/protected_resource.rb

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ module Semian
22
class ProtectedResource
33
extend Forwardable
44

5-
def_delegators :@bulkhead, :destroy, :count, :semid, :tickets, :registered_workers, :name
5+
def_delegators :@bulkhead, :destroy, :count, :semid, :tickets, :registered_workers
66
def_delegators :@circuit_breaker, :reset, :mark_failed, :mark_success, :request_allowed?,
77
:open?, :closed?, :half_open?
88

9-
attr_reader :bulkhead, :circuit_breaker
9+
attr_reader :bulkhead, :circuit_breaker, :name
1010

1111
def initialize(bulkhead, circuit_breaker)
1212
@bulkhead = bulkhead
1313
@circuit_breaker = circuit_breaker
14+
assign_name
1415
end
1516

1617
def destroy
@@ -54,5 +55,10 @@ def acquire_bulkhead(timeout, scope, adapter)
5455
Semian.notify(:busy, self, scope, adapter)
5556
raise
5657
end
58+
59+
def assign_name
60+
@name = @bulkhead.name if @bulkhead
61+
@name ||= @circuit_breaker.name if @circuit_breaker
62+
end
5763
end
5864
end

test/protected_resource_test.rb

+27
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,33 @@ def teardown
1616
super
1717
end
1818

19+
def test_get_name_without_bulkhead
20+
Semian.register(
21+
:testing,
22+
exceptions: [SomeError],
23+
error_threshold: 2,
24+
error_timeout: 5,
25+
success_threshold: 1,
26+
bulkhead: false,
27+
)
28+
29+
refute_nil Semian.resources[:testing].name
30+
end
31+
32+
def test_get_name_without_bulkhead_or_circuit_breaker
33+
Semian.register(
34+
:testing,
35+
exceptions: [SomeError],
36+
error_threshold: 2,
37+
error_timeout: 5,
38+
success_threshold: 1,
39+
bulkhead: false,
40+
circuit_breaker: false,
41+
)
42+
43+
assert_nil Semian.resources[:testing].name
44+
end
45+
1946
def test_acquire_without_bulkhead
2047
Semian.register(
2148
:testing,

0 commit comments

Comments
 (0)