Skip to content

Commit

Permalink
instrumentation spec for minitest suite with ci-queue runner
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jan 22, 2024
1 parent fffc2fe commit 897abcc
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
15 changes: 15 additions & 0 deletions spec/datadog/ci/contrib/ci_queue_minitest/fake_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "minitest"

class SomeTest < Minitest::Test
def test_pass
assert true
end

def test_pass_other
assert true
end

def test_fail
assert false
end
end
74 changes: 72 additions & 2 deletions spec/datadog/ci/contrib/ci_queue_minitest/instrumentation_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,76 @@
require "minitest"
require "minitest/queue/runner"
require "fileutils"

RSpec.describe "Minitest instrumentation with Shopify's ci-queue runner" do
it { true }
include_context "CI mode activated" do
let(:integration_name) { :minitest }
let(:integration_options) { {service_name: "ltest"} }
end

let(:run_id) { rand(1..2**64 - 1) }
let(:queue_file_path) { "#{Dir.pwd}/tmp/ci-queue-#{run_id}" }

before do
Minitest::Runnable.reset
FileUtils.mkdir("log")

Minitest::Queue::Runner.invoke(
[
"-Ispec/datadog/ci/contrib/ci_queue_minitest",
"--build",
run_id.to_s,
"--worker",
"1",
"--queue",
"list:SomeTest%23test_pass:SomeTest%23test_pass_other:SomeTest%23test_fail",
"run",
"spec/datadog/ci/contrib/ci_queue_minitest/fake_test.rb"
]
)

Minitest.run([])
end

after do
FileUtils.rm_rf("log")
end

it "instruments this minitest session" do
# test session and module traced
expect(test_session_span).not_to be_nil
expect(test_module_span).not_to be_nil

# test session and module are failed
expect(test_session_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)
expect(test_module_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)

# test suite spans are created for each test as for parallel execution
expect(test_suite_spans).to have(3).items
expect(test_suite_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS) }.sort).to eq(
[Datadog::CI::Ext::Test::Status::FAIL, Datadog::CI::Ext::Test::Status::PASS, Datadog::CI::Ext::Test::Status::PASS]
)
expect(test_suite_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE) }.sort).to eq(
[
"SomeTest at spec/datadog/ci/contrib/ci_queue_minitest/fake_test.rb (test_fail concurrently)",
"SomeTest at spec/datadog/ci/contrib/ci_queue_minitest/fake_test.rb (test_pass concurrently)",
"SomeTest at spec/datadog/ci/contrib/ci_queue_minitest/fake_test.rb (test_pass_other concurrently)"
]
)

# there is test span for every test case
expect(test_spans).to have(3).items
# each test span has its own test suite
expect(test_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID) }.uniq).to have(3).items

# every test span is connected to test module and test session
test_spans.each do |test_span|
[Datadog::CI::Ext::Test::TAG_TEST_MODULE_ID, Datadog::CI::Ext::Test::TAG_TEST_SESSION_ID].each do |tag|
expect(test_span.get_tag(tag)).not_to be_nil
end
end
end
end
2 changes: 1 addition & 1 deletion spec/datadog/ci/contrib/minitest/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def test_foo
Minitest.run([])
end

context "single test passed" do
context "passed tests" do
before(:context) do
Minitest::Runnable.reset

Expand Down

0 comments on commit 897abcc

Please sign in to comment.