summaryrefslogtreecommitdiffhomepage
path: root/test/test_ruby_hooks.py
diff options
context:
space:
mode:
authorKonstantin Pavlov <thresh@nginx.com>2023-08-31 09:41:46 -0700
committerKonstantin Pavlov <thresh@nginx.com>2023-08-31 09:41:46 -0700
commitc45c8919c7232eb20023484f6d1fc9f1f50395d8 (patch)
treecc12eb307c1611494948645e4b487fa06495c3d2 /test/test_ruby_hooks.py
parent88c90e1c351ab8c5bd487a5cd4b735014b08e271 (diff)
parent9b22b6957bc87b3df002d0bc691fdae6a20abdac (diff)
downloadunit-c45c8919c7232eb20023484f6d1fc9f1f50395d8.tar.gz
unit-c45c8919c7232eb20023484f6d1fc9f1f50395d8.tar.bz2
Merged with the default branch.1.31.0-1
Diffstat (limited to 'test/test_ruby_hooks.py')
-rw-r--r--test/test_ruby_hooks.py127
1 files changed, 66 insertions, 61 deletions
diff --git a/test/test_ruby_hooks.py b/test/test_ruby_hooks.py
index 078e5723..38893e47 100644
--- a/test/test_ruby_hooks.py
+++ b/test/test_ruby_hooks.py
@@ -1,94 +1,99 @@
-from unit.applications.lang.ruby import TestApplicationRuby
+from unit.applications.lang.ruby import ApplicationRuby
from unit.option import option
from unit.utils import waitforglob
+prerequisites = {'modules': {'ruby': 'all'}}
-class TestRubyHooks(TestApplicationRuby):
- prerequisites = {'modules': {'ruby': 'all'}}
+client = ApplicationRuby()
- def _wait_cookie(self, pattern, count):
- return waitforglob(
- f'{option.temp_dir}/ruby/hooks/cookie_{pattern}', count
- )
- def test_ruby_hooks_eval(self):
- processes = 2
+def wait_cookie(pattern, count):
+ return waitforglob(f'{option.temp_dir}/ruby/hooks/cookie_{pattern}', count)
- self.load('hooks', processes=processes, hooks='eval.rb')
- hooked = self._wait_cookie('eval.*', processes)
+def test_ruby_hooks_eval():
+ processes = 2
- assert hooked, 'hooks evaluated'
+ client.load('hooks', processes=processes, hooks='eval.rb')
- def test_ruby_hooks_on_worker_boot(self):
- processes = 2
+ hooked = wait_cookie('eval.*', processes)
- self.load('hooks', processes=processes, hooks='on_worker_boot.rb')
+ assert hooked, 'hooks evaluated'
- hooked = self._wait_cookie('worker_boot.*', processes)
- assert hooked, 'on_worker_boot called'
+def test_ruby_hooks_on_worker_boot():
+ processes = 2
- def test_ruby_hooks_on_worker_shutdown(self):
- processes = 2
+ client.load('hooks', processes=processes, hooks='on_worker_boot.rb')
- self.load('hooks', processes=processes, hooks='on_worker_shutdown.rb')
+ hooked = wait_cookie('worker_boot.*', processes)
- assert self.get()['status'] == 200, 'app response'
+ assert hooked, 'on_worker_boot called'
- self.load('empty')
- hooked = self._wait_cookie('worker_shutdown.*', processes)
+def test_ruby_hooks_on_worker_shutdown():
+ processes = 2
- assert hooked, 'on_worker_shutdown called'
+ client.load('hooks', processes=processes, hooks='on_worker_shutdown.rb')
- def test_ruby_hooks_on_thread_boot(self):
- processes = 1
- threads = 2
+ assert client.get()['status'] == 200, 'app response'
- self.load(
- 'hooks',
- processes=processes,
- threads=threads,
- hooks='on_thread_boot.rb',
- )
+ client.load('empty')
- hooked = self._wait_cookie('thread_boot.*', processes * threads)
+ hooked = wait_cookie('worker_shutdown.*', processes)
- assert hooked, 'on_thread_boot called'
+ assert hooked, 'on_worker_shutdown called'
- def test_ruby_hooks_on_thread_shutdown(self):
- processes = 1
- threads = 2
- self.load(
- 'hooks',
- processes=processes,
- threads=threads,
- hooks='on_thread_shutdown.rb',
- )
+def test_ruby_hooks_on_thread_boot():
+ processes = 1
+ threads = 2
- assert self.get()['status'] == 200, 'app response'
+ client.load(
+ 'hooks',
+ processes=processes,
+ threads=threads,
+ hooks='on_thread_boot.rb',
+ )
- self.load('empty')
+ hooked = wait_cookie('thread_boot.*', processes * threads)
- hooked = self._wait_cookie('thread_shutdown.*', processes * threads)
+ assert hooked, 'on_thread_boot called'
- assert hooked, 'on_thread_shutdown called'
- def test_ruby_hooks_multiple(self):
- processes = 1
- threads = 1
+def test_ruby_hooks_on_thread_shutdown():
+ processes = 1
+ threads = 2
- self.load(
- 'hooks',
- processes=processes,
- threads=threads,
- hooks='multiple.rb',
- )
+ client.load(
+ 'hooks',
+ processes=processes,
+ threads=threads,
+ hooks='on_thread_shutdown.rb',
+ )
- hooked = self._wait_cookie('worker_boot.*', processes)
- assert hooked, 'on_worker_boot called'
+ assert client.get()['status'] == 200, 'app response'
- hooked = self._wait_cookie('thread_boot.*', threads)
- assert hooked, 'on_thread_boot called'
+ client.load('empty')
+
+ hooked = wait_cookie('thread_shutdown.*', processes * threads)
+
+ assert hooked, 'on_thread_shutdown called'
+
+
+def test_ruby_hooks_multiple():
+ processes = 1
+ threads = 1
+
+ client.load(
+ 'hooks',
+ processes=processes,
+ threads=threads,
+ hooks='multiple.rb',
+ )
+
+ hooked = wait_cookie('worker_boot.*', processes)
+ assert hooked, 'on_worker_boot called'
+
+ hooked = wait_cookie('thread_boot.*', threads)
+ assert hooked, 'on_thread_boot called'