Class: Datadog::CI::TestVisibility::Store::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ci/test_visibility/store/process.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initializeProcess

Returns a new instance of Process.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 12

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

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

  # small copies of id, name and some tags: store them in the current process to set session/module context
  # for any spans faster
  @readonly_test_session = nil
  @readonly_test_module = nil
end

Instance Method Details

#active_test_moduleObject



52
53
54
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 52

def active_test_module
  @mutex.synchronize { @test_module }
end

#active_test_sessionObject



56
57
58
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 56

def active_test_session
  @mutex.synchronize { @test_session }
end

#active_test_suite(test_suite_name) ⇒ Object



60
61
62
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 60

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

#deactivate_test_module!Object



75
76
77
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 75

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

#deactivate_test_session!Object



71
72
73
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 71

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

#deactivate_test_suite!(test_suite_name) ⇒ Object



79
80
81
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 79

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

#fetch_or_activate_test_module(&block) ⇒ Object



40
41
42
43
44
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 40

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

#fetch_or_activate_test_session(&block) ⇒ Object



46
47
48
49
50
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 46

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



26
27
28
29
30
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 26

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

#fetch_single_test_suiteObject



32
33
34
35
36
37
38
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 32

def fetch_single_test_suite
  @mutex.synchronize do
    return nil if @test_suites.empty? || @test_suites.size > 1

    @test_suites.values.first
  end
end

#readonly_test_moduleObject



87
88
89
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 87

def readonly_test_module
  @mutex.synchronize { @readonly_test_module }
end

#readonly_test_sessionObject



83
84
85
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 83

def readonly_test_session
  @mutex.synchronize { @readonly_test_session }
end

#set_readonly_test_module(remote_test_module) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 99

def set_readonly_test_module(remote_test_module)
  return if remote_test_module.nil?

  @mutex.synchronize do
    @readonly_test_module = Datadog::CI::ReadonlyTestModule.new(remote_test_module)
  end
end

#set_readonly_test_session(remote_test_session) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 91

def set_readonly_test_session(remote_test_session)
  return if remote_test_session.nil?

  @mutex.synchronize do
    @readonly_test_session = Datadog::CI::ReadonlyTestSession.new(remote_test_session)
  end
end

#stop_all_test_suitesObject



64
65
66
67
68
69
# File 'lib/datadog/ci/test_visibility/store/process.rb', line 64

def stop_all_test_suites
  @mutex.synchronize do
    @test_suites.each_value(&:finish)
    @test_suites.clear
  end
end