diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2021-05-24 05:26:15 +0100 |
---|---|---|
committer | Andrei Zeliankou <zelenkov@nginx.com> | 2021-05-24 05:26:15 +0100 |
commit | 1154ede862824331d24591c717c270e779a2b08c (patch) | |
tree | b4706a17be3ec2c1ea4151fdee6b4d4caf68009d /test | |
parent | c160ea11e4ece4db52731ac8b83dd09ca2d1ef11 (diff) | |
download | unit-1154ede862824331d24591c717c270e779a2b08c.tar.gz unit-1154ede862824331d24591c717c270e779a2b08c.tar.bz2 |
Tests: test_settings_send_timeout improved.
Data length adjusts depending on socket buffer size when it's possible.
Diffstat (limited to 'test')
-rw-r--r-- | test/python/body_generate/wsgi.py | 6 | ||||
-rw-r--r-- | test/test_settings.py | 25 | ||||
-rw-r--r-- | test/unit/utils.py | 11 |
3 files changed, 34 insertions, 8 deletions
diff --git a/test/python/body_generate/wsgi.py b/test/python/body_generate/wsgi.py new file mode 100644 index 00000000..73462be6 --- /dev/null +++ b/test/python/body_generate/wsgi.py @@ -0,0 +1,6 @@ +def application(env, start_response): + length = env.get('HTTP_X_LENGTH', '10') + bytes = b'X' * int(length) + + start_response('200', [('Content-Length', length)]) + return [bytes] diff --git a/test/test_settings.py b/test/test_settings.py index d129dec9..ef4136e3 100644 --- a/test/test_settings.py +++ b/test/test_settings.py @@ -5,6 +5,7 @@ import time import pytest from unit.applications.lang.python import TestApplicationPython +from unit.utils import sysctl class TestSettings(TestApplicationPython): @@ -147,27 +148,35 @@ Connection: close assert resp['status'] == 200, 'status body read timeout update' def test_settings_send_timeout(self, temp_dir): - self.load('mirror') + self.load('body_generate') + + 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 + data_len = 1048576 if len(values) == 0 else 10 * max(values) self.conf({'http': {'send_timeout': 1}}, 'settings') addr = temp_dir + '/sock' - self.conf({"unix:" + addr: {'application': 'mirror'}}, 'listeners') + self.conf( + {"unix:" + addr: {'application': 'body_generate'}}, 'listeners' + ) sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(addr) - req = """POST / HTTP/1.1 + req = ( + """GET / HTTP/1.1 Host: localhost -Content-Type: text/html -Content-Length: %d +X-Length: %d Connection: close -""" % data_len + ( - 'X' * data_len +""" + % data_len ) sock.sendall(req.encode()) diff --git a/test/unit/utils.py b/test/unit/utils.py index e80fc469..a627e9f5 100644 --- a/test/unit/utils.py +++ b/test/unit/utils.py @@ -61,6 +61,17 @@ def findmnt(): return out +def sysctl(): + try: + out = subprocess.check_output( + ['sysctl', '-a'], stderr=subprocess.STDOUT + ).decode() + except FileNotFoundError: + pytest.skip('requires sysctl') + + return out + + def waitformount(template, wait=50): for i in range(wait): if findmnt().find(template) != -1: |