[Buildbot-commits] buildbot/buildbot/test test_run.py,1.21,1.22
Brian Warner
warner at users.sourceforge.net
Sat Apr 2 01:41:42 UTC 2005
Update of /cvsroot/buildbot/buildbot/buildbot/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15644/buildbot/test
Modified Files:
test_run.py
Log Message:
(Run.testMaster): change some uses of deferredResult to avoid hangs/warnings
under twisted-2.0
(RunMixin.tearDown): same
(RunMixin.shutdownSlave): same
(Disconnect.testIdle1): same
(Disconnect.testBuild2): same: wait one second after the build finishes for
test to really be done.. this should be cleaned up to avoid wasting that
second. Builder.detach uses a callLater(0), either that should be done
in-line (something else needed that behavior), or it should return a Deferred
that fires when the builder is really offline.
(Disconnect.testBuild3): same
(Disconnect.testDisappear): same
Index: test_run.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_run.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- test_run.py 11 Dec 2004 11:12:33 -0000 1.21
+++ test_run.py 2 Apr 2005 01:41:38 -0000 1.22
@@ -13,6 +13,16 @@
from buildbot.changes.changes import Change
from buildbot.status import builder
+def maybeWait(d, timeout="none"):
+ # this is required for oldtrial (twisted-1.3.0) compatibility. When we
+ # move to retrial (twisted-2.0.0), replace these with a simple 'return
+ # d'.
+ if timeout == "none":
+ unittest.deferredResult(d)
+ else:
+ unittest.deferredResult(d, timeout)
+ return None
+
config_1 = """
from buildbot.process import factory
@@ -125,6 +135,8 @@
self.failUnless(b1.waiting)
# now kill the timer
b1.waiting.stopTimer()
+ d = defer.maybeDeferred(m.stopService)
+ maybeWait(d)
class RunMixin:
master = None
@@ -173,31 +185,44 @@
def tearDown(self):
log.msg("doing tearDown")
- self.shutdownSlave()
+ d = self.shutdownSlave()
+ d.addCallback(self._tearDown_1)
+ d.addCallback(self._tearDown_2)
+ return maybeWait(d)
+ def _tearDown_1(self, res):
if self.master:
- dr(defer.maybeDeferred(self.master.stopService))
- self.master = None
+ return defer.maybeDeferred(self.master.stopService)
+ def _tearDown_2(self, res):
+ self.master = None
log.msg("tearDown done")
# various forms of slave death
- def shutdownSlave(self, waitForMasterToo=True):
+ def shutdownSlave(self, whendone=None):
# the slave has disconnected normally: they SIGINT'ed it, or it shut
# down willingly. This will kill child processes and give them a
- # chance to finish up.
+ # chance to finish up. We return a Deferred that will fire when
+ # everything is finished shutting down.
+
+ # 'whendone' is an optional Deferred that will be fired when the
+ # shutdown is complete
+ log.msg("doing shutdownSlave")
+ dl = []
if self.slave:
- d = self.slave.waitUntilDisconnected()
- dr(defer.maybeDeferred(self.slave.stopService))
- dr(d)
- self.slave = None
+ dl.append(self.slave.waitUntilDisconnected())
+ dl.append(defer.maybeDeferred(self.slave.stopService))
if self.slave2:
- d = self.slave2.waitUntilDisconnected()
- dr(defer.maybeDeferred(self.slave2.stopService))
- dr(d)
- self.slave2 = None
- if waitForMasterToo:
- d = self.master.botmaster.waitUntilBuilderDetached("dummy")
- dr(d)
+ dl.append(self.slave2.waitUntilDisconnected())
+ dl.append(defer.maybeDeferred(self.slave2.stopService))
+ d = defer.DeferredList(dl)
+ d.addCallback(self._shutdownSlaveDone)
+ if whendone:
+ d.addCallback(whendone.callback)
+ return d
+ def _shutdownSlaveDone(self, res):
+ self.slave = None
+ self.slave2 = None
+ return self.master.botmaster.waitUntilBuilderDetached("dummy")
def killSlave(self):
# the slave has died, its host sent a FIN. The .notifyOnDisconnect
@@ -413,8 +438,10 @@
def testIdle1(self):
m,s,c,s1 = self.disconnectSetup()
# disconnect the slave before the build starts
- self.shutdownSlave() # dies before it gets started
-
+ d = self.shutdownSlave() # dies before it gets started
+ d.addCallback(self._testIdle1_1, (m,s,c,s1))
+ return d
+ def _testIdle1_1(self, res, (m,s,c,s1)):
# trying to force a build now will cause an error. Regular builds
# just wait for the slave to re-appear, but forced builds that
# cannot be run right away trigger NoSlaveErrors
@@ -502,11 +529,25 @@
# shutdown the slave while it's running the first step
reactor.callLater(0.5, self.shutdownSlave)
- dr(bs.waitUntilFinished(), 5)
+ d = bs.waitUntilFinished()
+ d.addCallback(self._testBuild2_1, s1, bs)
+ return maybeWait(d, 5)
+ testBuild2.timeout = 5
+
+ def _testBuild2_1(self, res, s1, bs):
+ # we hit here when the build has finished. The builder is still being
+ # torn down, however, so spin for another second to allow the
+ # callLater(0) in Builder.detached to fire.
+ d = defer.Deferred()
+ reactor.callLater(1, d.callback, None)
+ d.addCallback(self._testBuild2_2, s1, bs)
+ return d
+ def _testBuild2_2(self, res, s1, bs):
self.failUnlessEqual(s1.getState()[0], "offline")
self.verifyDisconnect(bs)
+
def testBuild3(self):
m,s,c,s1 = self.disconnectSetup()
# this next sequence is timing-dependent
@@ -514,12 +555,23 @@
bs = bc.getStatus()
# kill the slave while it's running the first step
reactor.callLater(0.5, self.killSlave)
+ d = bs.waitUntilFinished()
+ d.addCallback(self._testBuild3_1, s1, bs)
+ return maybeWait(d, 5)
+ testBuild3.timeout = 5
- dr(bs.waitUntilFinished(), 5)
+ def _testBuild3_1(self, res, s1, bs):
+ # the builder is still being torn down, so give it another second
+ d = defer.Deferred()
+ reactor.callLater(1, d.callback, None)
+ d.addCallback(self._testBuild3_2, s1, bs)
+ return d
+ def _testBuild3_2(self, res, s1, bs):
self.failUnlessEqual(s1.getState()[0], "offline")
self.verifyDisconnect(bs)
+
def testBuild4(self):
m,s,c,s1 = self.disconnectSetup()
# this next sequence is timing-dependent
@@ -551,7 +603,10 @@
# ping should succeed
d = bc.ping(1)
- res = dr(d)
+ d.addCallback(self._testDisappear_1, (m,s,c,s1,bc))
+ return maybeWait(d)
+
+ def _testDisappear_1(self, res, (m,s,c,s1,bc)):
self.failUnlessEqual(res, True)
# now, before any build is run, make the slave disappear
@@ -560,7 +615,9 @@
# at this point, a ping to the slave should timeout
d = bc.ping(1)
- res = dr(d)
+ d.addCallback(self. _testDisappear_2)
+ return d
+ def _testDisappear_2(self, res):
self.failUnlessEqual(res, False)
def testDuplicate(self):
More information about the Commits
mailing list