From 9e6f62e3a6a0c3c27a04adf071d7bed74c4e9250 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 8 Aug 2024 16:20:18 +0200 Subject: [PATCH] test that memoized values are cleared between retries --- spec/datadog/ci/contrib/rspec/instrumentation_spec.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/datadog/ci/contrib/rspec/instrumentation_spec.rb b/spec/datadog/ci/contrib/rspec/instrumentation_spec.rb index c64fd235..0f472772 100644 --- a/spec/datadog/ci/contrib/rspec/instrumentation_spec.rb +++ b/spec/datadog/ci/contrib/rspec/instrumentation_spec.rb @@ -46,9 +46,13 @@ def rspec_session_run( max_flaky_test_failures = 4 flaky_test_failures = 0 + current_let_value = 0 + with_new_rspec_environment do spec = RSpec.describe "SomeTest", suite_meta do context "nested", context_meta do + let(:let_value) { current_let_value += 1 } + it "foo", test_meta do expect(1 + 1).to eq(2) end @@ -72,6 +76,7 @@ def rspec_session_run( if with_flaky_test it "flaky" do + Datadog::CI.active_test&.set_tag("let_value", let_value) if flaky_test_failures < max_flaky_test_failures flaky_test_failures += 1 expect(1 + 1).to eq(3) @@ -133,7 +138,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, "106") + expect(first_test_span).to have_test_tag(:source_start, "111") expect(first_test_span).to have_test_tag( :codeowners, "[\"@DataDog/ruby-guild\", \"@DataDog/ci-app-libraries\"]" @@ -838,6 +843,10 @@ def rspec_skipped_session_run test_spans_by_test_name = test_spans.group_by { |span| span.get_tag("test.name") } expect(test_spans_by_test_name["nested flaky"]).to have(5).items + # check that let values are cleared between retries + let_values = test_spans_by_test_name["nested flaky"].map { |span| span.get_tag("let_value") } + expect(let_values).to eq([1, 2, 3, 4, 5]) + # count how many spans were marked as retries retries_count = test_spans.count { |span| span.get_tag("test.is_retry") == "true" } expect(retries_count).to eq(4)