[Buildbot-commits] buildbot/buildbot/test test_slavecommand.py,1.5,1.6 test_maildir.py,1.1,1.2

Brian Warner warner at users.sourceforge.net
Thu Oct 14 17:28:36 UTC 2004


Update of /cvsroot/buildbot/buildbot/buildbot/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15955/buildbot/test

Modified Files:
	test_slavecommand.py test_maildir.py 
Log Message:
* buildbot/test/test_maildir.py (MaildirTest): use shutil.rmtree
instead of os.system("rm -rf") for win32 portability

* buildbot/test/test_slavecommand.py (SlaveCommandTestCase): use
SignalMixin instead of starting/stopping the reactor, which is
likely to cause problems with other tests


Index: test_maildir.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_maildir.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- test_maildir.py	8 Jan 2004 20:05:24 -0000	1.1
+++ test_maildir.py	14 Oct 2004 17:28:34 -0000	1.2
@@ -1,7 +1,7 @@
 #! /usr/bin/python
 
 from twisted.trial import unittest
-import os
+import os, shutil
 from buildbot.changes.mail import FCMaildirSource
 from twisted.internet import reactor
 from twisted.python import util
@@ -11,7 +11,7 @@
         print "creating empty maildir"
         self.maildir = "test-maildir"
         if os.path.isdir(self.maildir):
-            os.system("rm -rf %s" % self.maildir)
+            shutil.rmtree(self.maildir)
             print "removing stale maildir"
         os.mkdir(self.maildir)
         os.mkdir(os.path.join(self.maildir, "cur"))
@@ -22,7 +22,7 @@
 
     def tearDown(self):
         print "removing old maildir"
-        os.system("rm -rf %s" % self.maildir)
+        shutil.rmtree(self.maildir)
         if self.source:
             self.source.stopService()
 

Index: test_slavecommand.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_slavecommand.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- test_slavecommand.py	30 Aug 2004 20:27:11 -0000	1.5
+++ test_slavecommand.py	14 Oct 2004 17:28:34 -0000	1.6
@@ -11,7 +11,8 @@
     import sys
     startLogging(sys.stdout)
 
-import re
+import re, time
+import signal
 
 from buildbot.slave.commands import SlaveShellCommand
 
@@ -48,7 +49,23 @@
         self.updates.append(data)
 
 
-class SlaveCommandTestCase(unittest.TestCase):
+class SignalMixin:
+    sigchldHandler = None
+    
+    def setUpClass(self):
+        # make sure SIGCHLD handler is installed, as it should be on
+        # reactor.run(). problem is reactor may not have been run when this
+        # test runs.
+        if hasattr(reactor, "_handleSigchld") and hasattr(signal, "SIGCHLD"):
+            self.sigchldHandler = signal.signal(signal.SIGCHLD,
+                                                reactor._handleSigchld)
+    
+    def tearDownClass(self):
+        if self.sigchldHandler:
+            signal.signal(signal.SIGCHLD, self.sigchldHandler)
+
+
+class SlaveCommandTestCase(SignalMixin, unittest.TestCase):
 
     def setUp(self):
         self.builder = FakeSlaveBuilder()
@@ -60,7 +77,6 @@
     def callback(self, failed):
         self.failed = failed
         self.results = self.builder.updates
-        reactor.stop()
 
     def doTest(self, commandfactory, args):
         builder = self.builder
@@ -69,8 +85,12 @@
         cmd = commandfactory(builder, stepId, args)
         d = cmd.start()
         d.addCallbacks(builder.commandComplete, builder.commandFailed)
-        # we must make sure SIGCHLD gets registered
-        reactor.run()
+
+        timeout = time.time() + 2
+        while not (self.results or self.failed) and time.time() < timeout:
+            reactor.iterate(0.01)
+        if not (self.results or self.failed):
+            self.fail("timeout")
         if self.failed:
             print self.builder.failure
         return self.failed





More information about the Commits mailing list