summaryrefslogtreecommitdiffhomepage
path: root/test/test_settings.py
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2023-06-14 18:20:09 +0100
committerAndrei Zeliankou <zelenkov@nginx.com>2023-06-14 18:20:09 +0100
commitc183bd8749a19477390f8cb77efe5f6d223f0905 (patch)
tree4e821e9cb07be9a86bf2d442acb3ea6740ba5a99 /test/test_settings.py
parentc6d05191a069ac150cc8eb2bece75cf79c0a465a (diff)
downloadunit-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_settings.py')
-rw-r--r--test/test_settings.py829
1 files changed, 421 insertions, 408 deletions
diff --git a/test/test_settings.py b/test/test_settings.py
index 0a48da5e..33180046 100644
--- a/test/test_settings.py
+++ b/test/test_settings.py
@@ -4,220 +4,194 @@ import subprocess
import time
import pytest
-from unit.applications.lang.python import TestApplicationPython
+from unit.applications.lang.python import ApplicationPython
prerequisites = {'modules': {'python': 'any'}}
+client = ApplicationPython()
-class TestSettings(TestApplicationPython):
- def sysctl(self):
- try:
- out = subprocess.check_output(
- ['sysctl', '-a'], stderr=subprocess.STDOUT
- ).decode()
- except FileNotFoundError:
- pytest.skip('requires sysctl')
- return out
+def sysctl():
+ try:
+ out = subprocess.check_output(
+ ['sysctl', '-a'], stderr=subprocess.STDOUT
+ ).decode()
+ except FileNotFoundError:
+ pytest.skip('requires sysctl')
- def test_settings_large_header_buffer_size(self):
- self.load('empty')
+ return out
- def set_buffer_size(size):
- assert 'success' in self.conf(
- {'http': {'large_header_buffer_size': size}},
- 'settings',
- )
- def header_value(size, expect=200):
- headers = {'Host': 'a' * (size - 1), 'Connection': 'close'}
- assert self.get(headers=headers)['status'] == expect
+def test_settings_large_header_buffer_size():
+ client.load('empty')
- set_buffer_size(4096)
- header_value(4096)
- header_value(4097, 431)
-
- set_buffer_size(16384)
- header_value(16384)
- header_value(16385, 431)
-
- def test_settings_large_header_buffers(self):
- self.load('empty')
+ def set_buffer_size(size):
+ assert 'success' in client.conf(
+ {'http': {'large_header_buffer_size': size}},
+ 'settings',
+ )
- def set_buffers(buffers):
- assert 'success' in self.conf(
- {'http': {'large_header_buffers': buffers}},
- 'settings',
- )
+ def header_value(size, expect=200):
+ headers = {'Host': 'a' * (size - 1), 'Connection': 'close'}
+ assert client.get(headers=headers)['status'] == expect
- def big_headers(headers_num, expect=200):
- headers = {'Host': 'localhost', 'Connection': 'close'}
+ set_buffer_size(4096)
+ header_value(4096)
+ header_value(4097, 431)
- for i in range(headers_num):
- headers[f'Custom-header-{i}'] = 'a' * 8000
+ set_buffer_size(16384)
+ header_value(16384)
+ header_value(16385, 431)
- assert self.get(headers=headers)['status'] == expect
- set_buffers(1)
- big_headers(1)
- big_headers(2, 431)
+def test_settings_large_header_buffers():
+ client.load('empty')
- set_buffers(2)
- big_headers(2)
- big_headers(3, 431)
+ def set_buffers(buffers):
+ assert 'success' in client.conf(
+ {'http': {'large_header_buffers': buffers}},
+ 'settings',
+ )
- set_buffers(8)
- big_headers(8)
- big_headers(9, 431)
+ def big_headers(headers_num, expect=200):
+ headers = {'Host': 'localhost', 'Connection': 'close'}
- @pytest.mark.skip('not yet')
- def test_settings_large_header_buffer_invalid(self):
- def check_error(conf):
- assert 'error' in self.conf({'http': conf}, 'settings')
+ for i in range(headers_num):
+ headers[f'Custom-header-{i}'] = 'a' * 8000
- check_error({'large_header_buffer_size': -1})
- check_error({'large_header_buffer_size': 0})
- check_error({'large_header_buffers': -1})
- check_error({'large_header_buffers': 0})
+ assert client.get(headers=headers)['status'] == expect
- def test_settings_server_version(self):
- self.load('empty')
+ set_buffers(1)
+ big_headers(1)
+ big_headers(2, 431)
- assert self.get()['headers']['Server'].startswith('Unit/')
+ set_buffers(2)
+ big_headers(2)
+ big_headers(3, 431)
- assert 'success' in self.conf(
- {"http": {"server_version": False}}, 'settings'
- ), 'remove version'
- assert self.get()['headers']['Server'] == 'Unit'
+ set_buffers(8)
+ big_headers(8)
+ big_headers(9, 431)
- assert 'success' in self.conf(
- {"http": {"server_version": True}}, 'settings'
- ), 'add version'
- assert self.get()['headers']['Server'].startswith('Unit/')
- def test_settings_header_read_timeout(self):
- self.load('empty')
+@pytest.mark.skip('not yet')
+def test_settings_large_header_buffer_invalid():
+ def check_error(conf):
+ assert 'error' in client.conf({'http': conf}, 'settings')
- def req():
- (_, sock) = self.http(
- b"""GET / HTTP/1.1
-""",
- start=True,
- read_timeout=1,
- raw=True,
- )
+ check_error({'large_header_buffer_size': -1})
+ check_error({'large_header_buffer_size': 0})
+ check_error({'large_header_buffers': -1})
+ check_error({'large_header_buffers': 0})
- time.sleep(3)
- return self.http(
- b"""Host: localhost
-Connection: close
+def test_settings_server_version():
+ client.load('empty')
- """,
- sock=sock,
- raw=True,
- )
+ assert client.get()['headers']['Server'].startswith('Unit/')
- assert 'success' in self.conf(
- {'http': {'header_read_timeout': 2}}, 'settings'
- )
- assert req()['status'] == 408, 'status header read timeout'
+ assert 'success' in client.conf(
+ {"http": {"server_version": False}}, 'settings'
+ ), 'remove version'
+ assert client.get()['headers']['Server'] == 'Unit'
- assert 'success' in self.conf(
- {'http': {'header_read_timeout': 7}}, 'settings'
- )
- assert req()['status'] == 200, 'status header read timeout 2'
+ assert 'success' in client.conf(
+ {"http": {"server_version": True}}, 'settings'
+ ), 'add version'
+ assert client.get()['headers']['Server'].startswith('Unit/')
- def test_settings_header_read_timeout_update(self):
- self.load('empty')
- assert 'success' in self.conf(
- {'http': {'header_read_timeout': 4}}, 'settings'
- )
+def test_settings_header_read_timeout():
+ client.load('empty')
- sock = self.http(
+ def req():
+ (_, sock) = client.http(
b"""GET / HTTP/1.1
""",
+ start=True,
+ read_timeout=1,
raw=True,
- no_recv=True,
)
- time.sleep(2)
+ time.sleep(3)
- sock = self.http(
+ return client.http(
b"""Host: localhost
+Connection: close
+
""",
sock=sock,
raw=True,
- no_recv=True,
)
- time.sleep(2)
+ assert 'success' in client.conf(
+ {'http': {'header_read_timeout': 2}}, 'settings'
+ )
+ assert req()['status'] == 408, 'status header read timeout'
- (resp, sock) = self.http(
- b"""X-Blah: blah
-""",
- start=True,
- sock=sock,
- read_timeout=1,
- raw=True,
- )
+ assert 'success' in client.conf(
+ {'http': {'header_read_timeout': 7}}, 'settings'
+ )
+ assert req()['status'] == 200, 'status header read timeout 2'
- if len(resp) != 0:
- sock.close()
- else:
- time.sleep(2)
+def test_settings_header_read_timeout_update():
+ client.load('empty')
- resp = self.http(
- b"""Connection: close
+ assert 'success' in client.conf(
+ {'http': {'header_read_timeout': 4}}, 'settings'
+ )
+ sock = client.http(
+ b"""GET / HTTP/1.1
""",
- sock=sock,
- raw=True,
- )
+ raw=True,
+ no_recv=True,
+ )
- assert resp['status'] == 408, 'status header read timeout update'
+ time.sleep(2)
- def test_settings_body_read_timeout(self):
- self.load('empty')
+ sock = client.http(
+ b"""Host: localhost
+""",
+ sock=sock,
+ raw=True,
+ no_recv=True,
+ )
- def req():
- (_, sock) = self.http(
- b"""POST / HTTP/1.1
-Host: localhost
-Content-Length: 10
-Connection: close
+ time.sleep(2)
+ (resp, sock) = client.http(
+ b"""X-Blah: blah
""",
- start=True,
- raw_resp=True,
- read_timeout=1,
- raw=True,
- )
+ start=True,
+ sock=sock,
+ read_timeout=1,
+ raw=True,
+ )
- time.sleep(3)
+ if len(resp) != 0:
+ sock.close()
- return self.http(b"""0123456789""", sock=sock, raw=True)
+ else:
+ time.sleep(2)
- assert 'success' in self.conf(
- {'http': {'body_read_timeout': 2}}, 'settings'
- )
- assert req()['status'] == 408, 'status body read timeout'
+ resp = client.http(
+ b"""Connection: close
- assert 'success' in self.conf(
- {'http': {'body_read_timeout': 7}}, 'settings'
+""",
+ sock=sock,
+ raw=True,
)
- assert req()['status'] == 200, 'status body read timeout 2'
- def test_settings_body_read_timeout_update(self):
- self.load('empty')
+ assert resp['status'] == 408, 'status header read timeout update'
- assert 'success' in self.conf(
- {'http': {'body_read_timeout': 4}}, 'settings'
- )
- (resp, sock) = self.http(
+def test_settings_body_read_timeout():
+ client.load('empty')
+
+ def req():
+ (_, sock) = client.http(
b"""POST / HTTP/1.1
Host: localhost
Content-Length: 10
@@ -225,350 +199,389 @@ Connection: close
""",
start=True,
+ raw_resp=True,
read_timeout=1,
raw=True,
)
- time.sleep(2)
+ time.sleep(3)
- (resp, sock) = self.http(
- b"""012""", start=True, sock=sock, read_timeout=1, raw=True
- )
+ return client.http(b"""0123456789""", sock=sock, raw=True)
- time.sleep(2)
+ assert 'success' in client.conf(
+ {'http': {'body_read_timeout': 2}}, 'settings'
+ )
+ assert req()['status'] == 408, 'status body read timeout'
- (resp, sock) = self.http(
- b"""345""", start=True, sock=sock, read_timeout=1, raw=True
- )
+ assert 'success' in client.conf(
+ {'http': {'body_read_timeout': 7}}, 'settings'
+ )
+ assert req()['status'] == 200, 'status body read timeout 2'
- time.sleep(2)
- resp = self.http(b"""6789""", sock=sock, raw=True)
+def test_settings_body_read_timeout_update():
+ client.load('empty')
+
+ assert 'success' in client.conf(
+ {'http': {'body_read_timeout': 4}}, 'settings'
+ )
+
+ (resp, sock) = client.http(
+ b"""POST / HTTP/1.1
+Host: localhost
+Content-Length: 10
+Connection: close
+
+""",
+ start=True,
+ read_timeout=1,
+ raw=True,
+ )
+
+ time.sleep(2)
+
+ (resp, sock) = client.http(
+ b"""012""", start=True, sock=sock, read_timeout=1, raw=True
+ )
+
+ time.sleep(2)
+
+ (resp, sock) = client.http(
+ b"""345""", start=True, sock=sock, read_timeout=1, raw=True
+ )
+
+ time.sleep(2)
+
+ resp = client.http(b"""6789""", sock=sock, raw=True)
+
+ assert resp['status'] == 200, 'status body read timeout update'
- assert resp['status'] == 200, 'status body read timeout update'
- def test_settings_send_timeout(self, temp_dir):
- self.load('body_generate')
+def test_settings_send_timeout(temp_dir):
+ client.load('body_generate')
- def req(addr, data_len):
- sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
- sock.connect(addr)
+ def req(addr, data_len):
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ sock.connect(addr)
- req = f"""GET / HTTP/1.1
+ req = f"""GET / HTTP/1.1
Host: localhost
X-Length: {data_len}
Connection: close
"""
- sock.sendall(req.encode())
+ sock.sendall(req.encode())
- data = sock.recv(16).decode()
+ data = sock.recv(16).decode()
- time.sleep(3)
+ time.sleep(3)
- data += self.recvall(sock).decode()
+ data += client.recvall(sock).decode()
- sock.close()
+ sock.close()
- return data
+ return data
- sysctl_out = self.sysctl()
- values = re.findall(
- r'net.core.[rw]mem_(?:max|default).*?(\d+)', sysctl_out
- )
- values = [int(v) for v in values]
+ sysctl_out = sysctl()
+ values = re.findall(r'net.core.[rw]mem_(?:max|default).*?(\d+)', sysctl_out)
+ values = [int(v) for v in values]
- data_len = 1048576 if len(values) == 0 else 10 * max(values)
+ data_len = 1048576 if len(values) == 0 else 10 * max(values)
- addr = f'{temp_dir}/sock'
+ addr = f'{temp_dir}/sock'
- assert 'success' in self.conf(
- {f'unix:{addr}': {'application': 'body_generate'}}, 'listeners'
- )
+ assert 'success' in client.conf(
+ {f'unix:{addr}': {'application': 'body_generate'}}, 'listeners'
+ )
- assert 'success' in self.conf({'http': {'send_timeout': 1}}, 'settings')
+ assert 'success' in client.conf({'http': {'send_timeout': 1}}, 'settings')
- data = req(addr, data_len)
- assert re.search(r'200 OK', data), 'send timeout status'
- assert len(data) < data_len, 'send timeout data '
+ data = req(addr, data_len)
+ assert re.search(r'200 OK', data), 'send timeout status'
+ assert len(data) < data_len, 'send timeout data '
- self.conf({'http': {'send_timeout': 7}}, 'settings')
+ client.conf({'http': {'send_timeout': 7}}, 'settings')
- data = req(addr, data_len)
- assert re.search(r'200 OK', data), 'send timeout status 2'
- assert len(data) > data_len, 'send timeout data 2'
+ data = req(addr, data_len)
+ assert re.search(r'200 OK', data), 'send timeout status 2'
+ assert len(data) > data_len, 'send timeout data 2'
- def test_settings_idle_timeout(self):
- self.load('empty')
- def req():
- (_, sock) = self.get(
- headers={'Host': 'localhost', 'Connection': 'keep-alive'},
- start=True,
- read_timeout=1,
- )
+def test_settings_idle_timeout():
+ client.load('empty')
- time.sleep(3)
+ def req():
+ (_, sock) = client.get(
+ headers={'Host': 'localhost', 'Connection': 'keep-alive'},
+ start=True,
+ read_timeout=1,
+ )
- return self.get(sock=sock)
+ time.sleep(3)
- assert self.get()['status'] == 200, 'init'
+ return client.get(sock=sock)
- assert 'success' in self.conf({'http': {'idle_timeout': 2}}, 'settings')
- assert req()['status'] == 408, 'status idle timeout'
+ assert client.get()['status'] == 200, 'init'
- assert 'success' in self.conf({'http': {'idle_timeout': 7}}, 'settings')
- assert req()['status'] == 200, 'status idle timeout 2'
+ assert 'success' in client.conf({'http': {'idle_timeout': 2}}, 'settings')
+ assert req()['status'] == 408, 'status idle timeout'
- def test_settings_idle_timeout_2(self):
- self.load('empty')
+ assert 'success' in client.conf({'http': {'idle_timeout': 7}}, 'settings')
+ assert req()['status'] == 200, 'status idle timeout 2'
- def req():
- sock = self.http(b'', raw=True, no_recv=True)
- time.sleep(3)
+def test_settings_idle_timeout_2():
+ client.load('empty')
- return self.get(sock=sock)
+ def req():
+ sock = client.http(b'', raw=True, no_recv=True)
- assert self.get()['status'] == 200, 'init'
+ time.sleep(3)
- assert 'success' in self.conf({'http': {'idle_timeout': 1}}, 'settings')
- assert req()['status'] == 408, 'status idle timeout'
+ return client.get(sock=sock)
- assert 'success' in self.conf({'http': {'idle_timeout': 7}}, 'settings')
- assert req()['status'] == 200, 'status idle timeout 2'
+ assert client.get()['status'] == 200, 'init'
- def test_settings_max_body_size(self):
- self.load('empty')
+ assert 'success' in client.conf({'http': {'idle_timeout': 1}}, 'settings')
+ assert req()['status'] == 408, 'status idle timeout'
- assert 'success' in self.conf(
- {'http': {'max_body_size': 5}}, 'settings'
- )
+ assert 'success' in client.conf({'http': {'idle_timeout': 7}}, 'settings')
+ assert req()['status'] == 200, 'status idle timeout 2'
- assert self.post(body='01234')['status'] == 200, 'status size'
- assert self.post(body='012345')['status'] == 413, 'status size max'
- def test_settings_max_body_size_large(self):
- self.load('mirror')
+def test_settings_max_body_size():
+ client.load('empty')
- assert 'success' in self.conf(
- {'http': {'max_body_size': 32 * 1024 * 1024}}, 'settings'
- )
+ assert 'success' in client.conf({'http': {'max_body_size': 5}}, 'settings')
- body = '0123456789abcdef' * 4 * 64 * 1024
- resp = self.post(body=body, read_buffer_size=1024 * 1024)
- assert resp['status'] == 200, 'status size 4'
- assert resp['body'] == body, 'status body 4'
-
- body = '0123456789abcdef' * 8 * 64 * 1024
- resp = self.post(body=body, read_buffer_size=1024 * 1024)
- assert resp['status'] == 200, 'status size 8'
- assert resp['body'] == body, 'status body 8'
-
- body = '0123456789abcdef' * 16 * 64 * 1024
- resp = self.post(body=body, read_buffer_size=1024 * 1024)
- assert resp['status'] == 200, 'status size 16'
- assert resp['body'] == body, 'status body 16'
-
- body = '0123456789abcdef' * 32 * 64 * 1024
- resp = self.post(body=body, read_buffer_size=1024 * 1024)
- assert resp['status'] == 200, 'status size 32'
- assert resp['body'] == body, 'status body 32'
-
- @pytest.mark.skip('not yet')
- def test_settings_negative_value(self):
- assert 'error' in self.conf(
- {'http': {'max_body_size': -1}}, 'settings'
- ), 'settings negative value'
-
- def test_settings_body_buffer_size(self):
- self.load('mirror')
-
- assert 'success' in self.conf(
- {
- 'http': {
- 'max_body_size': 64 * 1024 * 1024,
- 'body_buffer_size': 32 * 1024 * 1024,
- }
- },
- 'settings',
- )
+ assert client.post(body='01234')['status'] == 200, 'status size'
+ assert client.post(body='012345')['status'] == 413, 'status size max'
- body = '0123456789abcdef'
- resp = self.post(body=body)
- assert bool(resp), 'response from application'
- assert resp['status'] == 200, 'status'
- assert resp['body'] == body, 'body'
- body = '0123456789abcdef' * 1024 * 1024
- resp = self.post(body=body, read_buffer_size=1024 * 1024)
- assert bool(resp), 'response from application 2'
- assert resp['status'] == 200, 'status 2'
- assert resp['body'] == body, 'body 2'
+def test_settings_max_body_size_large():
+ client.load('mirror')
- body = '0123456789abcdef' * 2 * 1024 * 1024
- resp = self.post(body=body, read_buffer_size=1024 * 1024)
- assert bool(resp), 'response from application 3'
- assert resp['status'] == 200, 'status 3'
- assert resp['body'] == body, 'body 3'
+ assert 'success' in client.conf(
+ {'http': {'max_body_size': 32 * 1024 * 1024}}, 'settings'
+ )
- body = '0123456789abcdef' * 3 * 1024 * 1024
- resp = self.post(body=body, read_buffer_size=1024 * 1024)
- assert bool(resp), 'response from application 4'
- assert resp['status'] == 200, 'status 4'
- assert resp['body'] == body, 'body 4'
+ body = '0123456789abcdef' * 4 * 64 * 1024
+ resp = client.post(body=body, read_buffer_size=1024 * 1024)
+ assert resp['status'] == 200, 'status size 4'
+ assert resp['body'] == body, 'status body 4'
- def test_settings_log_route(self, findall, search_in_file, wait_for_record):
- def count_fallbacks():
- return len(findall(r'"fallback" taken'))
+ body = '0123456789abcdef' * 8 * 64 * 1024
+ resp = client.post(body=body, read_buffer_size=1024 * 1024)
+ assert resp['status'] == 200, 'status size 8'
+ assert resp['body'] == body, 'status body 8'
- def check_record(template):
- assert search_in_file(template) is not None
+ body = '0123456789abcdef' * 16 * 64 * 1024
+ resp = client.post(body=body, read_buffer_size=1024 * 1024)
+ assert resp['status'] == 200, 'status size 16'
+ assert resp['body'] == body, 'status body 16'
- def check_no_record(template):
- assert search_in_file(template) is None
+ body = '0123456789abcdef' * 32 * 64 * 1024
+ resp = client.post(body=body, read_buffer_size=1024 * 1024)
+ assert resp['status'] == 200, 'status size 32'
+ assert resp['body'] == body, 'status body 32'
- def template_req_line(url):
- return rf'\[notice\].*http request line "GET {url} HTTP/1\.1"'
- def template_selected(route):
- return rf'\[notice\].*"{route}" selected'
+@pytest.mark.skip('not yet')
+def test_settings_negative_value():
+ assert 'error' in client.conf(
+ {'http': {'max_body_size': -1}}, 'settings'
+ ), 'settings negative value'
- def template_discarded(route):
- return rf'\[info\].*"{route}" discarded'
- def wait_for_request_log(status, uri, route):
- assert self.get(url=uri)['status'] == status
- assert wait_for_record(template_req_line(uri)) is not None
- assert wait_for_record(template_selected(route)) is not None
+def test_settings_body_buffer_size():
+ client.load('mirror')
- # routes array
+ assert 'success' in client.conf(
+ {
+ 'http': {
+ 'max_body_size': 64 * 1024 * 1024,
+ 'body_buffer_size': 32 * 1024 * 1024,
+ }
+ },
+ 'settings',
+ )
+
+ body = '0123456789abcdef'
+ resp = client.post(body=body)
+ assert bool(resp), 'response from application'
+ assert resp['status'] == 200, 'status'
+ assert resp['body'] == body, 'body'
+
+ body = '0123456789abcdef' * 1024 * 1024
+ resp = client.post(body=body, read_buffer_size=1024 * 1024)
+ assert bool(resp), 'response from application 2'
+ assert resp['status'] == 200, 'status 2'
+ assert resp['body'] == body, 'body 2'
+
+ body = '0123456789abcdef' * 2 * 1024 * 1024
+ resp = client.post(body=body, read_buffer_size=1024 * 1024)
+ assert bool(resp), 'response from application 3'
+ assert resp['status'] == 200, 'status 3'
+ assert resp['body'] == body, 'body 3'
+
+ body = '0123456789abcdef' * 3 * 1024 * 1024
+ resp = client.post(body=body, read_buffer_size=1024 * 1024)
+ assert bool(resp), 'response from application 4'
+ assert resp['status'] == 200, 'status 4'
+ assert resp['body'] == body, 'body 4'
+
+
+def test_settings_log_route(findall, search_in_file, wait_for_record):
+ def count_fallbacks():
+ return len(findall(r'"fallback" taken'))
+
+ def check_record(template):
+ assert search_in_file(template) is not None
+
+ def check_no_record(template):
+ assert search_in_file(template) is None
+
+ def template_req_line(url):
+ return rf'\[notice\].*http request line "GET {url} HTTP/1\.1"'
+
+ def template_selected(route):
+ return rf'\[notice\].*"{route}" selected'
+
+ def template_discarded(route):
+ return rf'\[info\].*"{route}" discarded'
+
+ def wait_for_request_log(status, uri, route):
+ assert client.get(url=uri)['status'] == status
+ assert wait_for_record(template_req_line(uri)) is not None
+ assert wait_for_record(template_selected(route)) is not None
+
+ # routes array
+
+ assert 'success' in client.conf(
+ {
+ "listeners": {"*:7080": {"pass": "routes"}},
+ "routes": [
+ {
+ "match": {
+ "uri": "/zero",
+ },
+ "action": {"return": 200},
+ },
+ {
+ "action": {"return": 201},
+ },
+ ],
+ "applications": {},
+ "settings": {"http": {"log_route": True}},
+ }
+ )
- assert 'success' in self.conf(
- {
- "listeners": {"*:7080": {"pass": "routes"}},
- "routes": [
+ wait_for_request_log(200, '/zero', 'routes/0')
+ check_no_record(r'discarded')
+
+ wait_for_request_log(201, '/one', 'routes/1')
+ check_record(template_discarded('routes/0'))
+
+ # routes object
+
+ assert 'success' in client.conf(
+ {
+ "listeners": {"*:7080": {"pass": "routes/main"}},
+ "routes": {
+ "main": [
{
"match": {
- "uri": "/zero",
+ "uri": "/named_route",
},
"action": {"return": 200},
},
{
"action": {"return": 201},
},
- ],
- "applications": {},
- "settings": {"http": {"log_route": True}},
- }
- )
-
- wait_for_request_log(200, '/zero', 'routes/0')
- check_no_record(r'discarded')
+ ]
+ },
+ "applications": {},
+ "settings": {"http": {"log_route": True}},
+ }
+ )
- wait_for_request_log(201, '/one', 'routes/1')
- check_record(template_discarded('routes/0'))
+ wait_for_request_log(200, '/named_route', 'routes/main/0')
+ check_no_record(template_discarded('routes/main'))
- # routes object
+ wait_for_request_log(201, '/unnamed_route', 'routes/main/1')
+ check_record(template_discarded('routes/main/0'))
- assert 'success' in self.conf(
- {
- "listeners": {"*:7080": {"pass": "routes/main"}},
- "routes": {
- "main": [
- {
- "match": {
- "uri": "/named_route",
- },
- "action": {"return": 200},
- },
- {
- "action": {"return": 201},
- },
- ]
- },
- "applications": {},
- "settings": {"http": {"log_route": True}},
- }
- )
+ # routes sequence
- wait_for_request_log(200, '/named_route', 'routes/main/0')
- check_no_record(template_discarded('routes/main'))
-
- wait_for_request_log(201, '/unnamed_route', 'routes/main/1')
- check_record(template_discarded('routes/main/0'))
+ assert 'success' in client.conf(
+ {
+ "listeners": {"*:7080": {"pass": "routes/first"}},
+ "routes": {
+ "first": [
+ {
+ "action": {"pass": "routes/second"},
+ },
+ ],
+ "second": [
+ {
+ "action": {"return": 200},
+ },
+ ],
+ },
+ "applications": {},
+ "settings": {"http": {"log_route": True}},
+ }
+ )
- # routes sequence
+ wait_for_request_log(200, '/sequence', 'routes/second/0')
+ check_record(template_selected('routes/first/0'))
- assert 'success' in self.conf(
- {
- "listeners": {"*:7080": {"pass": "routes/first"}},
- "routes": {
- "first": [
- {
- "action": {"pass": "routes/second"},
- },
- ],
- "second": [
- {
- "action": {"return": 200},
- },
- ],
- },
- "applications": {},
- "settings": {"http": {"log_route": True}},
- }
- )
+ # fallback
- wait_for_request_log(200, '/sequence', 'routes/second/0')
- check_record(template_selected('routes/first/0'))
-
- # fallback
-
- assert 'success' in self.conf(
- {
- "listeners": {"*:7080": {"pass": "routes/fall"}},
- "routes": {
- "fall": [
- {
- "action": {
- "share": "/blah",
- "fallback": {"pass": "routes/fall2"},
- },
- },
- ],
- "fall2": [
- {
- "action": {"return": 200},
+ assert 'success' in client.conf(
+ {
+ "listeners": {"*:7080": {"pass": "routes/fall"}},
+ "routes": {
+ "fall": [
+ {
+ "action": {
+ "share": "/blah",
+ "fallback": {"pass": "routes/fall2"},
},
- ],
- },
- "applications": {},
- "settings": {"http": {"log_route": True}},
- }
- )
+ },
+ ],
+ "fall2": [
+ {
+ "action": {"return": 200},
+ },
+ ],
+ },
+ "applications": {},
+ "settings": {"http": {"log_route": True}},
+ }
+ )
- wait_for_request_log(200, '/', 'routes/fall2/0')
- assert count_fallbacks() == 1
- check_record(template_selected('routes/fall/0'))
+ wait_for_request_log(200, '/', 'routes/fall2/0')
+ assert count_fallbacks() == 1
+ check_record(template_selected('routes/fall/0'))
- assert self.head()['status'] == 200
- assert count_fallbacks() == 2
+ assert client.head()['status'] == 200
+ assert count_fallbacks() == 2
- # disable log
+ # disable log
- assert 'success' in self.conf({"log_route": False}, 'settings/http')
+ assert 'success' in client.conf({"log_route": False}, 'settings/http')
- url = '/disable_logging'
- assert self.get(url=url)['status'] == 200
+ url = '/disable_logging'
+ assert client.get(url=url)['status'] == 200
- time.sleep(1)
+ time.sleep(1)
- check_no_record(template_req_line(url))
+ check_no_record(template_req_line(url))
- # total
+ # total
- assert len(findall(r'\[notice\].*http request line')) == 7
- assert len(findall(r'\[notice\].*selected')) == 10
- assert len(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