Skip to content

Commit a8d7c5c

Browse files
committed
auto instrumentation tests for knapsack
1 parent c184f56 commit a8d7c5c

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

Rakefile

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ TEST_METADATA = {
7979
"knapsack_rspec" => {
8080
"knapsack_pro-7-rspec-3" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ❌ jruby"
8181
},
82+
"knapsack_auto_instrument" => {
83+
"knapsack_pro-7-rspec-3" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ❌ jruby"
84+
},
8285
"selenium" => {
8386
"selenium-4-capybara-3" => "❌ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ❌ 3.4 / ✅ jruby"
8487
},
@@ -157,6 +160,7 @@ namespace :spec do
157160
ci_queue_minitest
158161
ci_queue_rspec
159162
knapsack_rspec
163+
knapsack_auto_instrument
160164
selenium timecop
161165
].each do |contrib|
162166
desc "" # "Explicitly hiding from `rake -T`"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
RSpec.describe "Knapsack Pro runner when Datadog::CI is auto instrumented" do
2+
let(:integration) { Datadog::CI::Contrib::Instrumentation.fetch_integration(:rspec) }
3+
4+
include_context "CI mode activated" do
5+
let(:integration_name) { :no_instrument }
6+
end
7+
8+
before do
9+
require_relative "../../../../../lib/datadog/ci/auto_instrument"
10+
11+
require "fileutils"
12+
require "knapsack_pro"
13+
14+
expect(Datadog::CI).to receive(:start_test_session).never
15+
expect(Datadog::CI).to receive(:start_test_module).never
16+
expect(Datadog::CI).to receive(:start_test_suite).never
17+
expect(Datadog::CI).to receive(:start_test).never
18+
19+
allow_any_instance_of(Datadog::Core::Remote::Negotiation).to(
20+
receive(:endpoint?).with("/evp_proxy/v4/").and_return(true)
21+
)
22+
23+
allow(Datadog::CI::Utils::TestRun).to receive(:command).and_return("knapsack:queue:rspec")
24+
25+
allow_any_instance_of(KnapsackPro::Runners::Queue::RSpecRunner).to receive(:test_file_paths).and_return(
26+
["./spec/datadog/ci/contrib/knapsack_rspec/suite_under_test/some_test_rspec.rb"],
27+
[]
28+
)
29+
30+
# raise to prevent Knapsack from running Kernel.exit(0)
31+
allow(KnapsackPro::Report).to receive(:save_node_queue_to_api).and_raise(ArgumentError)
32+
end
33+
34+
it "instruments this rspec session" do
35+
with_new_rspec_environment do
36+
ClimateControl.modify(
37+
"KNAPSACK_PRO_CI_NODE_BUILD_ID" => "144",
38+
"KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC" => "example_token",
39+
"KNAPSACK_PRO_FIXED_QUEUE_SPLIT" => "true",
40+
"KNAPSACK_PRO_QUEUE_ID" => nil
41+
) do
42+
KnapsackPro::Adapters::RSpecAdapter.bind
43+
KnapsackPro::Runners::Queue::RSpecRunner.run("", devnull, devnull)
44+
rescue ArgumentError
45+
# suppress invalid API key error
46+
end
47+
end
48+
49+
# test session and module traced
50+
expect(test_session_span).not_to be_nil
51+
expect(test_session_span).to have_test_tag(:framework, "rspec")
52+
expect(test_session_span).to have_test_tag(:framework_version, integration.version.to_s)
53+
54+
expect(test_module_span).not_to be_nil
55+
56+
# test session and module are failed
57+
expect([test_session_span, test_module_span]).to all have_fail_status
58+
59+
# single test suite span
60+
expect(test_suite_spans).to have(1).item
61+
expect(test_suite_spans.first).to have_test_tag(:status, Datadog::CI::Ext::Test::Status::FAIL)
62+
expect(test_suite_spans.first).to have_test_tag(
63+
:suite,
64+
"SomeTest at ./spec/datadog/ci/contrib/knapsack_rspec/suite_under_test/some_test_rspec.rb"
65+
)
66+
67+
# there is test span for every test case
68+
expect(test_spans).to have(2).items
69+
# test spans belong to a single test suite
70+
expect(test_spans).to have_unique_tag_values_count(:test_suite_id, 1)
71+
expect(test_spans).to have_tag_values_no_order(
72+
:status,
73+
[Datadog::CI::Ext::Test::Status::FAIL, Datadog::CI::Ext::Test::Status::PASS]
74+
)
75+
76+
# every test span is connected to test module and test session
77+
expect(test_spans).to all have_test_tag(:test_module_id)
78+
expect(test_spans).to all have_test_tag(:test_session_id)
79+
end
80+
end

0 commit comments

Comments
 (0)