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.
This commit is contained in:
Andrei Zeliankou
2023-06-14 18:20:09 +01:00
parent c6d05191a0
commit c183bd8749
84 changed files with 17455 additions and 16814 deletions

View File

@@ -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'