Skip to content

Commit

Permalink
Make this concurrency test more robust
Browse files Browse the repository at this point in the history
This test has never failed, but it has a race condition on paper.
With this coordination the race condition is gone.

Thanks to @eregon.
  • Loading branch information
fxn committed Aug 28, 2021
1 parent f81a95a commit 016404c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/lib/zeitwerk/test_concurrency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

class TestConcurrency < LoaderTest
test "constant definition is synchronized" do
$ensure_M_is_autoloaded_by_the_thread = Queue.new

files = [["m.rb", <<-EOS]]
module M
$ensure_M_is_autoloaded_by_the_thread << true
sleep 0.5
def self.works?
Expand All @@ -13,6 +16,7 @@ def self.works?
EOS
with_setup(files) do
t = Thread.new { M }
$ensure_M_is_autoloaded_by_the_thread.pop()
assert M.works?
t.join
end
Expand Down

0 comments on commit 016404c

Please sign in to comment.