diff --git a/superlance/tests/crashmail_test.py b/superlance/tests/crashmail_test.py index c7a9667..3b9da62 100644 --- a/superlance/tests/crashmail_test.py +++ b/superlance/tests/crashmail_test.py @@ -1,5 +1,6 @@ import unittest from superlance.compat import StringIO +import re class CrashMailTests(unittest.TestCase): def _getTargetClass(self): @@ -29,7 +30,7 @@ def _makeOnePopulated(self, programs, any, response=None): return prog def test_runforever_not_process_state_exited(self): - programs = {'foo':0, 'bar':0, 'baz_01':0 } + programs = [] any = None prog = self._makeOnePopulated(programs, any) prog.stdin.write('eventname:PROCESS_STATE len:0\n') @@ -38,7 +39,7 @@ def test_runforever_not_process_state_exited(self): self.assertEqual(prog.stderr.getvalue(), 'non-exited event\n') def test_runforever_expected_exit(self): - programs = ['foo'] + programs = [re.compile('foo')] any = None prog = self._makeOnePopulated(programs, any) payload=('expected:1 processname:foo groupname:bar ' @@ -51,7 +52,7 @@ def test_runforever_expected_exit(self): self.assertEqual(prog.stderr.getvalue(), 'expected exit\n') def test_runforever_unexpected_exit(self): - programs = ['foo'] + programs = [re.compile('bar:foo')] any = None prog = self._makeOnePopulated(programs, any) payload=('expected:0 processname:foo groupname:bar ' @@ -63,14 +64,15 @@ def test_runforever_unexpected_exit(self): prog.runforever(test=True) output = prog.stderr.getvalue() lines = output.split('\n') - self.assertEqual(lines[0], 'unexpected exit, mailing') - self.assertEqual(lines[1], 'Mailed:') - self.assertEqual(lines[2], '') - self.assertEqual(lines[3], 'To: chrism@plope.com') - self.assertTrue('Subject: [foo]: foo crashed at' in lines[4]) - self.assertEqual(lines[5], '') + + self.assertEqual(lines[1], 'unexpected exit, mailing') + self.assertEqual(lines[2], 'Mailed:') + self.assertEqual(lines[3], '') + self.assertEqual(lines[4], 'To: chrism@plope.com') + self.assertTrue('Subject: [foo]: foo crashed at' in lines[5]) + self.assertEqual(lines[6], '') self.assertTrue( - 'Process foo in group bar exited unexpectedly' in lines[6]) + 'Process foo in group bar exited unexpectedly' in lines[7]) import os f = open(os.path.join(self.tempdir, 'email.log'), 'r') mail = f.read() @@ -78,5 +80,37 @@ def test_runforever_unexpected_exit(self): self.assertTrue( 'Process foo in group bar exited unexpectedly' in mail) + def test_runforever_unexpected_exit_group(self): + programs = [re.compile('bar:*')] + any = None + prog = self._makeOnePopulated(programs, any) + payload=('expected:0 processname:foo groupname:bar ' + 'from_state:RUNNING pid:1') + prog.stdin.write( + 'eventname:PROCESS_STATE_EXITED len:%s\n' % len(payload)) + prog.stdin.write(payload) + prog.stdin.seek(0) + prog.runforever(test=True) + output = prog.stderr.getvalue() + lines = output.split('\n') + + self.assertEqual(lines[1], 'unexpected exit, mailing') + + def test_runforever_unexpected_exit_ignored(self): + programs = [re.compile('notfoo')] + any = None + prog = self._makeOnePopulated(programs, any) + payload=('expected:0 processname:foo groupname:bar ' + 'from_state:RUNNING pid:1') + prog.stdin.write( + 'eventname:PROCESS_STATE_EXITED len:%s\n' % len(payload)) + prog.stdin.write(payload) + prog.stdin.seek(0) + prog.runforever(test=True) + output = prog.stderr.getvalue() + lines = output.split('\n') + + self.assertTrue('ignoring [foo]: foo crashed ' in lines[1]) + if __name__ == '__main__': unittest.main()