Skip to content

Commit

Permalink
Merge pull request #215 from DataDog/anmarchenko/bail_out_of_tracing_…
Browse files Browse the repository at this point in the history
…when_job_canceled

[SDTEST-666] RSpec - don't report test errors if rspec process is quitting
  • Loading branch information
anmarchenko authored Aug 14, 2024
2 parents 96c1fe6 + 655e108 commit db2dcde
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/datadog/ci/contrib/rspec/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ def run(*args)
# before each run remove any previous exception
@exception = nil

super
result = super

# In case when test job is canceled and RSpec is quitting we don't want to report the last test
# before RSpec context unwinds. This test might have some unrelated errors that we don't want to
# report.
return result if ::RSpec.world.wants_to_quit

case execution_result.status
when :passed
Expand Down
28 changes: 27 additions & 1 deletion spec/datadog/ci/contrib/rspec/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def rspec_session_run(
with_shared_test: false,
with_shared_context: false,
with_flaky_test: false,
with_canceled_test: false,
unskippable: {
test: false,
context: false,
Expand Down Expand Up @@ -85,6 +86,14 @@ def rspec_session_run(
end
end
end

if with_canceled_test
it "canceled during execution" do
RSpec.world.wants_to_quit = true

expect(1 + 1).to eq(34)
end
end
end
end

Expand Down Expand Up @@ -138,7 +147,7 @@ def rspec_session_run(
:source_file,
"spec/datadog/ci/contrib/rspec/instrumentation_spec.rb"
)
expect(first_test_span).to have_test_tag(:source_start, "111")
expect(first_test_span).to have_test_tag(:source_start, "120")
expect(first_test_span).to have_test_tag(
:codeowners,
"[\"@DataDog/ruby-guild\", \"@DataDog/ci-app-libraries\"]"
Expand Down Expand Up @@ -932,4 +941,21 @@ def rspec_skipped_session_run
expect(test_session_span).to have_fail_status
end
end

context "session that is canceled during the test execution" do
include_context "CI mode activated" do
let(:integration_name) { :rspec }
let(:integration_options) { {service_name: "lspec"} }
end

it "retries test until it passes" do
rspec_session_run(with_canceled_test: true)

expect(test_spans).to have(2).items
test_spans.each do |test_span|
expect(test_span).not_to have_test_tag(:status, "fail")
expect(test_span.status).to eq(0)
end
end
end
end
5 changes: 5 additions & 0 deletions vendor/rbs/rspec/0/rspec.rbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module RSpec
def self.configuration: () -> RSpec::Core::Configuration
def self.world: () -> RSpec::Core::World
end

module RSpec::Core
Expand Down Expand Up @@ -46,3 +47,7 @@ end
class RSpec::Core::Configuration
def dry_run?: () -> bool
end

class RSpec::Core::World
def wants_to_quit: () -> bool
end

0 comments on commit db2dcde

Please sign in to comment.