[Buildbot-commits] buildbot/buildbot/test test_config.py,1.31,1.32

Brian Warner warner at users.sourceforge.net
Fri Nov 25 01:25:13 UTC 2005


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

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

fix test_config.StartService, by not using a fixed slavePort

	* buildbot/test/test_config.py (StartService): don't claim a fixed
	port number, instead set slavePort=0 on the first pass, figure out
	what port was allocated, then switch to a config file that uses
	the allocated port.

	* buildbot/master.py (BuildMaster.loadConfig): close the old
	slaveport before opening the new one, because unit tests might
	replace slavePort=0 with the same allocated portnumber, and if we
	don't wait for the old port to close first, we get a "port already
	in use" error. There is a tiny race condition here, but the only
	threat is from other programs that bind (statically) to the same
	port number we happened to be allocated, and only if those
	programs use SO_REUSEADDR, and only if they get control in between
	reactor turns.


Index: test_config.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_config.py,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- test_config.py	25 Nov 2005 00:36:41 -0000	1.31
+++ test_config.py	25 Nov 2005 01:25:11 -0000	1.32
@@ -874,13 +874,22 @@
         d.addCallback(finishedStalling)
         return d
 
-targetCfg1 = emptyCfg + \
+# we can't actually startService a buildmaster with a config that uses a
+# fixed slavePortnum like 9999, so instead this makes it possible to pass '0'
+# for the first time, and then substitute back in the allocated port number
+# on subsequent passes.
+startableEmptyCfg = emptyCfg + \
+"""
+c['slavePortnum'] = %d
+"""
+                    
+targetCfg1 = startableEmptyCfg + \
 """
 from buildbot.test.test_config import MyTarget
 c['status'] = [MyTarget('a')]
 """
 
-targetCfg2 = emptyCfg + \
+targetCfg2 = startableEmptyCfg + \
 """
 from buildbot.test.test_config import MySlowTarget
 c['status'] = [MySlowTarget('b')]
@@ -893,12 +902,20 @@
     def testStartService(self):
         os.mkdir("test_ss")
         self.master = m = BuildMaster("test_ss")
-        m.loadConfig(emptyCfg)
         m.startService()
+        d = m.loadConfig(startableEmptyCfg % 0)
+        d.addCallback(self._testStartService_0)
+        return maybeWait(d)
+
+    def _testStartService_0(self, res):
+        m = self.master
         m.targetevents = []
-        d = m.loadConfig(targetCfg1)
+        # figure out what port got allocated
+        self.portnum = m.slavePort._port.getHost().port
+        d = m.loadConfig(targetCfg1 % self.portnum)
         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))
@@ -906,16 +923,18 @@
                              [('start', 'a')])
         self.master.targetevents = []
         # reloading the same config should not start or stop the target
-        d = self.master.loadConfig(targetCfg1)
+        d = self.master.loadConfig(targetCfg1 % self.portnum)
         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 = self.master.loadConfig(targetCfg2 % self.portnum)
         d.addCallback(self._testStartService_3)
         return d
+
     def _testStartService_3(self, res):
         self.failUnlessEqual(self.master.targetevents,
                              [('stop', 'a'), ('start', 'b')])
@@ -923,9 +942,10 @@
         # 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 = self.master.loadConfig(targetCfg1 % self.portnum)
         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