-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement local context to keep track of current test being executed
- Loading branch information
1 parent
a1a2857
commit 4e70b4b
Showing
24 changed files
with
481 additions
and
178 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 was deleted.
Oops, something went wrong.
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,59 @@ | ||
# frozen_string_literal: true | ||
|
||
require "datadog/core/utils/sequence" | ||
|
||
module Datadog | ||
module CI | ||
module Context | ||
class Local | ||
def initialize | ||
@key = "datadog_ci_active_test_#{Local.next_instance_id}" | ||
end | ||
|
||
def activate_test!(test) | ||
raise "Nested tests are not supported. Currently active test: #{active_test}" unless active_test.nil? | ||
|
||
if block_given? | ||
begin | ||
self.active_test = test | ||
yield | ||
ensure | ||
self.active_test = nil | ||
end | ||
else | ||
self.active_test = test | ||
end | ||
end | ||
|
||
def deactivate_test!(test) | ||
return if active_test.nil? | ||
|
||
if active_test == test | ||
self.active_test = nil | ||
else | ||
raise "Trying to deactivate test #{test}, but currently active test is #{active_test}" | ||
end | ||
end | ||
|
||
def active_test | ||
Thread.current[@key] | ||
end | ||
|
||
UNIQUE_INSTANCE_MUTEX = Mutex.new | ||
UNIQUE_INSTANCE_GENERATOR = Datadog::Core::Utils::Sequence.new | ||
|
||
private_constant :UNIQUE_INSTANCE_MUTEX, :UNIQUE_INSTANCE_GENERATOR | ||
|
||
def self.next_instance_id | ||
UNIQUE_INSTANCE_MUTEX.synchronize { UNIQUE_INSTANCE_GENERATOR.next } | ||
end | ||
|
||
private | ||
|
||
def active_test=(test) | ||
Thread.current[@key] = test | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -46,6 +46,10 @@ def finish | |
tracer_span.finish | ||
end | ||
|
||
def span_type | ||
tracer_span.type | ||
end | ||
|
||
private | ||
|
||
def set_tags!(tags) | ||
|
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,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "span" | ||
|
||
module Datadog | ||
module CI | ||
class Test < Span | ||
def finish | ||
super | ||
|
||
CI.deactivate_test(self) | ||
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
Oops, something went wrong.