Skip to content

Commit

Permalink
WIP add first part of shoryuken tracer spec
Browse files Browse the repository at this point in the history
  • Loading branch information
JustSnow committed Dec 4, 2018
1 parent 6f68931 commit b4a1cf0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
31 changes: 31 additions & 0 deletions spec/ddtrace/contrib/shoryuken/shoryuken_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,34 @@
require 'shoryuken'
require 'ddtrace/contrib/shoryuken/tracer'
require 'ddtrace/contrib/shoryuken/integration'

class TestWorker
include Shoryuken::Worker

shoryuken_options queue: 'default'

def perform(sqs_msg, body); end
end

RSpec.configure do |config|
config.before do
Shoryuken::Client.class_variable_set :@@queues, {}
Shoryuken::Client.sqs = nil
Shoryuken.groups.clear
Shoryuken.options[:concurrency] = 1
Shoryuken.options[:delay] = 1
Shoryuken.options[:timeout] = 1
Shoryuken.options[:daemon] = nil
Shoryuken.options[:logfile] = nil
Shoryuken.options[:queues] = nil
TestWorker.get_shoryuken_options.clear
TestWorker.get_shoryuken_options['queue'] = 'default'
Shoryuken.active_job_queue_name_prefixing = false
Shoryuken.worker_registry.clear
Shoryuken.register_worker('default', TestWorker)
Aws.config[:stub_responses] = true
Shoryuken.sqs_client_receive_message_opts.clear

allow(Shoryuken).to receive(:active_job?).and_return(false)
end
end
29 changes: 29 additions & 0 deletions spec/ddtrace/contrib/shoryuken/tracer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'
require 'spec/ddtrace/contrib/shoryuken/shoryuken_spec_helper'

RSpec.describe Datadog::Contrib::Shoryuken::Tracer do
let(:worker) { TestWorker.perform_async(body) }
let(:tracer) { ::Datadog::Tracer.new(writer: writer) }
let(:writer) { FauxWriter.new }
let(:sqs_queue) { double Shoryuken::Queue, visibility_timeout: 60 }
let(:queue) { 'default' }
let(:body) { 'test' }
let :sqs_msg do
double \
Shoryuken::Message,
queue_url: queue,
body: 'test',
attributes: {
id: 1,
test_attribute: 'test'
}
end

before do
allow(Shoryuken::Client).to receive(:queues).with(queue).and_return sqs_queue

Shoryuken.server_middleware do |chain|
chain.add Datadog::Contrib::Shoryuken::Tracer, tracer: tracer
end
end
end

0 comments on commit b4a1cf0

Please sign in to comment.