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

migrate sucker_punch tests from minitest to rspec #1128

Merged
merged 6 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 1 addition & 10 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ namespace :test do
end

[
:grape,
:sucker_punch
:grape
].each do |contrib|
Rake::TestTask.new(contrib) do |t|
t.libs << %w[test lib]
Expand Down Expand Up @@ -201,7 +200,6 @@ task :ci do
if RUBY_PLATFORM != 'java'
# Contrib minitests
sh 'bundle exec appraisal contrib-old rake test:monkey'
sh 'bundle exec appraisal contrib-old rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib-old rake spec:active_model_serializers'
sh 'bundle exec appraisal contrib-old rake spec:active_record'
Expand Down Expand Up @@ -258,7 +256,6 @@ task :ci do
if RUBY_PLATFORM != 'java'
# Contrib minitests
sh 'bundle exec appraisal contrib-old rake test:monkey'
sh 'bundle exec appraisal contrib-old rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib-old rake spec:active_model_serializers'
sh 'bundle exec appraisal contrib-old rake spec:active_record'
Expand Down Expand Up @@ -322,7 +319,6 @@ task :ci do
if RUBY_PLATFORM != 'java'
# Contrib minitests
sh 'bundle exec appraisal contrib rake test:grape'
sh 'bundle exec appraisal contrib rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib rake spec:action_pack'
sh 'bundle exec appraisal contrib rake spec:action_view'
Expand Down Expand Up @@ -398,7 +394,6 @@ task :ci do
if RUBY_PLATFORM != 'java'
# Contrib minitests
sh 'bundle exec appraisal contrib rake test:grape'
sh 'bundle exec appraisal contrib rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib rake spec:action_pack'
sh 'bundle exec appraisal contrib rake spec:action_view'
Expand Down Expand Up @@ -479,7 +474,6 @@ task :ci do
sh 'bundle exec rake benchmark'
# Contrib minitests
sh 'bundle exec appraisal contrib rake test:grape'
sh 'bundle exec appraisal contrib rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib rake spec:action_pack'
sh 'bundle exec appraisal contrib rake spec:action_view'
Expand Down Expand Up @@ -545,7 +539,6 @@ task :ci do
sh 'bundle exec rake benchmark'
# Contrib minitests
sh 'bundle exec appraisal contrib rake test:grape'
sh 'bundle exec appraisal contrib rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib rake spec:action_pack'
sh 'bundle exec appraisal contrib rake spec:action_view'
Expand Down Expand Up @@ -621,7 +614,6 @@ task :ci do
sh 'bundle exec rake benchmark'
# Contrib minitests
sh 'bundle exec appraisal contrib rake test:grape'
sh 'bundle exec appraisal contrib rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib rake spec:action_pack'
sh 'bundle exec appraisal contrib rake spec:action_view'
Expand Down Expand Up @@ -696,7 +688,6 @@ task :ci do
sh 'bundle exec rake benchmark'
# Contrib minitests
sh 'bundle exec appraisal contrib rake test:grape'
sh 'bundle exec appraisal contrib rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib rake spec:action_pack'
sh 'bundle exec appraisal contrib rake spec:action_view'
Expand Down
101 changes: 101 additions & 0 deletions spec/ddtrace/contrib/sucker_punch/patcher_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
require 'ddtrace/contrib/support/spec_helper'
require 'sucker_punch'
require 'ddtrace'
require_relative 'dummy_worker'

RSpec.describe 'Sinatra instrumentation' do
before do
Datadog.configure do |c|
c.use :sucker_punch
end

::SuckerPunch::Queue.clear
::SuckerPunch::RUNNING.make_true
end

after do
::SuckerPunch::Queue.clear
end

around do |example|
# Reset before and after each example; don't allow global state to linger.
Datadog.registry[:sucker_punch].reset_configuration!
example.run
Datadog.registry[:sucker_punch].reset_configuration!
end

context 'successful job' do
subject(:dummy_work_success) { ::DummyWorker.perform_async }
marcotc marked this conversation as resolved.
Show resolved Hide resolved

it 'should generate 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 }
expect(spans.length).to eq(2)
end

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

span = spans.find { |s| s.resource[/PROCESS/] }
marcotc marked this conversation as resolved.
Show resolved Hide resolved

expect('sucker_punch').to eq(span.service)
marcotc marked this conversation as resolved.
Show resolved Hide resolved
expect('sucker_punch.perform').to eq(span.name)
expect('PROCESS DummyWorker').to eq(span.resource)
expect('DummyWorker').to eq(span.get_tag('sucker_punch.queue'))
expect(Datadog::Ext::Errors::STATUS).not_to eq(span.status)
marcotc marked this conversation as resolved.
Show resolved Hide resolved
expect(span.get_metric('_dd.measured')).to eq(1.0)
marcotc marked this conversation as resolved.
Show resolved Hide resolved
end

it 'should instrument successful enqueuing' do
is_expected.to be true
try_wait_until { fetch_spans.any? }

span = spans.find { |s| s.resource[/ENQUEUE/] }

expect('sucker_punch').to eq(span.service)
expect('sucker_punch.perform_async').to eq(span.name)
expect('ENQUEUE DummyWorker').to eq(span.resource)
expect('DummyWorker').to eq(span.get_tag('sucker_punch.queue'))
expect(span.get_metric('_dd.measured')).to eq(1.0)
end
end

context 'failed job' do
subject(:dummy_work_fail) { ::DummyWorker.perform_async(:fail) }

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

span = spans.find { |s| s.resource[/PROCESS/] }

expect('sucker_punch').to eq(span.service)
expect('sucker_punch.perform').to eq(span.name)
expect('PROCESS DummyWorker').to eq(span.resource)
expect('DummyWorker').to eq(span.get_tag('sucker_punch.queue'))
expect(Datadog::Ext::Errors::STATUS).to eq(span.status)
expect('ZeroDivisionError').to eq(span.get_tag(Datadog::Ext::Errors::TYPE))
expect('divided by 0').to eq(span.get_tag(Datadog::Ext::Errors::MSG))
expect(span.get_metric('_dd.measured')).to eq(1.0)
end
end

context 'delayed job' do
subject(:dummy_worker_delay) { ::DummyWorker.perform_in(0) }

it 'should instrument enqueuing for a delayed job' do
is_expected.to be true
try_wait_until { fetch_spans.any? }

span = spans.find { |s| s.resource[/ENQUEUE/] }

expect('sucker_punch').to eq(span.service)
expect('sucker_punch.perform_in').to eq(span.name)
expect('ENQUEUE DummyWorker').to eq(span.resource)
expect('DummyWorker').to eq(span.get_tag('sucker_punch.queue'))
expect(0).to eq(span.get_tag('sucker_punch.perform_in'))
expect(span.get_metric('_dd.measured')).to eq(1.0)
end
end
end
93 changes: 0 additions & 93 deletions test/contrib/sucker_punch/patcher_test.rb

This file was deleted.