From b4a1cf0ada7f81a065c1c91a0bf997cd79f046a4 Mon Sep 17 00:00:00 2001 From: JustSnow Date: Tue, 4 Dec 2018 16:46:06 +0300 Subject: [PATCH] WIP add first part of shoryuken tracer spec --- .../shoryuken/shoryuken_spec_helper.rb | 31 +++++++++++++++++++ spec/ddtrace/contrib/shoryuken/tracer_spec.rb | 29 +++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 spec/ddtrace/contrib/shoryuken/tracer_spec.rb diff --git a/spec/ddtrace/contrib/shoryuken/shoryuken_spec_helper.rb b/spec/ddtrace/contrib/shoryuken/shoryuken_spec_helper.rb index 9e055f22647..5539bf3dcdb 100644 --- a/spec/ddtrace/contrib/shoryuken/shoryuken_spec_helper.rb +++ b/spec/ddtrace/contrib/shoryuken/shoryuken_spec_helper.rb @@ -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 diff --git a/spec/ddtrace/contrib/shoryuken/tracer_spec.rb b/spec/ddtrace/contrib/shoryuken/tracer_spec.rb new file mode 100644 index 00000000000..ad0fe0b7d30 --- /dev/null +++ b/spec/ddtrace/contrib/shoryuken/tracer_spec.rb @@ -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