From ed878af9b61cd962ec6a8c50e2736bea7c87283c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 13 Jan 2025 15:49:25 -0500 Subject: [PATCH 1/2] DEBUG-3316 verify code tracking works in forked processes --- spec/datadog/di/code_tracker_spec.rb | 32 ++++++++++++++++++++ spec/datadog/di/code_tracker_test_class_4.rb | 2 ++ spec/datadog/di/code_tracker_test_class_5.rb | 2 ++ 3 files changed, 36 insertions(+) create mode 100644 spec/datadog/di/code_tracker_test_class_4.rb create mode 100644 spec/datadog/di/code_tracker_test_class_5.rb diff --git a/spec/datadog/di/code_tracker_spec.rb b/spec/datadog/di/code_tracker_spec.rb index 896eef6e6dc..a06af863d8e 100644 --- a/spec/datadog/di/code_tracker_spec.rb +++ b/spec/datadog/di/code_tracker_spec.rb @@ -97,6 +97,38 @@ expect(tracker.send(:registry)).to be_empty end end + + context 'when process forks' do + it 'continues tracking in the fork' do + # Load rspec assertion code + expect(1).to eq(1) + expect(1).to equal(1) + + expect(tracker.send(:registry)).to be_empty + tracker.start + + require_relative 'code_tracker_test_class_4' + expect(tracker.send(:registry).length).to eq(1) + path = tracker.send(:registry).to_a.dig(0, 0) + expect(File.basename(path)).to eq("code_tracker_test_class_4.rb") + + expect_in_fork do + expect(tracker.send(:registry).length).to eq(1) + path = tracker.send(:registry).to_a.dig(0, 0) + expect(File.basename(path)).to eq("code_tracker_test_class_4.rb") + end + + begin + Process.waitpid + rescue Errno::ECHILD + end + + # Verify parent did not change + expect(tracker.send(:registry).length).to eq(1) + path = tracker.send(:registry).to_a.dig(0, 0) + expect(File.basename(path)).to eq("code_tracker_test_class_4.rb") + end + end end describe "#active?" do diff --git a/spec/datadog/di/code_tracker_test_class_4.rb b/spec/datadog/di/code_tracker_test_class_4.rb new file mode 100644 index 00000000000..99c8cc88a08 --- /dev/null +++ b/spec/datadog/di/code_tracker_test_class_4.rb @@ -0,0 +1,2 @@ +class CodeTrackerTestClass4 +end diff --git a/spec/datadog/di/code_tracker_test_class_5.rb b/spec/datadog/di/code_tracker_test_class_5.rb new file mode 100644 index 00000000000..fd32977582e --- /dev/null +++ b/spec/datadog/di/code_tracker_test_class_5.rb @@ -0,0 +1,2 @@ +class CodeTrackerTestClass5 +end From 294d41f0aa5c9c2d910be8bd75083885019597e4 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 14 Jan 2025 10:21:19 -0500 Subject: [PATCH 2/2] put back in the assertion that was removed during debugging --- spec/datadog/di/code_tracker_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/datadog/di/code_tracker_spec.rb b/spec/datadog/di/code_tracker_spec.rb index a06af863d8e..053ce338783 100644 --- a/spec/datadog/di/code_tracker_spec.rb +++ b/spec/datadog/di/code_tracker_spec.rb @@ -116,6 +116,11 @@ expect(tracker.send(:registry).length).to eq(1) path = tracker.send(:registry).to_a.dig(0, 0) expect(File.basename(path)).to eq("code_tracker_test_class_4.rb") + + require_relative 'code_tracker_test_class_5' + expect(tracker.send(:registry).length).to eq(2) + path = tracker.send(:registry).to_a.dig(1, 0) + expect(File.basename(path)).to eq("code_tracker_test_class_5.rb") end begin