Skip to content

Commit

Permalink
test that memoized values are cleared between retries
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Aug 8, 2024
1 parent abed841 commit 9e6f62e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion spec/datadog/ci/contrib/rspec/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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\"]"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9e6f62e

Please sign in to comment.