3 from base_test import DakTestCase
5 from daklib.dakmultiprocessing import DakProcessPool, \
6 PROC_STATUS_SUCCESS, PROC_STATUS_MISCFAILURE, \
7 PROC_STATUS_EXCEPTION, PROC_STATUS_SIGNALRAISED
10 def test_function(num, num2):
11 from os import kill, getpid
14 sigs = [signal.SIGTERM, signal.SIGPIPE, signal.SIGALRM, signal.SIGHUP]
15 kill(getpid(), sigs[num2])
18 raise Exception('Test uncaught exception handling')
20 if num == 0 and num2 == 1:
21 return (PROC_STATUS_MISCFAILURE, 'Test custom error return')
23 return (PROC_STATUS_SUCCESS, 'blah, %d, %d' % (num, num2))
25 class DakProcessPoolTestCase(DakTestCase):
27 def alarm_handler(signum, frame):
28 raise AssertionError('Timed out')
30 # Shouldn't take us more than 15 seconds to run this test
31 signal.signal(signal.SIGALRM, alarm_handler)
37 p.apply_async(test_function, [s, j])
43 signal.signal(signal.SIGALRM, signal.SIG_DFL)
45 expected = [(PROC_STATUS_SUCCESS, 'blah, 0, 0'),
46 (PROC_STATUS_MISCFAILURE, 'Test custom error return'),
47 (PROC_STATUS_SUCCESS, 'blah, 0, 2'),
48 (PROC_STATUS_EXCEPTION, 'Test uncaught exception handling'),
49 (PROC_STATUS_SIGNALRAISED, 15),
50 (PROC_STATUS_SIGNALRAISED, 13),
51 (PROC_STATUS_SIGNALRAISED, 14),
52 (PROC_STATUS_SIGNALRAISED, 1),
53 (PROC_STATUS_SUCCESS, 'blah, 2, 0'),
54 (PROC_STATUS_SUCCESS, 'blah, 2, 1'),
55 (PROC_STATUS_SUCCESS, 'blah, 2, 2'),
56 (PROC_STATUS_EXCEPTION, 'Test uncaught exception handling')]
58 self.assertEqual( len(p.results), len(expected) )
60 for r in range(len(p.results)):
61 self.assertEqual(p.results[r], expected[r])