[Buildbot-commits] buildbot/buildbot/test test_vc.py,1.28,1.29

Brian Warner warner at users.sourceforge.net
Tue May 17 04:41:01 UTC 2005


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

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

add retry-VC-checkout control (SF#1200395)

Patches applied:

 * warner at monolith.lothar.com--2005/buildbot--dev--0--patch-29
   Merged from arch at buildbot.sf.net--2004 (patch 175-184)

 * warner at monolith.lothar.com--2005/buildbot--dev--0--patch-30
   add retry-VC-checkout control (SF#1200395)


Index: test_vc.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_vc.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- test_vc.py	6 May 2005 06:40:04 -0000	1.28
+++ test_vc.py	17 May 2005 04:40:58 -0000	1.29
@@ -227,13 +227,13 @@
             from twisted.protocols import http
             http._logDateTimeStop() # shut down the internal timer. DUMB!
 
-    def doBuild(self):
+    def doBuild(self, shouldSucceed=True):
         c = interfaces.IControl(self.master)
         
         bc = c.getBuilder("vc").forceBuild(None, "test_vc forced build")
         b = dr(bc.getStatus().waitUntilFinished())
         r = b.getResults()
-        if r != SUCCESS:
+        if r != SUCCESS and shouldSucceed:
             assert b.isFinished()
             print
             print
@@ -246,6 +246,7 @@
                     print "--- STOP ---"
                     print
             self.fail("build did not succeed")
+        return b
 
     def touch(self, d, f):
         open(os.path.join(d,f),"w").close()
@@ -261,7 +262,7 @@
         # woo double-substitution
         s = "s(%s, timeout=200, workdir='build', mode='%%s'" % (vctype,)
         for k,v in args.items():
-            s += ", %s='%s'" % (k, v)
+            s += ", %s=%s" % (k, repr(v))
         s += ")"
         config = config_vc % s
 
@@ -428,7 +429,7 @@
 
     def testBazaarHTTP(self):
         if not VCS.have['baz']:
-            raise unittest.SkipTest("Arch (tla) is not installed")
+            raise unittest.SkipTest("Arch (baz) is not installed")
         self.do_vc("step.Bazaar", {
             'url': VCS.Repository_HTTP % self.httpPort + "/Arch-Repository",
             'archive': "test at buildbot.sf.net--testvc",
@@ -436,10 +437,108 @@
             }, testRetry=False)
         os.system("baz register-archive -d test at buildbot.sf.net--testvc")
 
-class Patch(SetupMixin, unittest.TestCase):
-    def failUnlessIn(self, substr, string):
-        self.failUnless(string.find(substr) != -1)
+class Retry(SetupMixin, unittest.TestCase):
+    fixtimer = None
 
+    def serveHTTP(self):
+        # launch an HTTP server to serve the repository files
+        from twisted.web import static, server
+        from twisted.internet import reactor
+        self.root = static.File(VCS.RepositoryPath)
+        self.site = server.Site(self.root)
+        self.httpServer = reactor.listenTCP(0, self.site)
+        self.httpPort = self.httpServer.getHost().port
+
+    def fixRepository(self):
+        self.fixtimer = None
+        self.site.resource = self.root
+
+    def testRetry_BazaarHTTP(self):
+        # we want to verify that step.Source(retry=) works, and the easiest
+        # way to make VC updates break (temporarily) is to break the HTTP
+        # server that's providing the repository. Anything else pretty much
+        # requires mutating the (read-only) BUILDBOT_TEST_VC repository, or
+        # modifying the buildslave's checkout command while it's running.
+        if not VCS.have['baz']:
+            raise unittest.SkipTest("Arch (baz) is not installed")
+
+        # break the repository server
+        from twisted.web import static
+        self.site.resource = static.Data("Sorry, repository is offline",
+                                         "text/plain")
+        # and arrange to fix it again in 5 seconds, while the test is
+        # running.
+        self.fixtimer = reactor.callLater(5, self.fixRepository)
+
+        b = self.do_vc_once("step.Bazaar", {
+            'url': VCS.Repository_HTTP % self.httpPort + "/Arch-Repository",
+            'archive': "test at buildbot.sf.net--testvc",
+            'version': "testvc--mainline--1",
+            'retry': (5.0, 4),
+            }, shouldSucceed=True)
+
+        workdir = os.path.join(self.slavebase, "vc-dir", "build")
+        self.shouldExist(workdir, "Makefile")
+
+        # make sure there was mention of the retry attempt in the logs
+        l = b.getLogs()[0]
+        self.failUnlessIn("unable to access URL", l.getText(),
+                          "funny, VC operation didn't fail at least once")
+        self.failUnlessIn("update failed, trying 4 more times after 5 seconds",
+                          l.getTextWithHeaders(),
+                          "funny, VC operation wasn't reattempted")
+
+        os.system("baz register-archive -d test at buildbot.sf.net--testvc")
+
+    def testFails_BazaarHTTP(self):
+        # make sure that the build eventually gives up on a repository which
+        # is completely unavailable
+        
+        if not VCS.have['baz']:
+            raise unittest.SkipTest("Arch (baz) is not installed")
+
+        # break the repository server, and leave it broken
+        from twisted.web import static
+        self.site.resource = static.Data("Sorry, repository is offline",
+                                         "text/plain")
+
+        b = self.do_vc_once("step.Bazaar", {
+            'url': VCS.Repository_HTTP % self.httpPort + "/Arch-Repository",
+            'archive': "test at buildbot.sf.net--testvc",
+            'version': "testvc--mainline--1",
+            'retry': (0.5, 3),
+            }, shouldSucceed=False)
+        os.system("baz register-archive -d test at buildbot.sf.net--testvc "
+                  "2>/dev/null")
+
+        self.failUnlessEqual(b.getResults(), builder.FAILURE)
+
+
+    def do_vc_once(self, vctype, args, shouldSucceed):
+        m = self.master
+        vcdir = os.path.join(self.slavebase, "vc-dir", "source")
+        workdir = os.path.join(self.slavebase, "vc-dir", "build")
+        # woo double-substitution
+        s = "s(%s, timeout=200, workdir='build', mode='clobber'" % (vctype,)
+        for k,v in args.items():
+            s += ", %s=%s" % (k, repr(v))
+        s += ")"
+        config = config_vc % s
+
+        m.loadConfig(config)
+        m.readConfig = True
+        m.startService()
+
+        self.connectSlave()
+        b = self.doBuild(shouldSucceed) # initial checkout
+        return b
+
+    def tearDown(self):
+        if self.fixtimer:
+            self.fixtimer.cancel()
+        SetupMixin.tearDown(self)
+
+class Patch(SetupMixin, unittest.TestCase):
     def doPatch(self, vc, revision, **kwargs):
         m = self.master
         config = config_vc % "(step.Dummy)"





More information about the Commits mailing list