Skip to content

Commit d09539b

Browse files
committed
Fix race condition
1 parent 64a6809 commit d09539b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/power_assert.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ def initialize(assertion_proc, assertion_method)
6565
@message ||= build_assertion_message(@line || '', methods || [], return_values, refs || [], assertion_proc.binding).freeze
6666
}
6767
@proc_local_variables = assertion_proc.binding.eval('local_variables').map(&:to_s)
68+
target_thread = Thread.current
6869
@trace = TracePoint.new(:return, :c_return) do |tp|
6970
next if method_ids and ! method_ids.include?(tp.method_id)
7071
locs = tp.binding.eval('caller_locations')
7172
current_diff = locs.length - @base_caller_length
7273
target_diff = TARGET_CALLER_DIFF[tp.event]
7374
is_target_bmethod = current_diff < target_diff
74-
if is_target_bmethod or current_diff == target_diff
75+
if (is_target_bmethod or current_diff == target_diff) and Thread.current == target_thread
7576
idx = target_diff - TARGET_INDEX_OFFSET[is_target_bmethod ? :bmethod : :method]
7677
unless path
7778
path = locs[idx].path

0 commit comments

Comments
 (0)