diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2023-05-29 16:45:49 +0100 |
---|---|---|
committer | Andrei Zeliankou <zelenkov@nginx.com> | 2023-05-29 16:45:49 +0100 |
commit | 31ff94add9c4043a753683d9e8b68733c69aa1ac (patch) | |
tree | 1737c36a2641129a4de775c6058cc07b9cdca0f6 /test/test_settings.py | |
parent | f55818059c01ff9e61bee8107ed1389fe272a787 (diff) | |
download | unit-31ff94add9c4043a753683d9e8b68733c69aa1ac.tar.gz unit-31ff94add9c4043a753683d9e8b68733c69aa1ac.tar.bz2 |
Tests: more fixtures.
Common methods from applications/proto.py converted to the fixtures.
sysctl check moved to the specific file where it is using.
Some options moved to the constructor to have early access.
Diffstat (limited to 'test/test_settings.py')
-rw-r--r-- | test/test_settings.py | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/test/test_settings.py b/test/test_settings.py index 857bddcc..4b139069 100644 --- a/test/test_settings.py +++ b/test/test_settings.py @@ -1,15 +1,25 @@ import re import socket +import subprocess import time import pytest from unit.applications.lang.python import TestApplicationPython -from unit.utils import sysctl class TestSettings(TestApplicationPython): prerequisites = {'modules': {'python': 'any'}} + def sysctl(self): + try: + out = subprocess.check_output( + ['sysctl', '-a'], stderr=subprocess.STDOUT + ).decode() + except FileNotFoundError: + pytest.skip('requires sysctl') + + return out + def test_settings_large_header_buffer_size(self): self.load('empty') @@ -263,7 +273,7 @@ Connection: close return data - sysctl_out = sysctl() + sysctl_out = self.sysctl() values = re.findall( r'net.core.[rw]mem_(?:max|default).*?(\d+)', sysctl_out ) @@ -409,15 +419,15 @@ Connection: close assert resp['status'] == 200, 'status 4' assert resp['body'] == body, 'body 4' - def test_settings_log_route(self): + def test_settings_log_route(self, findall, search_in_file, wait_for_record): def count_fallbacks(): - return len(self.findall(r'"fallback" taken')) + return len(findall(r'"fallback" taken')) def check_record(template): - assert self.search_in_log(template) is not None + assert search_in_file(template) is not None def check_no_record(template): - assert self.search_in_log(template) is None + assert search_in_file(template) is None def template_req_line(url): return rf'\[notice\].*http request line "GET {url} HTTP/1\.1"' @@ -430,8 +440,8 @@ Connection: close def wait_for_request_log(status, uri, route): assert self.get(url=uri)['status'] == status - assert self.wait_for_record(template_req_line(uri)) is not None - assert self.wait_for_record(template_selected(route)) is not None + assert wait_for_record(template_req_line(uri)) is not None + assert wait_for_record(template_selected(route)) is not None # routes array @@ -559,6 +569,6 @@ Connection: close # total - assert len(self.findall(r'\[notice\].*http request line')) == 7 - assert len(self.findall(r'\[notice\].*selected')) == 10 - assert len(self.findall(r'\[info\].*discarded')) == 2 + assert len(findall(r'\[notice\].*http request line')) == 7 + assert len(findall(r'\[notice\].*selected')) == 10 + assert len(findall(r'\[info\].*discarded')) == 2 |