Tests: re-opening access log file.

This commit is contained in:
Andrey Zelenkov
2018-04-18 16:02:43 +03:00
parent 3e2326cff1
commit 961e8d800f
2 changed files with 40 additions and 5 deletions

View File

@@ -1,6 +1,8 @@
import os
import re
from subprocess import call
import unittest
import unit
import re
class TestUnitAccessLog(unit.TestUnitApplicationPython):
@@ -216,5 +218,38 @@ Connection: close
self.search_in_log(r'"GET / HTTP/1.1" 200 0 "-" "-"', 'new.log'),
'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.search_in_log(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.assertIsNone(
self.search_in_log(r'/usr1', 'new.log'), 'rename new 2')
self.assertIsNotNone(
self.search_in_log(r'"GET /usr1 HTTP/1.1" 200 0 "-" "-"'),
'reopen 2')
if __name__ == '__main__':
unittest.main()