[Buildbot-commits] buildbot/buildbot/test test_changes.py,1.5,1.6 test_config.py,1.26,1.27 test_status.py,1.23,1.24 test_control.py,1.8,1.9

Brian Warner warner at users.sourceforge.net
Fri Oct 14 19:48:00 UTC 2005


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

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

remove almost all remaining uses of deferredResult from unit tests

	* buildbot/test/test_changes.py: remove use of deferredResult
	* buildbot/test/test_config.py: same
	* buildbot/test/test_control.py: same
	* buildbot/test/test_status.py: same
	* buildbot/test/test_vc.py: this is the only remaining use, since
	it gets used at module level. This needs to be replaced by some
	sort of class-level run-once routine.


Index: test_changes.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_changes.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- test_changes.py	19 Jul 2005 23:11:58 -0000	1.5
+++ test_changes.py	14 Oct 2005 19:47:58 -0000	1.6
@@ -1,11 +1,11 @@
 # -*- test-case-name: buildbot.test.test_changes -*-
 
 from twisted.trial import unittest
-dr = unittest.deferredResult
 from twisted.internet import defer, reactor
 from twisted.python import log
 
 from buildbot import master
+from buildbot.twcompat import maybeWait
 from buildbot.changes import pb
 from buildbot.scripts import runner
 
@@ -78,50 +78,61 @@
         self.master = master.BuildMaster(".")
     def tearDown(self):
         d = defer.maybeDeferred(self.master.stopService)
-        dr(d)
         # TODO: something in Twisted-2.0.0 (and probably 2.0.1) doesn't shut
         # down the Broker listening socket when it's supposed to.
         # Twisted-1.3.0, and current SVN (which will be post-2.0.1) are ok.
         # This iterate() is a quick hack to deal with the problem. I need to
         # investigate more thoroughly and find a better solution.
-        reactor.iterate()
+        d.addCallback(self.stall, 0.1)
+        return maybeWait(d)
+
+    def stall(self, res, timeout):
+        d = defer.Deferred()
+        reactor.callLater(timeout, d.callback, res)
+        return d
 
     def testSender(self):
-        d = self.master.loadConfig(config_empty)
-        dr(d)
+        self.master.loadConfig(config_empty)
         self.master.startService()
         # TODO: BuildMaster.loadChanges replaces the change_svc object, so we
         # have to load it twice. Clean this up.
         d = self.master.loadConfig(config_sender)
-        dr(d)
+        d.addCallback(self._testSender_1)
+        return maybeWait(d)
 
-        cm = self.master.change_svc
-        s1 = list(cm)[0]
+    def _testSender_1(self, res):
+        self.cm = cm = self.master.change_svc
+        s1 = list(self.cm)[0]
         port = self.master.slavePort._port.getHost().port
 
-        options = {'username': "alice",
-                   'master': "localhost:%d" % port,
-                   'files': ["foo.c"],
-                   }
+        self.options = {'username': "alice",
+                        'master': "localhost:%d" % port,
+                        'files': ["foo.c"],
+                        }
 
-        d = runner.sendchange(options)
-        dr(d)
+        d = runner.sendchange(self.options)
+        d.addCallback(self._testSender_2)
+        return d
 
+    def _testSender_2(self, res):
         # now check that the change was received
-        self.failUnlessEqual(len(cm.changes), 1)
-        c = cm.changes.pop()
+        self.failUnlessEqual(len(self.cm.changes), 1)
+        c = self.cm.changes.pop()
         self.failUnlessEqual(c.who, "alice")
         self.failUnlessEqual(c.files, ["foo.c"])
         self.failUnlessEqual(c.comments, "")
         self.failUnlessEqual(c.revision, None)
 
-        options['revision'] = "r123"
-        options['comments'] = "test change"
+        self.options['revision'] = "r123"
+        self.options['comments'] = "test change"
 
-        d = runner.sendchange(options)
-        dr(d)
-        self.failUnlessEqual(len(cm.changes), 1)
-        c = cm.changes.pop()
+        d = runner.sendchange(self.options)
+        d.addCallback(self._testSender_3)
+        return d
+
+    def _testSender_3(self, res):
+        self.failUnlessEqual(len(self.cm.changes), 1)
+        c = self.cm.changes.pop()
         self.failUnlessEqual(c.who, "alice")
         self.failUnlessEqual(c.files, ["foo.c"])
         self.failUnlessEqual(c.comments, "test change")
