-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto instrumentation tests for knapsack
- Loading branch information
1 parent
c184f56
commit a8d7c5c
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
spec/datadog/ci/contrib/knapsack_auto_instrument/instrumentation_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
RSpec.describe "Knapsack Pro runner when Datadog::CI is auto instrumented" do | ||
let(:integration) { Datadog::CI::Contrib::Instrumentation.fetch_integration(:rspec) } | ||
|
||
include_context "CI mode activated" do | ||
let(:integration_name) { :no_instrument } | ||
end | ||
|
||
before do | ||
require_relative "../../../../../lib/datadog/ci/auto_instrument" | ||
|
||
require "fileutils" | ||
require "knapsack_pro" | ||
|
||
expect(Datadog::CI).to receive(:start_test_session).never | ||
expect(Datadog::CI).to receive(:start_test_module).never | ||
expect(Datadog::CI).to receive(:start_test_suite).never | ||
expect(Datadog::CI).to receive(:start_test).never | ||
|
||
allow_any_instance_of(Datadog::Core::Remote::Negotiation).to( | ||
receive(:endpoint?).with("/evp_proxy/v4/").and_return(true) | ||
) | ||
|
||
allow(Datadog::CI::Utils::TestRun).to receive(:command).and_return("knapsack:queue:rspec") | ||
|
||
allow_any_instance_of(KnapsackPro::Runners::Queue::RSpecRunner).to receive(:test_file_paths).and_return( | ||
["./spec/datadog/ci/contrib/knapsack_rspec/suite_under_test/some_test_rspec.rb"], | ||
[] | ||
) | ||
|
||
# raise to prevent Knapsack from running Kernel.exit(0) | ||
allow(KnapsackPro::Report).to receive(:save_node_queue_to_api).and_raise(ArgumentError) | ||
end | ||
|
||
it "instruments this rspec session" do | ||
with_new_rspec_environment do | ||
ClimateControl.modify( | ||
"KNAPSACK_PRO_CI_NODE_BUILD_ID" => "144", | ||
"KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC" => "example_token", | ||
"KNAPSACK_PRO_FIXED_QUEUE_SPLIT" => "true", | ||
"KNAPSACK_PRO_QUEUE_ID" => nil | ||
) do | ||
KnapsackPro::Adapters::RSpecAdapter.bind | ||
KnapsackPro::Runners::Queue::RSpecRunner.run("", devnull, devnull) | ||
rescue ArgumentError | ||
# suppress invalid API key error | ||
end | ||
end | ||
|
||
# test session and module traced | ||
expect(test_session_span).not_to be_nil | ||
expect(test_session_span).to have_test_tag(:framework, "rspec") | ||
expect(test_session_span).to have_test_tag(:framework_version, integration.version.to_s) | ||
|
||
expect(test_module_span).not_to be_nil | ||
|
||
# test session and module are failed | ||
expect([test_session_span, test_module_span]).to all have_fail_status | ||
|
||
# single test suite span | ||
expect(test_suite_spans).to have(1).item | ||
expect(test_suite_spans.first).to have_test_tag(:status, Datadog::CI::Ext::Test::Status::FAIL) | ||
expect(test_suite_spans.first).to have_test_tag( | ||
:suite, | ||
"SomeTest at ./spec/datadog/ci/contrib/knapsack_rspec/suite_under_test/some_test_rspec.rb" | ||
) | ||
|
||
# there is test span for every test case | ||
expect(test_spans).to have(2).items | ||
# test spans belong to a single test suite | ||
expect(test_spans).to have_unique_tag_values_count(:test_suite_id, 1) | ||
expect(test_spans).to have_tag_values_no_order( | ||
:status, | ||
[Datadog::CI::Ext::Test::Status::FAIL, Datadog::CI::Ext::Test::Status::PASS] | ||
) | ||
|
||
# every test span is connected to test module and test session | ||
expect(test_spans).to all have_test_tag(:test_module_id) | ||
expect(test_spans).to all have_test_tag(:test_session_id) | ||
end | ||
end |