-
Notifications
You must be signed in to change notification settings - Fork 79
/
instrumentation_test.rb
85 lines (71 loc) · 2 KB
/
instrumentation_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# frozen_string_literal: true
require "test_helper"
class TestInstrumentation < Minitest::Test
def setup
destroy_all_semian_resources
Semian.register(:testing, tickets: 1, error_threshold: 1, error_timeout: 5, success_threshold: 1)
end
def test_busy_instrumentation
assert_notify(:success, :busy, :state_change) do
Semian[:testing].acquire do
assert_raises(Semian::TimeoutError) do
Semian[:testing].acquire {}
end
end
end
end
def test_circuit_open_instrumentation
assert_notify(:success, :busy, :state_change) do
Semian[:testing].acquire do
assert_raises(Semian::TimeoutError) do
Semian[:testing].acquire {}
end
end
end
assert_notify(:circuit_open) do
assert_raises(Semian::OpenCircuitError) do
Semian[:testing].acquire {}
end
end
end
def test_success_instrumentation
assert_notify(:success) do
Semian[:testing].acquire {}
end
end
def test_success_instrumentation_without_bulkhead
Semian.register(:no_bulkhead, bulkhead: false, error_threshold: 1, error_timeout: 5, success_threshold: 1)
assert_notify(:success) do
Semian[:no_bulkhead].acquire {}
end
end
def test_success_instrumentation_wait_time
hit = false
subscription = Semian.subscribe do |*_, wait_time|
hit = true
assert_kind_of(Integer, wait_time)
end
Semian[:testing].acquire {}
assert(hit)
ensure
Semian.unsubscribe(subscription)
end
def test_success_instrumentation_when_unknown_exceptions_occur
assert_notify(:success) do
assert_raises(RuntimeError) do
Semian[:testing].acquire { raise "Some error" }
end
end
end
private
def assert_notify(*expected_events)
events = []
subscription = Semian.subscribe do |event, _resource|
events << event
end
yield
assert_equal(expected_events, events, "The timeline of events was not as expected")
ensure
Semian.unsubscribe(subscription)
end
end