@@ -132,27 +143,33 @@
         f = open(logfile, "wt")
         f.write("longer test change")
         f.close()
-        options['comments'] = None
-        options['logfile'] = logfile
+        self.options['comments'] = None
+        self.options['logfile'] = logfile
 
-        d = runner.sendchange(options)
-        dr(d)
-        self.failUnlessEqual(len(cm.changes), 1)
-        c = cm.changes.pop()
+        d = runner.sendchange(self.options)
+        d.addCallback(self._testSender_4)
+        return d
+
+    def _testSender_4(self, res):
+        self.failUnlessEqual(len(self.cm.changes), 1)
+        c = self.cm.changes.pop()
         self.failUnlessEqual(c.who, "alice")
         self.failUnlessEqual(c.files, ["foo.c"])
         self.failUnlessEqual(c.comments, "longer test change")
         self.failUnlessEqual(c.revision, "r123")
 
         # make sure that numeric revisions work too
-        options['logfile'] = None
-        del options['revision']
-        options['revision_number'] = 42
+        self.options['logfile'] = None
+        del self.options['revision']
+        self.options['revision_number'] = 42
 
-        d = runner.sendchange(options)
-        dr(d)
-        self.failUnlessEqual(len(cm.changes), 1)
-        c = cm.changes.pop()
+        d = runner.sendchange(self.options)
+        d.addCallback(self._testSender_5)
+        return d
+
+    def _testSender_5(self, res):
+        self.failUnlessEqual(len(self.cm.changes), 1)
+        c = self.cm.changes.pop()
         self.failUnlessEqual(c.who, "alice")
         self.failUnlessEqual(c.files, ["foo.c"])
         self.failUnlessEqual(c.comments, "")

Index: test_config.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_config.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- test_config.py	14 Oct 2005 19:42:39 -0000	1.26
+++ test_config.py	14 Oct 2005 19:47:58 -0000	1.27
@@ -4,7 +4,6 @@
 import os, os.path
 
 from twisted.trial import unittest
-dr = unittest.deferredResult
 from twisted.python import components, failure
 from twisted.internet import defer
 
@@ -452,6 +451,7 @@
         self.failUnlessEqual(master.checker.users,
                              {"change": "changepw"})
 
+
     def testSources(self):
         if not cvstoys:
             raise unittest.SkipTest("this test needs CVSToys installed")
