-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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,20 +64,53 @@ 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: [email protected]') | ||
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: [email protected]') | ||
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() | ||
f.close() | ||
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() |