diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2023-06-14 18:20:09 +0100 |
---|---|---|
committer | Andrei Zeliankou <zelenkov@nginx.com> | 2023-06-14 18:20:09 +0100 |
commit | c183bd8749a19477390f8cb77efe5f6d223f0905 (patch) | |
tree | 4e821e9cb07be9a86bf2d442acb3ea6740ba5a99 /test/test_ruby_hooks.py | |
parent | c6d05191a069ac150cc8eb2bece75cf79c0a465a (diff) | |
download | unit-c183bd8749a19477390f8cb77efe5f6d223f0905.tar.gz unit-c183bd8749a19477390f8cb77efe5f6d223f0905.tar.bz2 |
Tests: get rid of classes in test files.
Class usage came from the unittest framework and it was always redundant
after migration to the pytest. This commit removes classes from files
containing tests to make them more readable and understandable.
Diffstat (limited to 'test/test_ruby_hooks.py')
-rw-r--r-- | test/test_ruby_hooks.py | 125 |
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' |