Tests: re-opening access log file.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
|
import os
|
||||||
|
import re
|
||||||
|
from subprocess import call
|
||||||
import unittest
|
import unittest
|
||||||
import unit
|
import unit
|
||||||
import re
|
|
||||||
|
|
||||||
class TestUnitAccessLog(unit.TestUnitApplicationPython):
|
class TestUnitAccessLog(unit.TestUnitApplicationPython):
|
||||||
|
|
||||||
@@ -216,5 +218,38 @@ Connection: close
|
|||||||
self.search_in_log(r'"GET / HTTP/1.1" 200 0 "-" "-"', 'new.log'),
|
self.search_in_log(r'"GET / HTTP/1.1" 200 0 "-" "-"', 'new.log'),
|
||||||
'change')
|
'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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ class TestUnit(unittest.TestCase):
|
|||||||
self._p = Process(target=_run_unit)
|
self._p = Process(target=_run_unit)
|
||||||
self._p.start()
|
self._p.start()
|
||||||
|
|
||||||
if not self._waitforfiles(self.testdir + '/unit.pid',
|
if not self.waitforfiles(self.testdir + '/unit.pid',
|
||||||
self.testdir + '/unit.log', self.testdir + '/control.unit.sock'):
|
self.testdir + '/unit.log', self.testdir + '/control.unit.sock'):
|
||||||
exit("Could not start unit")
|
exit("Could not start unit")
|
||||||
|
|
||||||
@@ -151,10 +151,10 @@ class TestUnit(unittest.TestCase):
|
|||||||
if found:
|
if found:
|
||||||
print('skipped.')
|
print('skipped.')
|
||||||
|
|
||||||
def _waitforfiles(self, *files):
|
def waitforfiles(self, *files):
|
||||||
for i in range(50):
|
for i in range(50):
|
||||||
wait = False
|
wait = False
|
||||||
ret = 0
|
ret = False
|
||||||
|
|
||||||
for f in files:
|
for f in files:
|
||||||
if not os.path.exists(f):
|
if not os.path.exists(f):
|
||||||
@@ -165,7 +165,7 @@ class TestUnit(unittest.TestCase):
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
ret = 1
|
ret = True
|
||||||
break
|
break
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|||||||
Reference in New Issue
Block a user