summaryrefslogtreecommitdiffhomepage
path: root/test/test_ruby_hooks.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/test_ruby_hooks.py125
1 files changed, 65 insertions, 60 deletions
diff --git a/test/test_ruby_hooks.py b/test/test_ruby_hooks.py
index 6bd4c808..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'}}
+client = ApplicationRuby()
-class TestRubyHooks(TestApplicationRuby):
- 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'