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/config.ru | 7 +++++++ test/ruby/hooks/eval.rb | 3 +++ test/ruby/hooks/multiple.rb | 9 +++++++++ test/ruby/hooks/on_thread_boot.rb | 5 +++++ test/ruby/hooks/on_thread_shutdown.rb | 5 +++++ test/ruby/hooks/on_worker_boot.rb | 5 +++++ test/ruby/hooks/on_worker_shutdown.rb | 5 +++++ 7 files changed, 39 insertions(+) create mode 100644 test/ruby/hooks/config.ru create mode 100644 test/ruby/hooks/eval.rb create mode 100644 test/ruby/hooks/multiple.rb create mode 100644 test/ruby/hooks/on_thread_boot.rb create mode 100644 test/ruby/hooks/on_thread_shutdown.rb create mode 100644 test/ruby/hooks/on_worker_boot.rb create mode 100644 test/ruby/hooks/on_worker_shutdown.rb (limited to 'test/ruby/hooks') diff --git a/test/ruby/hooks/config.ru b/test/ruby/hooks/config.ru new file mode 100644 index 00000000..f3069558 --- /dev/null +++ b/test/ruby/hooks/config.ru @@ -0,0 +1,7 @@ +app = Proc.new do |env| + ['200', { + 'Content-Length' => '0' + }, ['']] +end + +run app diff --git a/test/ruby/hooks/eval.rb b/test/ruby/hooks/eval.rb new file mode 100644 index 00000000..ce7329c1 --- /dev/null +++ b/test/ruby/hooks/eval.rb @@ -0,0 +1,3 @@ +require 'securerandom' + +File.write("./cookie_eval.#{SecureRandom.hex}", "evaluated") 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 diff --git a/test/ruby/hooks/on_thread_boot.rb b/test/ruby/hooks/on_thread_boot.rb new file mode 100644 index 00000000..1e05e248 --- /dev/null +++ b/test/ruby/hooks/on_thread_boot.rb @@ -0,0 +1,5 @@ +require 'securerandom' + +on_thread_boot do + File.write("./cookie_thread_boot.#{SecureRandom.hex}", "booted") +end diff --git a/test/ruby/hooks/on_thread_shutdown.rb b/test/ruby/hooks/on_thread_shutdown.rb new file mode 100644 index 00000000..e65c1b42 --- /dev/null +++ b/test/ruby/hooks/on_thread_shutdown.rb @@ -0,0 +1,5 @@ +require 'securerandom' + +on_thread_shutdown do + File.write("./cookie_thread_shutdown.#{SecureRandom.hex}", "shutdown") +end diff --git a/test/ruby/hooks/on_worker_boot.rb b/test/ruby/hooks/on_worker_boot.rb new file mode 100644 index 00000000..b6529f60 --- /dev/null +++ b/test/ruby/hooks/on_worker_boot.rb @@ -0,0 +1,5 @@ +require 'securerandom' + +on_worker_boot do + File.write("./cookie_worker_boot.#{SecureRandom.hex}", "booted") +end diff --git a/test/ruby/hooks/on_worker_shutdown.rb b/test/ruby/hooks/on_worker_shutdown.rb new file mode 100644 index 00000000..9ffaad93 --- /dev/null +++ b/test/ruby/hooks/on_worker_shutdown.rb @@ -0,0 +1,5 @@ +require 'securerandom' + +on_worker_shutdown do + File.write("./cookie_worker_shutdown.#{SecureRandom.hex}", "shutdown") +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 +++++- test/ruby/hooks/on_thread_boot.rb | 6 +++++- test/ruby/hooks/on_thread_shutdown.rb | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) (limited to 'test/ruby/hooks') 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 diff --git a/test/ruby/hooks/on_thread_boot.rb b/test/ruby/hooks/on_thread_boot.rb index 1e05e248..4f88424e 100644 --- a/test/ruby/hooks/on_thread_boot.rb +++ b/test/ruby/hooks/on_thread_boot.rb @@ -1,5 +1,9 @@ require 'securerandom' +@mutex = Mutex.new + on_thread_boot do - File.write("./cookie_thread_boot.#{SecureRandom.hex}", "booted") + @mutex.synchronize do + File.write("./cookie_thread_boot.#{SecureRandom.hex}", "booted") + end end diff --git a/test/ruby/hooks/on_thread_shutdown.rb b/test/ruby/hooks/on_thread_shutdown.rb index e65c1b42..d953b8b7 100644 --- a/test/ruby/hooks/on_thread_shutdown.rb +++ b/test/ruby/hooks/on_thread_shutdown.rb @@ -1,5 +1,9 @@ require 'securerandom' +@mutex = Mutex.new + on_thread_shutdown do - File.write("./cookie_thread_shutdown.#{SecureRandom.hex}", "shutdown") + @mutex.synchronize do + File.write("./cookie_thread_shutdown.#{SecureRandom.hex}", "shutdown") + end end -- cgit