-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from DataDog/anmarchenko/knapsack_pro_integra…
…tion [CIVIS-10061] Fix Knapsack Pro integration
- Loading branch information
Showing
17 changed files
with
189 additions
and
12 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
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
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
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
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module RSpec | ||
module KnapsackPro | ||
module Patcher | ||
def self.patch | ||
if defined?(::KnapsackPro::Extensions::RSpecExtension::Runner) && | ||
::RSpec::Core::Runner.ancestors.include?(::KnapsackPro::Extensions::RSpecExtension::Runner) | ||
# knapsack already patched rspec runner | ||
require_relative "runner" | ||
::RSpec::Core::Runner.include(KnapsackPro::Runner) | ||
else | ||
# knapsack didn't patch rspec runner yet | ||
require_relative "extension" | ||
::KnapsackPro::Extensions::RSpecExtension.include(KnapsackPro::Extension) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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
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
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
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,13 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module RSpec | ||
module KnapsackPro | ||
module Patcher | ||
def self.patch: () -> void | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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
79 changes: 79 additions & 0 deletions
79
spec/datadog/ci/contrib/knapsack_rspec_go/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,79 @@ | ||
require "knapsack_pro" | ||
require "fileutils" | ||
|
||
RSpec.describe "Knapsack Pro runner when Datadog::CI is configured during the knapsack run like in rspec_go rake task" do | ||
# Yields to a block in a new RSpec global context. All RSpec | ||
# test configuration and execution should be wrapped in this method. | ||
def with_new_rspec_environment | ||
old_configuration = ::RSpec.configuration | ||
old_world = ::RSpec.world | ||
::RSpec.configuration = ::RSpec::Core::Configuration.new | ||
::RSpec.world = ::RSpec::Core::World.new | ||
|
||
yield | ||
ensure | ||
::RSpec.configuration = old_configuration | ||
::RSpec.world = old_world | ||
end | ||
|
||
def devnull | ||
File.new("/dev/null", "w") | ||
end | ||
|
||
before do | ||
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_go/suite_under_test/some_test_rspec.rb"], | ||
[] | ||
) | ||
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("--require knapsack_helper", 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_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_go/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 |
13 changes: 13 additions & 0 deletions
13
spec/datadog/ci/contrib/knapsack_rspec_go/suite_under_test/some_test_rspec.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,13 @@ | ||
require "rspec" | ||
|
||
RSpec.describe "SomeTest" do | ||
context "nested" do | ||
it "foo" do | ||
# DO NOTHING | ||
end | ||
|
||
it "fails" do | ||
expect(1).to eq(2) | ||
end | ||
end | ||
end |
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
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,8 @@ | ||
# this file is required for knapsack unit tests | ||
|
||
Datadog.configure do |c| | ||
c.service = "knapsack_rspec_example" | ||
c.ci.enabled = true | ||
c.ci.git_metadata_upload_enabled = false | ||
c.ci.instrument :rspec | ||
end |
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
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 |
---|---|---|
|
@@ -12,6 +12,9 @@ module KnapsackPro | |
module Extensions | ||
module RSpecExtension | ||
def setup!: () -> void | ||
|
||
module Runner | ||
end | ||
end | ||
end | ||
end |
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