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' require 'securerandom'
@mutex = Mutex.new
on_worker_boot do on_worker_boot do
File.write("./cookie_worker_boot.#{SecureRandom.hex}", "worker booted") File.write("./cookie_worker_boot.#{SecureRandom.hex}", "worker booted")
end end
on_thread_boot do on_thread_boot do
@mutex.synchronize do
File.write("./cookie_thread_boot.#{SecureRandom.hex}", "thread booted") File.write("./cookie_thread_boot.#{SecureRandom.hex}", "thread booted")
end
end end

View File

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

View File

@@ -1,5 +1,9 @@
require 'securerandom' require 'securerandom'
@mutex = Mutex.new
on_thread_shutdown do on_thread_shutdown do
@mutex.synchronize do
File.write("./cookie_thread_shutdown.#{SecureRandom.hex}", "shutdown") File.write("./cookie_thread_shutdown.#{SecureRandom.hex}", "shutdown")
end
end end