Skip to content

Commit 14426f3

Browse files
committed
Don't delegate anything to bulkhead
1 parent b2797ba commit 14426f3

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

lib/semian/protected_resource.rb

+20-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module Semian
22
class ProtectedResource
33
extend Forwardable
44

5-
def_delegators :@bulkhead, :destroy, :count, :semid, :tickets, :registered_workers
65
def_delegators :@circuit_breaker, :reset, :mark_failed, :mark_success, :request_allowed?,
76
:open?, :closed?, :half_open?
87

@@ -27,6 +26,26 @@ def acquire(timeout: nil, scope: nil, adapter: nil)
2726
end
2827
end
2928

29+
def tickets
30+
@bulkhead ? @bulkhead.tickets : 0
31+
end
32+
33+
def count
34+
@bulkhead ? @bulkhead.count : 0
35+
end
36+
37+
def registered_workers
38+
@bulkhead ? @bulkhead.registered_workers : 0
39+
end
40+
41+
def semid
42+
@bulkhead ? @bulkhead.semid : 0
43+
end
44+
45+
def destroy
46+
@bulkhead.destroy if bulkhead
47+
end
48+
3049
private
3150

3251
def acquire_circuit_breaker(scope, adapter)

test/protected_resource_test.rb

+52
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,58 @@ def test_get_name_without_bulkhead_or_circuit_breaker
4343
assert_nil Semian.resources[:testing].name
4444
end
4545

46+
def test_get_semid_without_bulkhead
47+
Semian.register(
48+
:testing,
49+
exceptions: [SomeError],
50+
error_threshold: 2,
51+
error_timeout: 5,
52+
success_threshold: 1,
53+
bulkhead: false,
54+
)
55+
56+
assert_equal(0, Semian.resources[:testing].semid)
57+
end
58+
59+
def test_get_tickets_without_bulkhead
60+
Semian.register(
61+
:testing,
62+
exceptions: [SomeError],
63+
error_threshold: 2,
64+
error_timeout: 5,
65+
success_threshold: 1,
66+
bulkhead: false,
67+
)
68+
69+
assert_equal(0, Semian.resources[:testing].tickets)
70+
end
71+
72+
def test_get_count_without_bulkhead
73+
Semian.register(
74+
:testing,
75+
exceptions: [SomeError],
76+
error_threshold: 2,
77+
error_timeout: 5,
78+
success_threshold: 1,
79+
bulkhead: false,
80+
)
81+
82+
assert_equal(0, Semian.resources[:testing].count)
83+
end
84+
85+
def test_get_registered_workers_without_bulkhead
86+
Semian.register(
87+
:testing,
88+
exceptions: [SomeError],
89+
error_threshold: 2,
90+
error_timeout: 5,
91+
success_threshold: 1,
92+
bulkhead: false,
93+
)
94+
95+
assert_equal(0, Semian.resources[:testing].registered_workers)
96+
end
97+
4698
def test_acquire_without_bulkhead
4799
Semian.register(
48100
:testing,

0 commit comments

Comments
 (0)