3939 end
4040
4141 let ( :expect_thread? ) { true }
42- let ( :mutex ) { Mutex . new }
4342
4443 let ( :worker_class ) do
4544 Class . new do
@@ -51,12 +50,6 @@ def perform(action = :none, **_)
5150 end
5251 end
5352
54- def check_spans_count_eq ( count )
55- mutex . synchronize do
56- try_wait_until { get_spans_count == count }
57- end
58- end
59-
6053 context 'successful job' do
6154 subject ( :dummy_worker_success ) { worker_class . perform_async }
6255
@@ -67,19 +60,19 @@ def check_spans_count_eq(count)
6760 it_behaves_like 'measured span for integration' , true do
6861 before do
6962 dummy_worker_success
70- check_spans_count_eq ( 2 )
63+ try_wait_until { get_spans_count == 2 }
7164 end
7265 end
7366
7467 it 'generates two spans, one for pushing to enqueue and one for the job itself' do
7568 is_expected . to be true
76- check_spans_count_eq ( 2 )
69+ try_wait_until { get_spans_count == 2 }
7770 expect ( spans . length ) . to eq ( 2 )
7871 end
7972
8073 it 'instruments successful job' do
8174 is_expected . to be true
82- check_spans_count_eq ( 2 )
75+ try_wait_until { get_spans_count == 2 }
8376
8477 expect ( job_span . service ) . to eq ( tracer . default_service )
8578 expect ( job_span . name ) . to eq ( 'sucker_punch.perform' )
@@ -92,7 +85,7 @@ def check_spans_count_eq(count)
9285
9386 it 'instruments successful enqueuing' do
9487 is_expected . to be true
95- check_spans_count_eq ( 2 )
88+ try_wait_until { get_spans_count == 2 }
9689
9790 expect ( enqueue_span . service ) . to eq ( tracer . default_service )
9891 expect ( enqueue_span . name ) . to eq ( 'sucker_punch.perform_async' )
@@ -113,13 +106,13 @@ def check_spans_count_eq(count)
113106 it_behaves_like 'measured span for integration' , true do
114107 before do
115108 dummy_worker_fail
116- check_spans_count_eq ( 2 )
109+ try_wait_until { get_spans_count == 2 }
117110 end
118111 end
119112
120113 it 'instruments a failed job' do
121114 is_expected . to be true
122- check_spans_count_eq ( 2 )
115+ try_wait_until { get_spans_count == 2 }
123116
124117 expect ( job_span . service ) . to eq ( tracer . default_service )
125118 expect ( job_span . name ) . to eq ( 'sucker_punch.perform' )
@@ -140,13 +133,13 @@ def check_spans_count_eq(count)
140133 it_behaves_like 'measured span for integration' , true do
141134 before do
142135 dummy_worker_delay
143- check_spans_count_eq ( 2 )
136+ try_wait_until { get_spans_count == 2 }
144137 end
145138 end
146139
147140 it 'instruments enqueuing for a delayed job' do
148141 dummy_worker_delay
149- check_spans_count_eq ( 2 )
142+ try_wait_until { get_spans_count == 2 }
150143
151144 expect ( enqueue_span . service ) . to eq ( tracer . default_service )
152145 expect ( enqueue_span . name ) . to eq ( 'sucker_punch.perform_in' )
0 commit comments