Tests: use mutex with multitthreaded Ruby hooks.

This commit fixes a rare crash that can occur when File.write is
called by many threads.
This commit is contained in:
Oisin Canty
2021-07-21 14:53:33 +00:00
parent f27fbd9b4d
commit 1f2ba4dca8
3 changed files with 15 additions and 3 deletions

View File

@@ -1,9 +1,13 @@
require 'securerandom'
@mutex = Mutex.new
on_worker_boot do
File.write("./cookie_worker_boot.#{SecureRandom.hex}", "worker booted")
end
on_thread_boot do
File.write("./cookie_thread_boot.#{SecureRandom.hex}", "thread booted")
@mutex.synchronize do
File.write("./cookie_thread_boot.#{SecureRandom.hex}", "thread booted")
end
end