Skip to content

Commit

Permalink
DEBUG-3316 verify code tracking works in forked processes (#4284)
Browse files Browse the repository at this point in the history
  • Loading branch information
p-datadog authored Jan 14, 2025
1 parent 5235204 commit 08743d9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
37 changes: 37 additions & 0 deletions spec/datadog/di/code_tracker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,43 @@
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")

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
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
Expand Down
2 changes: 2 additions & 0 deletions spec/datadog/di/code_tracker_test_class_4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class CodeTrackerTestClass4
end
2 changes: 2 additions & 0 deletions spec/datadog/di/code_tracker_test_class_5.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class CodeTrackerTestClass5
end

0 comments on commit 08743d9

Please sign in to comment.