[Buildbot-commits] buildbot/buildbot/test test_config.py,1.29,1.30

Brian Warner warner at users.sourceforge.net
Tue Nov 15 08:57:01 UTC 2005


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

Modified Files:
	test_config.py 
Log Message:
Revision: arch at buildbot.sf.net--2004/buildbot--dev--0--patch-424
Creator:  Brian Warner <warner at lothar.com>

serialize config-file loading

	* buildbot/master.py (BuildMaster.loadConfig): serialize the
	config-file loading, specifically to make sure old StatusTargets
	are finished shutting down before new ones start up (thus
	resolving a bug in which changing the Waterfall object would fail
	because both new and old instances were claiming the same
	listening port). Also load new Schedulers after all the new
	Builders are set up, in case they fire off a new build right away.
	* buildbot/test/test_config.py (StartService): test it


Index: test_config.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_config.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- test_config.py	15 Oct 2005 19:19:18 -0000	1.29
+++ test_config.py	15 Nov 2005 08:56:59 -0000	1.30
@@ -23,7 +23,7 @@
 from buildbot.process.builder import Builder
 from buildbot.process.factory import BasicBuildFactory
 from buildbot.process import step
-from buildbot.status import html, builder
+from buildbot.status import html, builder, base
 try:
     from buildbot.status import words
 except ImportError:
@@ -843,3 +843,88 @@
         m = BuildMaster("test_cf", "alternate.cfg")
         m.loadTheConfigFile()
         self.failUnlessEqual(m.slavePortnum, 9000)
+
+
+class MyTarget(base.StatusReceiverMultiService):
+    def __init__(self, name):
+        self.name = name
+        base.StatusReceiverMultiService.__init__(self)
+    def startService(self):
+        # make a note in a list stashed in the BuildMaster
+        self.parent.targetevents.append(("start", self.name))
+        return base.StatusReceiverMultiService.startService(self)
+    def stopService(self):
+        self.parent.targetevents.append(("stop", self.name))
+        return base.StatusReceiverMultiService.stopService(self)
+
+class MySlowTarget(MyTarget):
+    def stopService(self):
+        from twisted.internet import reactor
+        d = base.StatusReceiverMultiService.stopService(self)
+        def stall(res):
+            d2 = defer.Deferred()
+            reactor.callLater(0.1, d2.callback, res)
+            return d2
+        d.addCallback(stall)
+        m = self.parent
+        def finishedStalling(res):
+            m.targetevents.append(("stop", self.name))
+            return res
+        d.addCallback(finishedStalling)
+        return d
+
+targetCfg1 = emptyCfg + \
+"""
+from buildbot.test.test_config import MyTarget
+c['status'] = [MyTarget('a')]
+"""
+
+targetCfg2 = emptyCfg + \
+"""
+from buildbot.test.test_config import MySlowTarget
+c['status'] = [MySlowTarget('b')]
+"""
+
+class StartService(unittest.TestCase):
+    def tearDown(self):
+        return self.master.stopService()
+
+    def testStartService(self):
+        os.mkdir("test_ss")
+        self.master = m = BuildMaster("test_ss")
+        m.loadConfig(emptyCfg)
+        m.startService()
+        m.targetevents = []
+        d = m.loadConfig(targetCfg1)
+        d.addCallback(self._testStartService_1)
+        return d
+    def _testStartService_1(self, res):
+        self.failUnlessEqual(len(self.master.statusTargets), 1)
+        self.failUnless(isinstance(self.master.statusTargets[0], MyTarget))
+        self.failUnlessEqual(self.master.targetevents,
+                             [('start', 'a')])
+        self.master.targetevents = []
+        # reloading the same config should not start or stop the target
+        d = self.master.loadConfig(targetCfg1)
+        d.addCallback(self._testStartService_2)
+        return d
+    def _testStartService_2(self, res):
+        self.failUnlessEqual(self.master.targetevents, [])
+        # but loading a new config file should stop the old one, then
+        # start the new one
+        d = self.master.loadConfig(targetCfg2)
+        d.addCallback(self._testStartService_3)
+        return d
+    def _testStartService_3(self, res):
+        self.failUnlessEqual(self.master.targetevents,
+                             [('stop', 'a'), ('start', 'b')])
+        self.master.targetevents = []
+        # and going back to the old one should do the same, in the same
+        # order, even though the current MySlowTarget takes a moment to shut
+        # down
+        d = self.master.loadConfig(targetCfg1)
+        d.addCallback(self._testStartService_4)
+        return d
+    def _testStartService_4(self, res):
+        self.failUnlessEqual(self.master.targetevents,
+                             [('stop', 'b'), ('start', 'a')])





More information about the Commits mailing list