Skip to content

Commit

Permalink
fix sporadic thread_safety test failure
Browse files Browse the repository at this point in the history
For this test, the spawned thread was ending after the main block was running

When the main block quit, it undefined the method on the class.
The threaded class kept calling the method (now undefined) and threw an exception
because the method was no longer defined.

solution is to wait for the thread to finish before exiting and undefining the method
  • Loading branch information
kbrock committed Feb 29, 2024
1 parent c574a2c commit 84883a9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion spec/core_ext/module/cache_with_timeout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
# clears the current value, the other thread could get nil.
test_class.cache_with_timeout(:thread_safety) { 2 }

Thread.new do
t = Thread.new do
10000.times do
test_class.thread_safety(true)
end
Expand All @@ -172,6 +172,7 @@
10000.times do
expect(test_class.thread_safety).to eq(2)
end
t.join
end
end
end

0 comments on commit 84883a9

Please sign in to comment.