Class: Datadog::CI::Context::Global

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ci/context/global.rb

Overview

This context is shared between threads and represents the current test session and test module.

Instance Method Summary collapse

Constructor Details

#initializeGlobal

Returns a new instance of Global.



8
9
10
11
12
13
14
15
# File 'lib/datadog/ci/context/global.rb', line 8

def initialize
  # we are using Monitor instead of Mutex because it is reentrant
  @mutex = Monitor.new

  @test_session = nil
  @test_module = nil
  @test_suites = {}
end

Instance Method Details

#active_test_moduleObject



35
36
37
# File 'lib/datadog/ci/context/global.rb', line 35

def active_test_module
  @test_module
end

#active_test_sessionObject



39
40
41
# File 'lib/datadog/ci/context/global.rb', line 39

def active_test_session
  @test_session
end

#active_test_suite(test_suite_name) ⇒ Object



43
44
45
# File 'lib/datadog/ci/context/global.rb', line 43

def active_test_suite(test_suite_name)
  @mutex.synchronize { @test_suites[test_suite_name] }
end

#deactivate_test_module!Object



70
71
72
# File 'lib/datadog/ci/context/global.rb', line 70

def deactivate_test_module!
  @mutex.synchronize { @test_module = nil }
end

#deactivate_test_session!Object



66
67
68
# File 'lib/datadog/ci/context/global.rb', line 66

def deactivate_test_session!
  @mutex.synchronize { @test_session = nil }
end

#deactivate_test_suite!(test_suite_name) ⇒ Object



74
75
76
# File 'lib/datadog/ci/context/global.rb', line 74

def deactivate_test_suite!(test_suite_name)
  @mutex.synchronize { @test_suites.delete(test_suite_name) }
end

#fetch_or_activate_test_module(&block) ⇒ Object



23
24
25
26
27
# File 'lib/datadog/ci/context/global.rb', line 23

def fetch_or_activate_test_module(&block)
  @mutex.synchronize do
    @test_module ||= block.call
  end
end

#fetch_or_activate_test_session(&block) ⇒ Object



29
30
31
32
33
# File 'lib/datadog/ci/context/global.rb', line 29

def fetch_or_activate_test_session(&block)
  @mutex.synchronize do
    @test_session ||= block.call
  end
end

#fetch_or_activate_test_suite(test_suite_name, &block) ⇒ Object



17
18
19
20
21
# File 'lib/datadog/ci/context/global.rb', line 17

def fetch_or_activate_test_suite(test_suite_name, &block)
  @mutex.synchronize do
    @test_suites[test_suite_name] ||= block.call
  end
end

#inheritable_session_tagsObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/datadog/ci/context/global.rb', line 55

def inheritable_session_tags
  @mutex.synchronize do
    test_session = @test_session
    if test_session
      test_session.inheritable_tags
    else
      {}
    end
  end
end

#serviceObject



47
48
49
50
51
52
53
# File 'lib/datadog/ci/context/global.rb', line 47

def service
  @mutex.synchronize do
    # thank you RBS for this weirdness
    test_session = @test_session
    test_session.service if test_session
  end
end