Tests: unit_stop() removed where possible.

Since wait_for_record() was introduced there is no need
to stop Unit before parsing unit.log.
This commit is contained in:
Andrei Zeliankou
2021-01-12 06:20:23 +00:00
parent a0bc946db3
commit f5ac143246
6 changed files with 10 additions and 70 deletions

View File

@@ -2,7 +2,6 @@ import time
import pytest import pytest
from conftest import unit_stop
from unit.applications.lang.python import TestApplicationPython from unit.applications.lang.python import TestApplicationPython
from unit.option import option from unit.option import option
@@ -50,8 +49,6 @@ class TestAccessLog(TestApplicationPython):
body='0123456789', body='0123456789',
) )
unit_stop()
assert ( assert (
self.wait_for_record(r'"POST / HTTP/1.1" 200 10') is not None self.wait_for_record(r'"POST / HTTP/1.1" 200 10') is not None
), 'keepalive 2' ), 'keepalive 2'
@@ -78,8 +75,6 @@ Connection: close
raw=True, raw=True,
) )
unit_stop()
assert ( assert (
self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "Referer-1" "-"') self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "Referer-1" "-"')
is not None is not None
@@ -100,8 +95,6 @@ Connection: close
self.get(sock_type='ipv6') self.get(sock_type='ipv6')
unit_stop()
assert ( assert (
self.wait_for_record( self.wait_for_record(
r'::1 - - \[.+\] "GET / HTTP/1.1" 200 0 "-" "-"' r'::1 - - \[.+\] "GET / HTTP/1.1" 200 0 "-" "-"'
@@ -120,8 +113,6 @@ Connection: close
self.get(sock_type='unix', addr=addr) self.get(sock_type='unix', addr=addr)
unit_stop()
assert ( assert (
self.wait_for_record( self.wait_for_record(
r'unix: - - \[.+\] "GET / HTTP/1.1" 200 0 "-" "-"' r'unix: - - \[.+\] "GET / HTTP/1.1" 200 0 "-" "-"'
@@ -140,8 +131,6 @@ Connection: close
} }
) )
unit_stop()
assert ( assert (
self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "referer-value" "-"') self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "referer-value" "-"')
is not None is not None
@@ -158,8 +147,6 @@ Connection: close
} }
) )
unit_stop()
assert ( assert (
self.wait_for_record( self.wait_for_record(
r'"GET / HTTP/1.1" 200 0 "-" "user-agent-value"' r'"GET / HTTP/1.1" 200 0 "-" "user-agent-value"'
@@ -172,8 +159,6 @@ Connection: close
self.get(http_10=True) self.get(http_10=True)
unit_stop()
assert ( assert (
self.wait_for_record(r'"GET / HTTP/1.0" 200 0 "-" "-"') is not None self.wait_for_record(r'"GET / HTTP/1.0" 200 0 "-" "-"') is not None
), 'http 1.0' ), 'http 1.0'
@@ -187,8 +172,6 @@ Connection: close
time.sleep(1) time.sleep(1)
unit_stop()
assert ( assert (
self.wait_for_record(r'"GE" 400 0 "-" "-"') is not None self.wait_for_record(r'"GE" 400 0 "-" "-"') is not None
), 'partial' ), 'partial'
@@ -200,8 +183,6 @@ Connection: close
self.http(b"""GET /\n""", raw=True) self.http(b"""GET /\n""", raw=True)
unit_stop()
assert ( assert (
self.wait_for_record(r'"GET /" 400 \d+ "-" "-"') is not None self.wait_for_record(r'"GET /" 400 \d+ "-" "-"') is not None
), 'partial 2' ), 'partial 2'
@@ -215,8 +196,6 @@ Connection: close
time.sleep(1) time.sleep(1)
unit_stop()
assert ( assert (
self.wait_for_record(r'"GET /" 400 0 "-" "-"') is not None self.wait_for_record(r'"GET /" 400 0 "-" "-"') is not None
), 'partial 3' ), 'partial 3'
@@ -230,8 +209,6 @@ Connection: close
time.sleep(1) time.sleep(1)
unit_stop()
assert ( assert (
self.wait_for_record(r'"GET / HTTP/1.1" 400 0 "-" "-"') is not None self.wait_for_record(r'"GET / HTTP/1.1" 400 0 "-" "-"') is not None
), 'partial 4' ), 'partial 4'
@@ -244,8 +221,6 @@ Connection: close
self.get(headers={'Connection': 'close'}) self.get(headers={'Connection': 'close'})
unit_stop()
assert ( assert (
self.wait_for_record(r'"GET / HTTP/1.1" 400 \d+ "-" "-"') self.wait_for_record(r'"GET / HTTP/1.1" 400 \d+ "-" "-"')
is not None is not None
@@ -256,8 +231,6 @@ Connection: close
self.get(url='/?blah&var=val') self.get(url='/?blah&var=val')
unit_stop()
assert ( assert (
self.wait_for_record( self.wait_for_record(
r'"GET /\?blah&var=val HTTP/1.1" 200 0 "-" "-"' r'"GET /\?blah&var=val HTTP/1.1" 200 0 "-" "-"'
@@ -272,8 +245,6 @@ Connection: close
self.get(url='/delete') self.get(url='/delete')
unit_stop()
assert self.search_in_log(r'/delete', 'access.log') is None, 'delete' assert self.search_in_log(r'/delete', 'access.log') is None, 'delete'
def test_access_log_change(self, temp_dir): def test_access_log_change(self, temp_dir):
@@ -285,8 +256,6 @@ Connection: close
self.get() self.get()
unit_stop()
assert ( assert (
self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "-" "-"', 'new.log') self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "-" "-"', 'new.log')
is not None is not None

View File

@@ -2,7 +2,6 @@ import re
import pytest import pytest
from conftest import unit_stop
from unit.applications.lang.perl import TestApplicationPerl from unit.applications.lang.perl import TestApplicationPerl
@@ -119,8 +118,6 @@ class TestPerlApplication(TestApplicationPerl):
assert self.get()['body'] == '1', 'errors result' assert self.get()['body'] == '1', 'errors result'
unit_stop()
assert ( assert (
self.wait_for_record(r'\[error\].+Error in application') self.wait_for_record(r'\[error\].+Error in application')
is not None is not None

View File

@@ -2,10 +2,10 @@ import os
import re import re
import shutil import shutil
import time import time
from subprocess import call
import pytest import pytest
from conftest import unit_stop
from unit.applications.lang.php import TestApplicationPHP from unit.applications.lang.php import TestApplicationPHP
from unit.option import option from unit.option import option
@@ -20,7 +20,7 @@ class TestPHPApplication(TestApplicationPHP):
def set_opcache(self, app, val): def set_opcache(self, app, val):
assert 'success' in self.conf( assert 'success' in self.conf(
{"admin": {"opcache.enable": val, "opcache.enable_cli": val,},}, {"admin": {"opcache.enable": val, "opcache.enable_cli": val}},
'applications/' + app + '/options', 'applications/' + app + '/options',
) )
@@ -99,7 +99,10 @@ class TestPHPApplication(TestApplicationPHP):
assert self.get()['body'] == '0123' assert self.get()['body'] == '0123'
unit_stop() with open(temp_dir + '/unit.pid', 'r') as f:
pid = f.read().rstrip()
call(['kill', '-s', 'USR1', pid])
with open(temp_dir + '/unit.log', 'r', errors='ignore') as f: with open(temp_dir + '/unit.log', 'r', errors='ignore') as f:
errs = re.findall(r'Error in fastcgi_finish_request', f.read()) errs = re.findall(r'Error in fastcgi_finish_request', f.read())
@@ -113,7 +116,10 @@ class TestPHPApplication(TestApplicationPHP):
assert resp['status'] == 200 assert resp['status'] == 200
assert resp['body'] == '' assert resp['body'] == ''
unit_stop() with open(temp_dir + '/unit.pid', 'r') as f:
pid = f.read().rstrip()
call(['kill', '-s', 'USR1', pid])
with open(temp_dir + '/unit.log', 'r', errors='ignore') as f: with open(temp_dir + '/unit.log', 'r', errors='ignore') as f:
errs = re.findall(r'Error in fastcgi_finish_request', f.read()) errs = re.findall(r'Error in fastcgi_finish_request', f.read())
@@ -538,8 +544,6 @@ class TestPHPApplication(TestApplicationPHP):
assert self.get()['status'] == 200, 'status 2' assert self.get()['status'] == 200, 'status 2'
unit_stop()
pattern = r'\d{4}\/\d\d\/\d\d\s\d\d:.+\[notice\].+Error in application' pattern = r'\d{4}\/\d\d\/\d\d\s\d\d:.+\[notice\].+Error in application'
assert self.wait_for_record(pattern) is not None, 'errors print' assert self.wait_for_record(pattern) is not None, 'errors print'

View File

@@ -5,7 +5,6 @@ import time
import pytest import pytest
from conftest import unit_stop
from unit.applications.lang.python import TestApplicationPython from unit.applications.lang.python import TestApplicationPython
from unit.option import option from unit.option import option
@@ -157,8 +156,6 @@ custom-header: BLAH
self.conf({"listeners": {}, "applications": {}}) self.conf({"listeners": {}, "applications": {}})
unit_stop()
assert ( assert (
self.wait_for_record(r'RuntimeError') is not None self.wait_for_record(r'RuntimeError') is not None
), 'ctx iter atexit' ), 'ctx iter atexit'
@@ -337,8 +334,6 @@ Connection: close
self.conf({"listeners": {}, "applications": {}}) self.conf({"listeners": {}, "applications": {}})
unit_stop()
assert self.wait_for_record(r'At exit called\.') is not None, 'atexit' assert self.wait_for_record(r'At exit called\.') is not None, 'atexit'
def test_python_process_switch(self): def test_python_process_switch(self):
@@ -496,8 +491,6 @@ last line: 987654321
self.get() self.get()
unit_stop()
assert ( assert (
self.wait_for_record(r'\[error\].+Error in application\.') self.wait_for_record(r'\[error\].+Error in application\.')
is not None is not None
@@ -537,8 +530,6 @@ last line: 987654321
self.get() self.get()
unit_stop()
assert self.wait_for_record(r'Close called\.') is not None, 'close' assert self.wait_for_record(r'Close called\.') is not None, 'close'
def test_python_application_close_error(self): def test_python_application_close_error(self):
@@ -546,8 +537,6 @@ last line: 987654321
self.get() self.get()
unit_stop()
assert ( assert (
self.wait_for_record(r'Close called\.') is not None self.wait_for_record(r'Close called\.') is not None
), 'close error' ), 'close error'
@@ -557,8 +546,6 @@ last line: 987654321
self.get() self.get()
unit_stop()
assert ( assert (
self.wait_for_record( self.wait_for_record(
r'\[error\].+the application returned not an iterable object' r'\[error\].+the application returned not an iterable object'

View File

@@ -2,7 +2,6 @@ import re
import pytest import pytest
from conftest import unit_stop
from unit.applications.lang.ruby import TestApplicationRuby from unit.applications.lang.ruby import TestApplicationRuby
@@ -175,8 +174,6 @@ class TestRubyApplication(TestApplicationRuby):
self.get() self.get()
unit_stop()
assert ( assert (
self.wait_for_record(r'\[error\].+Error in application') self.wait_for_record(r'\[error\].+Error in application')
is not None is not None
@@ -187,8 +184,6 @@ class TestRubyApplication(TestApplicationRuby):
self.get() self.get()
unit_stop()
assert ( assert (
self.wait_for_record(r'\[error\].+1234567890') is not None self.wait_for_record(r'\[error\].+1234567890') is not None
), 'errors puts int' ), 'errors puts int'
@@ -198,8 +193,6 @@ class TestRubyApplication(TestApplicationRuby):
self.get() self.get()
unit_stop()
assert ( assert (
self.wait_for_record(r'\[error\].+Error in application') self.wait_for_record(r'\[error\].+Error in application')
is not None is not None
@@ -215,7 +208,6 @@ class TestRubyApplication(TestApplicationRuby):
self.get() self.get()
unit_stop()
assert ( assert (
self.wait_for_record(r'\[error\].+1234567890') is not None self.wait_for_record(r'\[error\].+1234567890') is not None
@@ -228,8 +220,6 @@ class TestRubyApplication(TestApplicationRuby):
self.conf({"listeners": {}, "applications": {}}) self.conf({"listeners": {}, "applications": {}})
unit_stop()
assert ( assert (
self.wait_for_record(r'\[error\].+At exit called\.') is not None self.wait_for_record(r'\[error\].+At exit called\.') is not None
), 'at exit' ), 'at exit'
@@ -289,8 +279,6 @@ class TestRubyApplication(TestApplicationRuby):
assert self.get()['status'] == 500, 'body each error status' assert self.get()['status'] == 500, 'body each error status'
unit_stop()
assert ( assert (
self.wait_for_record(r'\[error\].+Failed to run ruby script') self.wait_for_record(r'\[error\].+Failed to run ruby script')
is not None is not None

View File

@@ -1,7 +1,6 @@
import os import os
from subprocess import call from subprocess import call
from conftest import unit_stop
from unit.applications.lang.python import TestApplicationPython from unit.applications.lang.python import TestApplicationPython
from unit.utils import waitforfiles from unit.utils import waitforfiles
@@ -41,8 +40,6 @@ class TestUSR1(TestApplicationPython):
assert self.get(url='/usr1')['status'] == 200 assert self.get(url='/usr1')['status'] == 200
unit_stop()
assert ( assert (
self.wait_for_record(r'"GET /usr1 HTTP/1.1" 200 0 "-" "-"', log) self.wait_for_record(r'"GET /usr1 HTTP/1.1" 200 0 "-" "-"', log)
is not None is not None
@@ -74,8 +71,6 @@ class TestUSR1(TestApplicationPython):
body = 'body_for_a_log_unit' body = 'body_for_a_log_unit'
assert self.post(body=body)['status'] == 200 assert self.post(body=body)['status'] == 200
unit_stop()
assert self.wait_for_record(body) is not None, 'rename new' assert self.wait_for_record(body) is not None, 'rename new'
assert self.search_in_log(body, log_new) is None, 'rename new 2' assert self.search_in_log(body, log_new) is None, 'rename new 2'