-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split tests out per handler
- Loading branch information
1 parent
5aa3549
commit d5ae266
Showing
4 changed files
with
488 additions
and
359 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...ntation/active_job/test/opentelemetry/instrumentation/active_job/handlers/discard_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
require 'test_helper' | ||
|
||
require_relative '../../../../../lib/opentelemetry/instrumentation/active_job' | ||
|
||
describe "OpenTelemetry::Instrumentation::ActiveJob::Handlers::Discard" do | ||
let(:instrumentation) { OpenTelemetry::Instrumentation::ActiveJob::Instrumentation.instance } | ||
# Technically these are the defaults. But ActiveJob seems to act oddly if you re-install | ||
# the instrumentation over and over again - so we manipulate instance variables to | ||
# reset between tests, and that means we should set the defaults here. | ||
let(:config) { { propagation_style: :link, span_naming: :queue } } | ||
let(:exporter) { EXPORTER } | ||
let(:spans) { exporter.finished_spans } | ||
let(:publish_span) { spans.find { |s| s.name == 'default publish' } } | ||
let(:process_span) { spans.find { |s| s.name == 'default process' } } | ||
let(:discard_span) { spans.find { |s| s.name == 'discard.active_job' } } | ||
|
||
before do | ||
OpenTelemetry::Instrumentation::ActiveJob::Handlers.unsubscribe | ||
instrumentation.instance_variable_set(:@config, config) | ||
instrumentation.instance_variable_set(:@installed, false) | ||
|
||
instrumentation.install(config) | ||
ActiveJob::Base.queue_adapter = :async | ||
ActiveJob::Base.queue_adapter.immediate = true | ||
|
||
exporter.reset | ||
end | ||
|
||
after do | ||
begin | ||
ActiveJob::Base.queue_adapter.shutdown | ||
rescue StandardError | ||
nil | ||
end | ||
ActiveJob::Base.queue_adapter = :inline | ||
end | ||
|
||
describe 'exception handling' do | ||
it 'sets discard span status to error' do | ||
DiscardJob.perform_later | ||
|
||
_(process_span.status.code).must_equal OpenTelemetry::Trace::Status::ERROR | ||
_(process_span.status.description).must_equal 'discard me' | ||
|
||
_(discard_span.status.code).must_equal OpenTelemetry::Trace::Status::ERROR | ||
_(discard_span.status.description).must_equal 'discard me' | ||
_(discard_span.events.first.name).must_equal 'exception' | ||
_(discard_span.events.first.attributes['exception.type']).must_equal 'DiscardJob::DiscardError' | ||
_(discard_span.events.first.attributes['exception.message']).must_equal 'discard me' | ||
end | ||
end | ||
end |
Oops, something went wrong.