]> git.decadent.org.uk Git - dak.git/commitdiff
Merge remote branch 'mhy/multiproc' into merge
authorJoerg Jaspert <joerg@debian.org>
Sat, 7 May 2011 12:39:34 +0000 (14:39 +0200)
committerJoerg Jaspert <joerg@debian.org>
Sat, 7 May 2011 12:39:34 +0000 (14:39 +0200)
* mhy/multiproc:
  Get syntax right
  Deal with args being a tuple
  Add backwards compatibility code
  Make daklog be a Singleton
  Bugfixes for usage of DakProcessPool API
  remove unused variable
  Fix variable name
  Fix function name
  Fix up pool usage
  Enhance process pool implementation

Signed-off-by: Joerg Jaspert <joerg@debian.org>
1  2 
tests/test_multiprocessing.py

index 0000000000000000000000000000000000000000,2d93e8aaacc6d156acff043ad8922c945d934228..595032f756aed0fa792e573cd77b98515f4111ef
mode 000000,100755..100755
--- /dev/null
@@@ -1,0 -1,61 +1,61 @@@
 -                                      PROC_STATUS_EXCEPTION, PROC_STATUS_SIGNALRAISED 
+ #!/usr/bin/python
+ from base_test import DakTestCase
+ from daklib.dakmultiprocessing import DakProcessPool, \
+                                       PROC_STATUS_SUCCESS,   PROC_STATUS_MISCFAILURE, \
++                                      PROC_STATUS_EXCEPTION, PROC_STATUS_SIGNALRAISED
+ import signal
+ def test_function(num, num2):
+     from os import kill, getpid
+     if num == 1:
+         sigs = [signal.SIGTERM, signal.SIGPIPE, signal.SIGALRM, signal.SIGHUP]
+         kill(getpid(), sigs[num2])
+     if num2 == 3:
+         raise Exception('Test uncaught exception handling')
+     if num == 0 and num2 == 1:
+         return (PROC_STATUS_MISCFAILURE, 'Test custom error return')
+     return (PROC_STATUS_SUCCESS, 'blah, %d, %d' % (num, num2))
+ class DakProcessPoolTestCase(DakTestCase):
+     def testPool(self):
+         def alarm_handler(signum, frame):
+             raise AssertionError('Timed out')
+         # Shouldn't take us more than 15 seconds to run this test
+         signal.signal(signal.SIGALRM, alarm_handler)
+         signal.alarm(15)
+         p = DakProcessPool()
+         for s in range(3):
+             for j in range(4):
+                 p.apply_async(test_function, [s, j])
+         p.close()
+         p.join()
+         signal.alarm(0)
+         signal.signal(signal.SIGALRM, signal.SIG_DFL)
+         expected = [(PROC_STATUS_SUCCESS,      'blah, 0, 0'),
+                     (PROC_STATUS_MISCFAILURE,  'Test custom error return'),
+                     (PROC_STATUS_SUCCESS,      'blah, 0, 2'),
+                     (PROC_STATUS_EXCEPTION,    'Test uncaught exception handling'),
+                     (PROC_STATUS_SIGNALRAISED, 15),
+                     (PROC_STATUS_SIGNALRAISED, 13),
+                     (PROC_STATUS_SIGNALRAISED, 14),
+                     (PROC_STATUS_SIGNALRAISED, 1),
+                     (PROC_STATUS_SUCCESS,      'blah, 2, 0'),
+                     (PROC_STATUS_SUCCESS,      'blah, 2, 1'),
+                     (PROC_STATUS_SUCCESS,      'blah, 2, 2'),
+                     (PROC_STATUS_EXCEPTION,    'Test uncaught exception handling')]
+         self.assertEqual( len(p.results), len(expected) )
+         for r in range(len(p.results)):
+             self.assertEqual(p.results[r], expected[r])