Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Aug 8, 2024
1 parent fc4bf35 commit d5d98fd
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 231 deletions.
14 changes: 5 additions & 9 deletions lib/datadog/core/crashtracking/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def self.build(settings, agent_settings, logger:)
agent_base_url = AgentBaseUrl.resolve(agent_settings)
logger.warn('Missing agent base URL; cannot enable crash tracking') unless agent_base_url

ld_library_path = Libdatadog.ld_library_path
ld_library_path = ::Libdatadog.ld_library_path
logger.warn('Missing ld_library_path; cannot enable crash tracking') unless ld_library_path

path_to_crashtracking_receiver_binary = Libdatadog.path_to_crashtracking_receiver_binary
path_to_crashtracking_receiver_binary = ::Libdatadog.path_to_crashtracking_receiver_binary
unless path_to_crashtracking_receiver_binary
logger.warn('Missing path_to_crashtracking_receiver_binary; cannot enable crash tracking')
end
Expand All @@ -61,20 +61,16 @@ def initialize(tags:, agent_base_url:, ld_library_path:, path_to_crashtracking_r
end

def start
Datadog::Core::Utils::AtForkMonkeyPatch.apply!
Utils::AtForkMonkeyPatch.apply!

start_or_update_on_fork(action: :start)
reset_after_fork
end

def reset_after_fork
ONLY_ONCE.run do
if Process.respond_to?(:datadog_at_fork)
Process.datadog_at_fork(:child) do
start_or_update_on_fork(action: :update_on_fork)
end
else
logger.debug 'Unexpected: At fork hooks not available'
Utils::AtForkMonkeyPatch.at_fork(:child) do
start_or_update_on_fork(action: :update_on_fork)
end
end
end
Expand Down
28 changes: 27 additions & 1 deletion sig/datadog/core/utils/at_fork_monkey_patch.rbs
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
# TODO
module Datadog
module Core
module Utils
module AtForkMonkeyPatch
AT_FORK_CHILD_BLOCKS: ::Array[untyped]

def self.supported?: () -> untyped

def self.apply!: () -> (false | true)

def self.run_at_fork_blocks: (untyped stage) -> untyped

def self.at_fork: (untyped stage) ?{ () -> untyped } -> true

module KernelMonkeyPatch
def fork: () ?{ () -> untyped } -> untyped
end

module ProcessMonkeyPatch
def _fork: () -> untyped

def daemon: (*untyped args) -> untyped
end
end
end
end
end
Loading

0 comments on commit d5d98fd

Please sign in to comment.