mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Make TracePoint#enable with block target current thread by default
If TracePoint#enable is passed a block, it previously started the trace on all threads. This changes it to trace only the current thread by default. To limit the scope of the change, the current thread is only used by default if target and target_line are both nil. You can pass target_thread: nil to enable tracing on all threads, to get the previous default behavior. Fixes [Bug #16889]
This commit is contained in:
parent
6d3f447aec
commit
9c1d32a7ad
Notes:
git
2022-03-30 10:15:03 +09:00
4 changed files with 70 additions and 39 deletions
|
@ -57,25 +57,50 @@ describe 'TracePoint#enable' do
|
|||
end.enable { event_name.should equal(:line) }
|
||||
end
|
||||
|
||||
it 'enables the trace object for any thread' do
|
||||
threads = []
|
||||
trace = TracePoint.new(:line) do |tp|
|
||||
# Runs on purpose on any Thread
|
||||
threads << Thread.current
|
||||
end
|
||||
|
||||
thread = nil
|
||||
trace.enable do
|
||||
line_event = true
|
||||
thread = Thread.new do
|
||||
event_in_other_thread = true
|
||||
ruby_version_is '3.2' do
|
||||
it 'enables the trace object for any thread' do
|
||||
threads = []
|
||||
trace = TracePoint.new(:line) do |tp|
|
||||
# Runs on purpose on any Thread
|
||||
threads << Thread.current
|
||||
end
|
||||
thread.join
|
||||
end
|
||||
|
||||
threads = threads.uniq
|
||||
threads.should.include?(Thread.current)
|
||||
threads.should.include?(thread)
|
||||
thread = nil
|
||||
trace.enable do
|
||||
line_event = true
|
||||
thread = Thread.new do
|
||||
event_in_other_thread = true
|
||||
end
|
||||
thread.join
|
||||
end
|
||||
|
||||
threads = threads.uniq
|
||||
threads.should.include?(Thread.current)
|
||||
threads.should_not.include?(thread)
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.2' do
|
||||
it 'enables the trace object for any thread' do
|
||||
threads = []
|
||||
trace = TracePoint.new(:line) do |tp|
|
||||
# Runs on purpose on any Thread
|
||||
threads << Thread.current
|
||||
end
|
||||
|
||||
thread = nil
|
||||
trace.enable do
|
||||
line_event = true
|
||||
thread = Thread.new do
|
||||
event_in_other_thread = true
|
||||
end
|
||||
thread.join
|
||||
end
|
||||
|
||||
threads = threads.uniq
|
||||
threads.should.include?(Thread.current)
|
||||
threads.should.include?(thread)
|
||||
end
|
||||
end
|
||||
|
||||
it 'can accept arguments within a block but it should not yield arguments' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue