Skip to content

Commit

Permalink
[NO-TICKET] Re-add at_fork hook testing for crashtracking
Browse files Browse the repository at this point in the history
**What does this PR do?**

This PR re-adds the spec that validates that the at_fork hook in
crashtracking correctly picks up the latest instance of the
component.

**Motivation:**

Since this is quite a weird corner case, I think it's important to
have a spec to cover it.

**Additional Notes:**

This spec was temporarily removed in #3970 with the intention of
re-adding it in #3983 but we kinda forgot about it.

**How to test the change?**

Check this test passes as-is, and fails if you change the
`update_on_fork` call to use `self`, for instance.
  • Loading branch information
ivoanjo committed Dec 9, 2024
1 parent c07a8d4 commit d19b07f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions spec/datadog/core/crashtracking/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,35 @@
expect(crash_report_message[:os_info]).to_not be_empty
end
end

context 'when forked' do
# This tests that the callback registered with `Utils::AtForkMonkeyPatch.at_fork`
# does not contain a stale instance of the crashtracker component.
it 'ensures the latest configuration applied' do
allow(described_class).to receive(:_native_start_or_update_on_fork)

# `Datadog.configure` to trigger crashtracking component reinstantiation,
# a callback is first registered with `Utils::AtForkMonkeyPatch.at_fork`,
# but not with the second `Datadog.configure` invokation.
Datadog.configure do |c|
c.agent.host = 'example.com'
end

Datadog.configure do |c|
c.agent.host = 'google.com'
c.agent.port = 12345
end

expect_in_fork do
expect(described_class).to have_received(:_native_start_or_update_on_fork).with(
hash_including(
action: :update_on_fork,
agent_base_url: 'http://google.com:12345/',
)
)
end
end
end
end
end

Expand Down

0 comments on commit d19b07f

Please sign in to comment.