From 54837759f36eddb80af22c8d73e103a948221dc7 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Mon, 19 Oct 2020 22:25:29 +0100 Subject: Tests: fixed unit.log print. --- test/test_python_application.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'test/test_python_application.py') diff --git a/test/test_python_application.py b/test/test_python_application.py index 3e27a24c..6ea9f4ff 100644 --- a/test/test_python_application.py +++ b/test/test_python_application.py @@ -5,7 +5,9 @@ import time import pytest +from conftest import option from conftest import skip_alert +from conftest import unit_stop from unit.applications.lang.python import TestApplicationPython @@ -13,7 +15,7 @@ class TestPythonApplication(TestApplicationPython): prerequisites = {'modules': {'python': 'all'}} def findall(self, pattern): - with open(self.temp_dir + '/unit.log', 'r', errors='ignore') as f: + with open(option.temp_dir + '/unit.log', 'r', errors='ignore') as f: return re.findall(pattern, f.read()) def test_python_application_variables(self): @@ -156,7 +158,7 @@ custom-header: BLAH self.conf({"listeners": {}, "applications": {}}) - self.stop() + unit_stop() assert ( self.wait_for_record(r'RuntimeError') is not None @@ -344,7 +346,7 @@ Connection: close self.conf({"listeners": {}, "applications": {}}) - self.stop() + unit_stop() assert self.wait_for_record(r'At exit called\.') is not None, 'atexit' @@ -507,7 +509,7 @@ last line: 987654321 self.get() - self.stop() + unit_stop() assert ( self.wait_for_record(r'\[error\].+Error in application\.') @@ -550,7 +552,7 @@ last line: 987654321 self.get() - self.stop() + unit_stop() assert self.wait_for_record(r'Close called\.') is not None, 'close' @@ -559,7 +561,7 @@ last line: 987654321 self.get() - self.stop() + unit_stop() assert ( self.wait_for_record(r'Close called\.') is not None @@ -570,7 +572,7 @@ last line: 987654321 self.get() - self.stop() + unit_stop() assert ( self.wait_for_record( -- cgit From f27953af6103db390aa3eee012a254f130fdf5f4 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Thu, 5 Nov 2020 00:05:02 +0300 Subject: Tests: added Python threading tests. --- test/test_python_application.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'test/test_python_application.py') diff --git a/test/test_python_application.py b/test/test_python_application.py index 6ea9f4ff..780b836a 100644 --- a/test/test_python_application.py +++ b/test/test_python_application.py @@ -832,3 +832,44 @@ last line: 987654321 assert 'success' in self.conf_delete('applications/callable/callable') assert self.get()['status'] == 204, 'default response 2' + + def test_python_application_threads(self): + self.load('threads') + + assert 'success' in self.conf( + '4', 'applications/threads/threads' + ), 'configure 4 threads' + + socks = [] + + for i in range(4): + (_, sock) = self.get( + headers={ + 'Host': 'localhost', + 'X-Delay': '2', + 'Connection': 'close', + }, + no_recv=True, + start=True, + ) + + socks.append(sock) + + threads = set() + + for sock in socks: + resp = self.recvall(sock).decode('utf-8') + + self.log_in(resp) + + resp = self._resp_to_dict(resp) + + assert resp['status'] == 200, 'status' + + threads.add(resp['headers']['X-Thread']) + + assert resp['headers']['Wsgi-Multithread'] == 'True', 'multithread' + + sock.close() + + assert len(socks) == len(threads), 'threads differs' -- cgit From a8a9d80f8dcff98a99c74a923a2a37b9e3e177eb Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Tue, 10 Nov 2020 22:27:08 +0300 Subject: Tests: supporting instant app parameters in load(). --- test/test_python_application.py | 54 +++++++++-------------------------------- 1 file changed, 11 insertions(+), 43 deletions(-) (limited to 'test/test_python_application.py') diff --git a/test/test_python_application.py b/test/test_python_application.py index 780b836a..871d8bc0 100644 --- a/test/test_python_application.py +++ b/test/test_python_application.py @@ -197,11 +197,6 @@ custom-header: BLAH assert resp['body'] == body, 'keep-alive 2' def test_python_keepalive_reconfigure(self): - skip_alert( - r'pthread_mutex.+failed', - r'failed to apply', - r'process \d+ exited on signal', - ) self.load('mirror') assert self.get()['status'] == 200, 'init' @@ -223,9 +218,8 @@ custom-header: BLAH ) assert resp['body'] == body, 'keep-alive open' - assert 'success' in self.conf( - str(i + 1), 'applications/mirror/processes' - ), 'reconfigure' + + self.load('mirror', processes=i + 1) socks.append(sock) @@ -243,9 +237,8 @@ custom-header: BLAH ) assert resp['body'] == body, 'keep-alive request' - assert 'success' in self.conf( - str(i + 1), 'applications/mirror/processes' - ), 'reconfigure 2' + + self.load('mirror', processes=i + 1) for i in range(conns): resp = self.post( @@ -259,9 +252,8 @@ custom-header: BLAH ) assert resp['body'] == body, 'keep-alive close' - assert 'success' in self.conf( - str(i + 1), 'applications/mirror/processes' - ), 'reconfigure 3' + + self.load('mirror', processes=i + 1) def test_python_keepalive_reconfigure_2(self): self.load('mirror') @@ -351,11 +343,7 @@ Connection: close assert self.wait_for_record(r'At exit called\.') is not None, 'atexit' def test_python_process_switch(self): - self.load('delayed') - - assert 'success' in self.conf( - '2', 'applications/delayed/processes' - ), 'configure 2 processes' + self.load('delayed', processes=2) self.get( headers={ @@ -541,9 +529,7 @@ last line: 987654321 def test_python_application_loading_error(self): skip_alert(r'Python failed to import module "blah"') - self.load('empty') - - assert 'success' in self.conf('"blah"', 'applications/empty/module') + self.load('empty', module="blah") assert self.get()['status'] == 503, 'loading error' @@ -811,34 +797,16 @@ last line: 987654321 assert self.get()['status'] == 204, 'default application response' - assert 'success' in self.conf( - '"app"', 'applications/callable/callable' - ) + self.load('callable', callable="app") assert self.get()['status'] == 200, 'callable response' - assert 'success' in self.conf( - '"blah"', 'applications/callable/callable' - ) + self.load('callable', callable="blah") assert self.get()['status'] not in [200, 204], 'callable response inv' - assert 'success' in self.conf( - '"app"', 'applications/callable/callable' - ) - - assert self.get()['status'] == 200, 'callable response 2' - - assert 'success' in self.conf_delete('applications/callable/callable') - - assert self.get()['status'] == 204, 'default response 2' - def test_python_application_threads(self): - self.load('threads') - - assert 'success' in self.conf( - '4', 'applications/threads/threads' - ), 'configure 4 threads' + self.load('threads', threads=4) socks = [] -- cgit From 567f0a7b3049f4532524ac35cb232cbeedb868bf Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Mon, 16 Nov 2020 20:37:01 +0300 Subject: Tests: fixing tests interrupt in terminal. KeyboardInterrupt re-raised. --- test/test_python_application.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/test_python_application.py') diff --git a/test/test_python_application.py b/test/test_python_application.py index 871d8bc0..83b0c8f4 100644 --- a/test/test_python_application.py +++ b/test/test_python_application.py @@ -730,7 +730,7 @@ last line: 987654321 try: group_id = grp.getgrnam(group).gr_gid - except: + except KeyError: group = 'nogroup' group_id = grp.getgrnam(group).gr_gid @@ -775,7 +775,7 @@ last line: 987654321 try: grp.getgrnam(group) group = True - except: + except KeyError: group = False if group: -- cgit