From 8c83652c2a0ad7386e27a9ea595c996d3dce018c Mon Sep 17 00:00:00 2001 From: Oisin Canty Date: Fri, 2 Jul 2021 13:00:57 +0000 Subject: Tests: Ruby hooks. --- test/ruby/hooks/multiple.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/ruby/hooks/multiple.rb (limited to 'test/ruby/hooks/multiple.rb') diff --git a/test/ruby/hooks/multiple.rb b/test/ruby/hooks/multiple.rb new file mode 100644 index 00000000..295b46a9 --- /dev/null +++ b/test/ruby/hooks/multiple.rb @@ -0,0 +1,9 @@ +require 'securerandom' + +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") +end -- cgit From 1f2ba4dca8c67442e19367ac7f1f96dbff6457ff Mon Sep 17 00:00:00 2001 From: Oisin Canty Date: Wed, 21 Jul 2021 14:53:33 +0000 Subject: Tests: use mutex with multitthreaded Ruby hooks. This commit fixes a rare crash that can occur when File.write is called by many threads. --- test/ruby/hooks/multiple.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test/ruby/hooks/multiple.rb') diff --git a/test/ruby/hooks/multiple.rb b/test/ruby/hooks/multiple.rb index 295b46a9..b1b659a5 100644 --- a/test/ruby/hooks/multiple.rb +++ b/test/ruby/hooks/multiple.rb @@ -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 -- cgit