@@ -469,27 +469,36 @@
 """
 
         d = master.loadConfig(sourcesCfg)
-        dr(d)
-        self.failUnlessEqual(len(list(master.change_svc)), 1)
-        s1 = list(master.change_svc)[0]
+        d.addCallback(self._testSources_1)
+        return maybeWait(d)
+
+    def _testSources_1(self, res):
+        self.failUnlessEqual(len(list(self.buildmaster.change_svc)), 1)
+        s1 = list(self.buildmaster.change_svc)[0]
         self.failUnless(isinstance(s1, FreshCVSSource))
         self.failUnlessEqual(s1.where, ("cvs.example.com", 1000))
         self.failUnlessEqual(s1.prefix, "Prefix/")
-        self.failUnlessEqual(s1, list(master.change_svc)[0])
+        self.failUnlessEqual(s1, list(self.buildmaster.change_svc)[0])
         self.failUnless(s1.parent)
 
         # verify that unchanged sources are not interrupted
-        d = master.loadConfig(sourcesCfg)
-        dr(d)
-        self.failUnlessEqual(len(list(master.change_svc)), 1)
-        s2 = list(master.change_svc)[0]
+        d = self.buildmaster.loadConfig(sourcesCfg)
+        d.addCallback(self._testSources_2)
+        return d
+
+    def _testSources_2(self, res):
+        self.failUnlessEqual(len(list(self.buildmaster.change_svc)), 1)
+        s2 = list(self.buildmaster.change_svc)[0]
         self.failUnlessIdentical(s1, s2)
         self.failUnless(s1.parent)
 
         # make sure we can get rid of the sources too
-        d = master.loadConfig(emptyCfg)
-        dr(d)
-        self.failUnlessEqual(list(master.change_svc), [])
+        d = self.buildmaster.loadConfig(emptyCfg)
+        d.addCallback(self._testSources_3)
+        return d
+
+    def _testSources_3(self, res):
+        self.failUnlessEqual(list(self.buildmaster.change_svc), [])
 
     def shouldBeFailure(self, res, *expected):
         self.failUnless(isinstance(res, failure.Failure),
@@ -664,89 +673,103 @@
         master = self.buildmaster
         master.loadChanges()
         d = master.loadConfig(emptyCfg)
-        dr(d)
-        self.checkIRC(master, {})
-
-        d = master.loadConfig(ircCfg1)
-        dr(d)
-        expected = {'irc.us.freenode.net': ('buildbot', ['twisted'])}
-        self.checkIRC(master, expected)
-
-        d = master.loadConfig(ircCfg2)
-        dr(d)
-        expected = {'irc.us.freenode.net': ('buildbot', ['twisted']),
-                    'irc.example.com': ('otherbot', ['chan1', 'chan2'])}
-        self.checkIRC(master, expected)
-
-        d = master.loadConfig(ircCfg3)
-        dr(d)
-        expected = {'irc.us.freenode.net': ('buildbot', ['knotted'])}
-        self.checkIRC(master, expected)
-
-        d = master.loadConfig(ircCfg1)
-        dr(d)
-        expected = {'irc.us.freenode.net': ('buildbot', ['twisted'])}
-        self.checkIRC(master, expected)
+        e1 = {}
+        d.addCallback(lambda res: self.checkIRC(master, e1))
+        d.addCallback(lambda res: master.loadConfig(ircCfg1))
+        e2 = {'irc.us.freenode.net': ('buildbot', ['twisted'])}
+        d.addCallback(lambda res: self.checkIRC(master, e2))
+        d.addCallback(lambda res: master.loadConfig(ircCfg2))
+        e3 = {'irc.us.freenode.net': ('buildbot', ['twisted']),
+              'irc.example.com': ('otherbot', ['chan1', 'chan2'])}
+        d.addCallback(lambda res: self.checkIRC(master, e3))
+        d.addCallback(lambda res: master.loadConfig(ircCfg3))
+        e4 = {'irc.us.freenode.net': ('buildbot', ['knotted'])}
+        d.addCallback(lambda res: self.checkIRC(master, e4))
+        d.addCallback(lambda res: master.loadConfig(ircCfg1))
+        e5 = {'irc.us.freenode.net': ('buildbot', ['twisted'])}
+        d.addCallback(lambda res: self.checkIRC(master, e5))
+        return maybeWait(d)
 
     def testWebPortnum(self):
         master = self.buildmaster
         master.loadChanges()
 
         d = master.loadConfig(webCfg1)
-        dr(d)
-        ports = self.checkPorts(master, [(9999, pb.PBServerFactory),
-                                         (9980, Site)])
+        d.addCallback(self._testWebPortnum_1)
+        return maybeWait(d)
+    def _testWebPortnum_1(self, res):
+        ports = self.checkPorts(self.buildmaster, [(9999, pb.PBServerFactory),
+                                                   (9980, Site)])
         p = ports[1]
 
-        d = master.loadConfig(webCfg1) # nothing should be changed
-        dr(d)
-        ports = self.checkPorts(master, [(9999, pb.PBServerFactory),
-                                         (9980, Site)])
+        d = self.buildmaster.loadConfig(webCfg1) # nothing should be changed
+        d.addCallback(self._testWebPortnum_2, p)
+        return d
+    def _testWebPortnum_2(self, res, p):
+        ports = self.checkPorts(self.buildmaster, [(9999, pb.PBServerFactory),
+                                                   (9980, Site)])
         self.failUnlessIdentical(p, ports[1],
                                  "web port was changed even though " + \
                                  "configuration was not")
 
-        d = master.loadConfig(webCfg2) # changes to 9981
-        dr(d)
-        ports = self.checkPorts(master, [(9999, pb.PBServerFactory),
-                                         (9981, Site)])
+        d = self.buildmaster.loadConfig(webCfg2) # changes to 9981
+        d.addCallback(self._testWebPortnum_3, p)
+        return d
+    def _testWebPortnum_3(self, res, p):
+        ports = self.checkPorts(self.buildmaster, [(9999, pb.PBServerFactory),
+                                                   (9981, Site)])
         self.failIf(p is ports[1],
                     "web port was unchanged but configuration was changed")
 
-        d = master.loadConfig(emptyCfg)
-        dr(d)
-        self.checkPorts(master, [(9999, pb.PBServerFactory)])
+        d = self.buildmaster.loadConfig(emptyCfg)
+        d.addCallback(lambda res:
+                      self.checkPorts(self.buildmaster,
+                                      [(9999, pb.PBServerFactory)]))
+        return d
 
     def testWebPathname(self):
         master = self.buildmaster
         master.loadChanges()
 
         d = master.loadConfig(webNameCfg1)
-        dr(d)
-        self.checkPorts(master, [(9999, pb.PBServerFactory),
-                                 ('~/.twistd-web-pb', pb.PBServerFactory)])
-        unixports = self.UNIXports(master)
+        d.addCallback(self._testWebPathname_1)
+        return maybeWait(d)
+    def _testWebPathname_1(self, res):
+        self.checkPorts(self.buildmaster,
+                        [(9999, pb.PBServerFactory),
+                         ('~/.twistd-web-pb', pb.PBServerFactory)])
+        unixports = self.UNIXports(self.buildmaster)
         f = unixports[0].args[1]
         self.failUnless(isinstance(f.root, ResourcePublisher))
 
-        d = master.loadConfig(webNameCfg1) # nothing should be changed
-        dr(d)
-        self.checkPorts(master, [(9999, pb.PBServerFactory),
-                                 ('~/.twistd-web-pb', pb.PBServerFactory)])
-        self.failUnlessIdentical(f, self.UNIXports(master)[0].args[1],
+        d = self.buildmaster.loadConfig(webNameCfg1)
+        # nothing should be changed
+        d.addCallback(self._testWebPathname_2, f)
+        return d
+    def _testWebPathname_2(self, res, f):
+        self.checkPorts(self.buildmaster,
+                        [(9999, pb.PBServerFactory),
+                         ('~/.twistd-web-pb', pb.PBServerFactory)])
+        self.failUnlessIdentical(f,
+                                 self.UNIXports(self.buildmaster)[0].args[1],
                                  "web factory was changed even though " + \
                                  "configuration was not")
 
-        d = master.loadConfig(webNameCfg2)
-        dr(d)
-        self.checkPorts(master, [(9999, pb.PBServerFactory),
-                                 ('bar.socket', pb.PBServerFactory)])
-        self.failIf(f is self.UNIXports(master)[0].args[1],
+        d = self.buildmaster.loadConfig(webNameCfg2)
+        d.addCallback(self._testWebPathname_3, f)
+        return d
+    def _testWebPathname_3(self, res, f):
+        self.checkPorts(self.buildmaster,
+                        [(9999, pb.PBServerFactory),
+                         ('bar.socket', pb.PBServerFactory)])
+        self.failIf(f is self.UNIXports(self.buildmaster)[0].args[1],
                     "web factory was unchanged but configuration was changed")
 
-        d = master.loadConfig(emptyCfg)
-        dr(d)
-        self.checkPorts(master, [(9999, pb.PBServerFactory)])
+        d = self.buildmaster.loadConfig(emptyCfg)
+        d.addCallback(lambda res:
+                      self.checkPorts(self.buildmaster,
+                                      [(9999, pb.PBServerFactory)]))
+        return d
 
     def testDebugPassword(self):
         master = self.buildmaster

Index: test_control.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_control.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- test_control.py	17 Aug 2005 02:15:38 -0000	1.8
+++ test_control.py	14 Oct 2005 19:47:58 -0000	1.9
@@ -3,7 +3,6 @@
 import sys, os, signal, shutil, time, errno
 
 from twisted.trial import unittest
-dr = unittest.deferredResult
 from twisted.internet import defer, reactor
 
 from buildbot import master, interfaces
@@ -80,18 +79,7 @@
         self.slave = slave
         slave.startService()
         d = self.master.botmaster.waitUntilBuilderAttached("force")
-        dr(d)
-
-    def loadConfig(self, config):
-        # reloading the config file causes a new 'listDirs' command to be
-        # sent to the slave. To synchronize on this properly, it is easiest
-        # to stop and restart the slave.
-        if self.slave:
-            d = self.master.botmaster.waitUntilBuilderDetached("force")
-            dr(defer.maybeDeferred(self.slave.stopService))
-            dr(d)
-        self.master.loadConfig(config)
-        self.connectSlave()
+        return d
 
     def tearDown(self):
         dl = []
@@ -107,23 +95,25 @@
         # test is scheduled to be removed soon
         m = self.master
         m.loadConfig(config)
-        m.readConfig = True
         m.startService()
-        self.connectSlave()
+        d = self.connectSlave()
+        d.addCallback(self._testForce_1)
+        return maybeWait(d)
 
-        c = interfaces.IControl(m)
+    def _testForce_1(self, res):
+        c = interfaces.IControl(self.master)
         builder_control = c.getBuilder("force")
         d = builder_control.forceBuild("bob", "I was bored")
-        d.addCallback(self._testForce_1)
-        return maybeWait(d)
+        d.addCallback(self._testForce_2)
+        return d
 
-    def _testForce_1(self, build_control):
+    def _testForce_2(self, build_control):
         self.failUnless(providedBy(build_control, interfaces.IBuildControl))
         d = build_control.getStatus().waitUntilFinished()
-        d.addCallback(self._testForce_2)
+        d.addCallback(self._testForce_3)
         return d
 
-    def _testForce_2(self, bs):
+    def _testForce_3(self, bs):
         self.failUnless(providedBy(bs, interfaces.IBuildStatus))
         self.failUnless(bs.isFinished())
         self.failUnlessEqual(bs.getResults(), SUCCESS)
@@ -134,15 +124,17 @@
     def testRequest(self):
         m = self.master
         m.loadConfig(config)
-        m.readConfig = True
         m.startService()
-        self.connectSlave()
-
-        c = interfaces.IControl(m)
+        d = self.connectSlave()
+        d.addCallback(self._testRequest_1)
+        return maybeWait(d)
+    def _testRequest_1(self, res):
+        c = interfaces.IControl(self.master)
         req = base.BuildRequest("I was bored", SourceStamp())
         builder_control = c.getBuilder("force")
         d = defer.Deferred()
         req.subscribe(d.callback)
         builder_control.requestBuild(req)
-        d.addCallback(self._testForce_1)
-        return maybeWait(d)
+        d.addCallback(self._testForce_2)
+        # we use the same check-the-results code as testForce
+        return d

Index: test_status.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_status.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- test_status.py	9 Aug 2005 00:43:35 -0000	1.23
+++ test_status.py	14 Oct 2005 19:47:58 -0000	1.24
@@ -4,7 +4,6 @@
 
 from twisted.internet import defer, reactor
 from twisted.trial import unittest
-dr = unittest.deferredResult
 
 from buildbot import interfaces
 from buildbot.sourcestamp import SourceStamp
@@ -124,6 +123,11 @@
     def setUp(self):
         self.builder = MyBuilder("builder1")
 
+    def stall(self, res, timeout):
+        d = defer.Deferred()
+        reactor.callLater(timeout, d.callback, res)
+        return d
+
     def makeBuild(self, number, results):
         return MyBuild(self.builder, number, results)
 
@@ -339,16 +343,15 @@
 
         print "sending mail to", dest
         d = mailer.buildFinished("builder1", b1, b1.results)
-        dr(d)
-        # the mail has been sent, but the SMTP connection is still up
-        # (because smtp.sendmail relies upon the server to hang up). Spin for
-        # a moment to avoid the "unclean reactor" warning that Trial gives us
-        # if we finish before the socket is disconnected. Really, sendmail()
-        # ought to hang up the connection once it is finished: otherwise a
-        # malicious SMTP server could make us consume lots of memory.
-        d = defer.Deferred()
-        reactor.callLater(0.1, d.callback, None)
-        dr(d)
+        # When this fires, the mail has been sent, but the SMTP connection is
+        # still up (because smtp.sendmail relies upon the server to hang up).
+        # Spin for a moment to avoid the "unclean reactor" warning that Trial
+        # gives us if we finish before the socket is disconnected. Really,
+        # sendmail() ought to hang up the connection once it is finished:
+        # otherwise a malicious SMTP server could make us consume lots of
+        # memory.
+        d.addCallback(self.stall, 0.1)
+        return maybeWait(d)
 
 if not mail:
     Mail.skip = "the Twisted Mail package is not installed"





More information about the Commits mailing list