Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address sucker_punch flaky test #4344

Merged
merged 7 commits into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions spec/datadog/tracing/contrib/sucker_punch/patcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def perform(action = :none, **_)
end
end

def get_spans_count(tracer = self.tracer)
fetch_traces(tracer).sum { |trace| trace.spans.length }
end

context 'successful job' do
subject(:dummy_worker_success) { worker_class.perform_async }

Expand All @@ -60,19 +64,19 @@ def perform(action = :none, **_)
it_behaves_like 'measured span for integration', true do
before do
dummy_worker_success
try_wait_until { fetch_spans.length == 2 }
try_wait_until { get_spans_count == 2 }
end
end

it 'generates two spans, one for pushing to enqueue and one for the job itself' do
is_expected.to be true
try_wait_until { fetch_spans.length == 2 }
try_wait_until { get_spans_count == 2 }
expect(spans.length).to eq(2)
end

it 'instruments successful job' do
is_expected.to be true
try_wait_until { fetch_spans.length == 2 }
try_wait_until { get_spans_count == 2 }

expect(job_span.service).to eq(tracer.default_service)
expect(job_span.name).to eq('sucker_punch.perform')
Expand All @@ -85,7 +89,7 @@ def perform(action = :none, **_)

it 'instruments successful enqueuing' do
is_expected.to be true
try_wait_until { fetch_spans.length == 2 }
try_wait_until { get_spans_count == 2 }

expect(enqueue_span.service).to eq(tracer.default_service)
expect(enqueue_span.name).to eq('sucker_punch.perform_async')
Expand All @@ -106,13 +110,13 @@ def perform(action = :none, **_)
it_behaves_like 'measured span for integration', true do
before do
dummy_worker_fail
try_wait_until { fetch_spans.length == 2 }
try_wait_until { get_spans_count == 2 }
end
end

it 'instruments a failed job' do
is_expected.to be true
try_wait_until { fetch_spans.length == 2 }
try_wait_until { get_spans_count == 2 }

expect(job_span.service).to eq(tracer.default_service)
expect(job_span.name).to eq('sucker_punch.perform')
Expand All @@ -133,13 +137,13 @@ def perform(action = :none, **_)
it_behaves_like 'measured span for integration', true do
before do
dummy_worker_delay
try_wait_until { fetch_spans.length == 2 }
try_wait_until { get_spans_count == 2 }
end
end

it 'instruments enqueuing for a delayed job' do
dummy_worker_delay
try_wait_until { fetch_spans.length == 2 }
try_wait_until { get_spans_count == 2 }

expect(enqueue_span.service).to eq(tracer.default_service)
expect(enqueue_span.name).to eq('sucker_punch.perform_in')
Expand Down
Loading