39
39
end
40
40
41
41
let ( :expect_thread? ) { true }
42
+ let ( :mutex ) { Mutex . new }
42
43
43
44
let ( :worker_class ) do
44
45
Class . new do
@@ -50,6 +51,12 @@ def perform(action = :none, **_)
50
51
end
51
52
end
52
53
54
+ def check_span_count_eq ( count )
55
+ mutex . synchronize do
56
+ try_wait_until { fetch_spans_without_sorting . length == count }
57
+ end
58
+ end
59
+
53
60
context 'successful job' do
54
61
subject ( :dummy_worker_success ) { worker_class . perform_async }
55
62
@@ -60,19 +67,19 @@ def perform(action = :none, **_)
60
67
it_behaves_like 'measured span for integration' , true do
61
68
before do
62
69
dummy_worker_success
63
- try_wait_until { fetch_spans . length == 2 }
70
+ check_span_count_eq ( 2 )
64
71
end
65
72
end
66
73
67
74
it 'generates two spans, one for pushing to enqueue and one for the job itself' do
68
75
is_expected . to be true
69
- try_wait_until { fetch_spans . length == 2 }
76
+ check_span_count_eq ( 2 )
70
77
expect ( spans . length ) . to eq ( 2 )
71
78
end
72
79
73
80
it 'instruments successful job' do
74
81
is_expected . to be true
75
- try_wait_until { fetch_spans . length == 2 }
82
+ check_span_count_eq ( 2 )
76
83
77
84
expect ( job_span . service ) . to eq ( tracer . default_service )
78
85
expect ( job_span . name ) . to eq ( 'sucker_punch.perform' )
@@ -85,7 +92,7 @@ def perform(action = :none, **_)
85
92
86
93
it 'instruments successful enqueuing' do
87
94
is_expected . to be true
88
- try_wait_until { fetch_spans . length == 2 }
95
+ check_span_count_eq ( 2 )
89
96
90
97
expect ( enqueue_span . service ) . to eq ( tracer . default_service )
91
98
expect ( enqueue_span . name ) . to eq ( 'sucker_punch.perform_async' )
@@ -106,13 +113,13 @@ def perform(action = :none, **_)
106
113
it_behaves_like 'measured span for integration' , true do
107
114
before do
108
115
dummy_worker_fail
109
- try_wait_until { fetch_spans . length == 2 }
116
+ check_span_count_eq ( 2 )
110
117
end
111
118
end
112
119
113
120
it 'instruments a failed job' do
114
121
is_expected . to be true
115
- try_wait_until { fetch_spans . length == 2 }
122
+ check_span_count_eq ( 2 )
116
123
117
124
expect ( job_span . service ) . to eq ( tracer . default_service )
118
125
expect ( job_span . name ) . to eq ( 'sucker_punch.perform' )
@@ -133,13 +140,13 @@ def perform(action = :none, **_)
133
140
it_behaves_like 'measured span for integration' , true do
134
141
before do
135
142
dummy_worker_delay
136
- try_wait_until { fetch_spans . length == 2 }
143
+ check_span_count_eq ( 2 )
137
144
end
138
145
end
139
146
140
147
it 'instruments enqueuing for a delayed job' do
141
148
dummy_worker_delay
142
- try_wait_until { fetch_spans . length == 2 }
149
+ check_span_count_eq ( 2 )
143
150
144
151
expect ( enqueue_span . service ) . to eq ( tracer . default_service )
145
152
expect ( enqueue_span . name ) . to eq ( 'sucker_punch.perform_in' )
0 commit comments