summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrey Zelenkov <zelenkov@nginx.com>2018-04-18 16:02:43 +0300
committerAndrey Zelenkov <zelenkov@nginx.com>2018-04-18 16:02:43 +0300
commit961e8d800f916980859ed70cf3f1a1452078e9e6 (patch)
tree65708b9d90bf848eecc68ba90db950260680bb0d
parent3e2326cff15768801e1211c267e650a8e668e8ce (diff)
downloadunit-961e8d800f916980859ed70cf3f1a1452078e9e6.tar.gz
unit-961e8d800f916980859ed70cf3f1a1452078e9e6.tar.bz2
Tests: re-opening access log file.
-rw-r--r--test/test_access_log.py37
-rw-r--r--test/unit.py8
2 files changed, 40 insertions, 5 deletions
diff --git a/test/test_access_log.py b/test/test_access_log.py
index 0ec49a51..8c7fae30 100644
--- a/test/test_access_log.py
+++ b/test/test_access_log.py
@@ -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()
diff --git a/test/unit.py b/test/unit.py
index f1b66221..7a839a66 100644
--- a/test/unit.py
+++ b/test/unit.py
@@ -86,7 +86,7 @@ class TestUnit(unittest.TestCase):
self._p = Process(target=_run_unit)
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'):
exit("Could not start unit")
@@ -151,10 +151,10 @@ class TestUnit(unittest.TestCase):
if found:
print('skipped.')
- def _waitforfiles(self, *files):
+ def waitforfiles(self, *files):
for i in range(50):
wait = False
- ret = 0
+ ret = False
for f in files:
if not os.path.exists(f):
@@ -165,7 +165,7 @@ class TestUnit(unittest.TestCase):
time.sleep(0.1)
else:
- ret = 1
+ ret = True
break
return ret