Tests: added USR1 signal test for unit.log.
This commit is contained in:
parent
1033cfa3b0
commit
38cfe4cf3d
3 changed files with 101 additions and 37 deletions
9
test/python/log_body/wsgi.py
Normal file
9
test/python/log_body/wsgi.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
def application(environ, start_response):
|
||||
content_length = int(environ.get('CONTENT_LENGTH', 0))
|
||||
body = bytes(environ['wsgi.input'].read(content_length))
|
||||
|
||||
environ['wsgi.errors'].write(body)
|
||||
environ['wsgi.errors'].flush()
|
||||
|
||||
start_response('200', [('Content-Length', '0')])
|
||||
return []
|
|
@ -298,42 +298,5 @@ Connection: close
|
|||
'change',
|
||||
)
|
||||
|
||||
def test_access_log_reopen(self):
|
||||
self.load('empty')
|
||||
|
||||
log_path = self.testdir + '/access.log'
|
||||
|
||||
self.assertTrue(self.waitforfiles(log_path), 'open')
|
||||
|
||||
log_path_new = self.testdir + '/new.log'
|
||||
|
||||
os.rename(log_path, log_path_new)
|
||||
|
||||
self.get()
|
||||
|
||||
self.assertIsNotNone(
|
||||
self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "-" "-"', 'new.log'),
|
||||
'rename new',
|
||||
)
|
||||
self.assertFalse(os.path.isfile(log_path), 'rename old')
|
||||
|
||||
with open(self.testdir + '/unit.pid', 'r') as f:
|
||||
pid = f.read().rstrip()
|
||||
|
||||
call(['kill', '-s', 'USR1', pid])
|
||||
|
||||
self.assertTrue(self.waitforfiles(log_path), 'reopen')
|
||||
|
||||
self.get(url='/usr1')
|
||||
|
||||
self.assertIsNotNone(
|
||||
self.wait_for_record(r'"GET /usr1 HTTP/1.1" 200 0 "-" "-"'),
|
||||
'reopen 2',
|
||||
)
|
||||
self.assertIsNone(
|
||||
self.search_in_log(r'/usr1', 'new.log'), 'rename new 2'
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
TestAccessLog.main()
|
||||
|
|
92
test/test_usr1.py
Normal file
92
test/test_usr1.py
Normal file
|
@ -0,0 +1,92 @@
|
|||
import os
|
||||
import unittest
|
||||
from subprocess import call
|
||||
from unit.applications.lang.python import TestApplicationPython
|
||||
|
||||
|
||||
class TestUSR1(TestApplicationPython):
|
||||
prerequisites = {'modules': ['python']}
|
||||
|
||||
def test_usr1_access_log(self):
|
||||
self.load('empty')
|
||||
|
||||
log_path = self.testdir + '/access.log'
|
||||
|
||||
self.assertIn(
|
||||
'success',
|
||||
self.conf('"' + log_path + '"', 'access_log'),
|
||||
'access log configure',
|
||||
)
|
||||
|
||||
self.assertTrue(self.waitforfiles(log_path), 'open')
|
||||
|
||||
log_path_new = self.testdir + '/new.log'
|
||||
|
||||
os.rename(log_path, log_path_new)
|
||||
|
||||
self.get()
|
||||
|
||||
self.assertIsNotNone(
|
||||
self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "-" "-"', 'new.log'),
|
||||
'rename new',
|
||||
)
|
||||
self.assertFalse(os.path.isfile(log_path), 'rename old')
|
||||
|
||||
with open(self.testdir + '/unit.pid', 'r') as f:
|
||||
pid = f.read().rstrip()
|
||||
|
||||
call(['kill', '-s', 'USR1', pid])
|
||||
|
||||
self.assertTrue(self.waitforfiles(log_path), 'reopen')
|
||||
|
||||
self.get(url='/usr1')
|
||||
|
||||
self.assertIsNotNone(
|
||||
self.wait_for_record(
|
||||
r'"GET /usr1 HTTP/1.1" 200 0 "-" "-"', 'access.log'
|
||||
),
|
||||
'reopen 2',
|
||||
)
|
||||
self.assertIsNone(
|
||||
self.search_in_log(r'/usr1', 'new.log'), 'rename new 2'
|
||||
)
|
||||
|
||||
@unittest.skip('not yet')
|
||||
def test_usr1_unit_log(self):
|
||||
self.load('log_body')
|
||||
|
||||
log_path = self.testdir + '/unit.log'
|
||||
log_path_new = self.testdir + '/new.log'
|
||||
|
||||
os.rename(log_path, log_path_new)
|
||||
|
||||
body = 'body_for_a_log_new'
|
||||
self.post(body=body)
|
||||
|
||||
self.assertIsNotNone(
|
||||
self.wait_for_record(body, 'new.log'), 'rename new'
|
||||
)
|
||||
self.assertFalse(os.path.isfile(log_path), 'rename old')
|
||||
|
||||
with open(self.testdir + '/unit.pid', 'r') as f:
|
||||
pid = f.read().rstrip()
|
||||
|
||||
call(['kill', '-s', 'USR1', pid])
|
||||
|
||||
self.assertTrue(self.waitforfiles(log_path), 'reopen')
|
||||
|
||||
body = 'body_for_a_log_unit'
|
||||
self.post(body=body)
|
||||
|
||||
self.assertIsNotNone(self.wait_for_record(body), 'rename new')
|
||||
self.assertIsNone(self.search_in_log(body, 'new.log'), 'rename new 2')
|
||||
|
||||
# merge two log files into unit.log to check alerts
|
||||
|
||||
with open(log_path, 'w') as unit_log, \
|
||||
open(log_path_new, 'r') as new_log:
|
||||
unit_log.write(new_log.read())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
TestUSR1.main()
|
Loading…
Reference in a new issue