xref: /unit/test/unit/applications/proto.py (revision 1050)
11019Szelenkov@nginx.comimport re
21019Szelenkov@nginx.comimport time
31019Szelenkov@nginx.comfrom unit.control import TestControl
41019Szelenkov@nginx.com
51019Szelenkov@nginx.com
61019Szelenkov@nginx.comclass TestApplicationProto(TestControl):
71019Szelenkov@nginx.com    def sec_epoch(self):
81019Szelenkov@nginx.com        return time.mktime(time.gmtime())
91019Szelenkov@nginx.com
101019Szelenkov@nginx.com    def date_to_sec_epoch(self, date, template='%a, %d %b %Y %H:%M:%S %Z'):
111019Szelenkov@nginx.com        return time.mktime(time.strptime(date, template))
121019Szelenkov@nginx.com
131027Szelenkov@nginx.com    def search_in_log(self, pattern, name='unit.log'):
141027Szelenkov@nginx.com        with open(self.testdir + '/' + name, 'r', errors='ignore') as f:
151019Szelenkov@nginx.com            return re.search(pattern, f.read())
161028Szelenkov@nginx.com
171028Szelenkov@nginx.com    def wait_for_record(self, pattern, name='unit.log'):
181028Szelenkov@nginx.com        for i in range(50):
191028Szelenkov@nginx.com            found = self.search_in_log(pattern, name)
201028Szelenkov@nginx.com
211028Szelenkov@nginx.com            if found is not None:
221028Szelenkov@nginx.com                break
231028Szelenkov@nginx.com
241028Szelenkov@nginx.com            time.sleep(0.1)
251028Szelenkov@nginx.com
261028Szelenkov@nginx.com        return found
27*1050Szelenkov@nginx.com
28*1050Szelenkov@nginx.com    def _load_conf(self, conf):
29*1050Szelenkov@nginx.com        self.assertIn(
30*1050Szelenkov@nginx.com            'success', self.conf(conf), 'load application configuration'
31*1050Szelenkov@nginx.com        )
32