Skip to content

Commit

Permalink
di delayed
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Jul 15, 2024
1 parent 5a63e37 commit 6ceefdc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/datadog/di/hook_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ def hook_line(file, line_no, &block)
# defined when the hook request is received.
attr_reader :definition_trace_point

def pending_methods
PENDING_METHODS
end

def instrumented_methods
INSTRUMENTED_METHODS
end

PENDING_METHODS = Concurrent::Map.new
INSTRUMENTED_METHODS = Concurrent::Map.new
INSTRUMENTED_LINES = Concurrent::Map.new
Expand Down
7 changes: 7 additions & 0 deletions spec/datadog/di/hook_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,19 @@ def hook_test_method_with_kwarg(kwarg:)
invoked = true
end).to be false

expect(manager.send(:pending_methods)[[:HookManagerTestLateDefinition, :test_method]]).to be_a(Proc)
expect(manager.send(:instrumented_methods)[[:HookManagerTestLateDefinition, :test_method]]).to be nil

class HookManagerTestLateDefinition
def test_method
42
end
end

# Method should now be hooked, and no longer pending
expect(manager.send(:pending_methods)[[:HookManagerTestLateDefinition, :test_method]]).to be nil
expect(manager.send(:instrumented_methods)[[:HookManagerTestLateDefinition, :test_method]]).to be_a(Integer)

expect(HookManagerTestLateDefinition.new.test_method).to eq 42

expect(invoked).to be true
Expand Down

0 comments on commit 6ceefdc

Please sign in to comment.