diff options
author | Max Romanov <max.romanov@nginx.com> | 2021-04-08 19:11:11 +0300 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2021-04-08 19:11:11 +0300 |
commit | 74b1b1fc17726d805b00dee6b5547254f5cf230c (patch) | |
tree | 54c4fee99f1ff735431fe4b4f83fb7e04c7dacba /test/unit | |
parent | 30922c5741af0c712f465d0e98b71f8848c0db91 (diff) | |
download | unit-74b1b1fc17726d805b00dee6b5547254f5cf230c.tar.gz unit-74b1b1fc17726d805b00dee6b5547254f5cf230c.tar.bz2 |
Tests: preserving unit.log when run without restart.
Introducing "unit.log.Log" class for "unit.log" file management.
Moving "findall()" function into TestApplicationProto.
Using "os.kill()" to send signals.
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/applications/proto.py | 18 | ||||
-rw-r--r-- | test/unit/log.py | 23 |
2 files changed, 35 insertions, 6 deletions
diff --git a/test/unit/applications/proto.py b/test/unit/applications/proto.py index 5c400621..92754c03 100644 --- a/test/unit/applications/proto.py +++ b/test/unit/applications/proto.py @@ -4,6 +4,7 @@ import time from unit.control import TestControl from unit.option import option +from unit.log import Log class TestApplicationProto(TestControl): @@ -15,18 +16,23 @@ class TestApplicationProto(TestControl): def date_to_sec_epoch(self, date, template='%a, %d %b %Y %H:%M:%S %Z'): return time.mktime(time.strptime(date, template)) + def findall(self, pattern, name='unit.log'): + with Log.open(name) as f: + return re.findall(pattern, f.read()) + def search_in_log(self, pattern, name='unit.log'): - with open(option.temp_dir + '/' + name, 'r', errors='ignore') as f: + with Log.open(name) as f: return re.search(pattern, f.read()) def wait_for_record(self, pattern, name='unit.log', wait=150): - for i in range(wait): - found = self.search_in_log(pattern, name) + with Log.open(name) as f: + for i in range(wait): + found = re.search(pattern, f.read()) - if found is not None: - break + if found is not None: + break - time.sleep(0.1) + time.sleep(0.1) return found diff --git a/test/unit/log.py b/test/unit/log.py new file mode 100644 index 00000000..7263443d --- /dev/null +++ b/test/unit/log.py @@ -0,0 +1,23 @@ +UNIT_LOG = 'unit.log' + + +class Log: + temp_dir = None + pos = {} + + def open(name=UNIT_LOG, encoding=None): + f = open(Log.get_path(name), 'r', encoding=encoding, errors='ignore') + f.seek(Log.pos.get(name, 0)) + + return f + + def set_pos(pos, name=UNIT_LOG): + Log.pos[name] = pos + + def swap(name): + pos = Log.pos.get(UNIT_LOG, 0) + Log.pos[UNIT_LOG] = Log.pos.get(name, 0) + Log.pos[name] = pos + + def get_path(name=UNIT_LOG): + return Log.temp_dir + '/' + name |