summaryrefslogtreecommitdiffhomepage
path: root/test/unit.py
diff options
context:
space:
mode:
authorAndrey Zelenkov <zelenkov@nginx.com>2018-03-21 18:26:40 +0300
committerAndrey Zelenkov <zelenkov@nginx.com>2018-03-21 18:26:40 +0300
commitc7e67446a3054998893d64cbab150810d2a99aa5 (patch)
tree55e447f271a8553112d93149851b71a83eb5af43 /test/unit.py
parent37051b6c15cce7d6ab01c50e1086f8ef0b34e93d (diff)
downloadunit-c7e67446a3054998893d64cbab150810d2a99aa5.tar.gz
unit-c7e67446a3054998893d64cbab150810d2a99aa5.tar.bz2
Tests: Ruby module.
Diffstat (limited to 'test/unit.py')
-rw-r--r--test/unit.py43
1 files changed, 40 insertions, 3 deletions
diff --git a/test/unit.py b/test/unit.py
index 892624c1..cdf9ff62 100644
--- a/test/unit.py
+++ b/test/unit.py
@@ -16,12 +16,13 @@ class TestUnit(unittest.TestCase):
pardir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
architecture = platform.architecture()[0]
+ maxDiff = None
def setUp(self):
self._run()
def tearDown(self):
- self._stop()
+ self.stop()
with open(self.testdir + '/unit.log', 'r', encoding='utf-8',
errors='ignore') as f:
@@ -44,7 +45,7 @@ class TestUnit(unittest.TestCase):
break
if m is None:
- self._stop()
+ self.stop()
exit("Unit is writing log too long")
self._check_alerts(log)
@@ -56,12 +57,16 @@ class TestUnit(unittest.TestCase):
missed_module = module
break
- self._stop()
+ self.stop()
shutil.rmtree(self.testdir)
if missed_module:
raise unittest.SkipTest('Unit has no ' + missed_module + ' module')
+ def stop(self):
+ if self._started:
+ self._stop()
+
def _run(self):
self.testdir = tempfile.mkdtemp(prefix='unit-test-')
@@ -85,6 +90,8 @@ class TestUnit(unittest.TestCase):
self.testdir + '/unit.log', self.testdir + '/control.unit.sock'):
exit("Could not start unit")
+ self._started = True
+
self.skip_alerts = [r'read signalfd\(4\) failed']
self.skip_sanitizer = False
@@ -105,6 +112,8 @@ class TestUnit(unittest.TestCase):
if os.path.exists(self.testdir + '/unit.pid'):
exit("Could not terminate unit")
+ self._started = False
+
self._p.join(timeout=1)
self._terminate_process(self._p)
@@ -322,6 +331,16 @@ class TestUnitApplicationProto(TestUnitControl):
current_dir = os.path.dirname(os.path.abspath(__file__))
+ def sec_epoch(self):
+ return time.mktime(time.gmtime())
+
+ def date_to_sec_epoch(self, date):
+ return time.mktime(time.strptime(date, '%a, %d %b %Y %H:%M:%S GMT'))
+
+ def search_in_log(self, pattern):
+ with open(self.testdir + '/unit.log', 'r') as f:
+ return re.search(pattern, f.read())
+
class TestUnitApplicationPython(TestUnitApplicationProto):
def load(self, script, name=None):
if name is None:
@@ -343,6 +362,24 @@ class TestUnitApplicationPython(TestUnitApplicationProto):
}
})
+class TestUnitApplicationRuby(TestUnitApplicationProto):
+ def load(self, script, name='config.ru'):
+ self.conf({
+ "listeners": {
+ "*:7080": {
+ "application": script
+ }
+ },
+ "applications": {
+ script: {
+ "type": "ruby",
+ "processes": { "spare": 0 },
+ "working_directory": self.current_dir + '/ruby/' + script,
+ "script": self.current_dir + '/ruby/' + script + '/' + name
+ }
+ }
+ })
+
class TestUnitApplicationPerl(TestUnitApplicationProto):
def load(self, script, name='psgi.pl'):
self.conf({