[Buildbot-commits] buildbot/buildbot/test test_web.py,1.5,1.6
Brian Warner
warner at users.sourceforge.net
Sat Apr 2 00:56:49 UTC 2005
Update of /cvsroot/buildbot/buildbot/buildbot/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23408/buildbot/test
Modified Files:
test_web.py
Log Message:
rearrange server-setup and teardown code to remove unclean-reactor warnings
from twisted-2.0
Index: test_web.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_web.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- test_web.py 14 Oct 2004 16:47:32 -0000 1.5
+++ test_web.py 2 Apr 2005 00:56:46 -0000 1.6
@@ -7,7 +7,7 @@
from twisted.trial import unittest
dr = unittest.deferredResult
-from twisted.internet import reactor
+from twisted.internet import reactor, defer
from twisted.internet.interfaces import IReactorUNIX
from twisted.web import client
@@ -41,21 +41,32 @@
-def distrib_unix(unixpath):
- from twisted.web import server, resource, distrib
- root = resource.Resource()
- r = distrib.ResourceSubscription("unix", unixpath)
- root.putChild('remote', r)
- p = reactor.listenTCP(0, server.Site(root))
- return p
+class DistribUNIX:
+ def __init__(self, unixpath):
+ from twisted.web import server, resource, distrib
+ root = resource.Resource()
+ self.r = r = distrib.ResourceSubscription("unix", unixpath)
+ root.putChild('remote', r)
+ self.p = p = reactor.listenTCP(0, server.Site(root))
+ self.portnum = p.getHost().port
+ def shutdown(self):
+ d = defer.maybeDeferred(self.p.stopListening)
+ return d
-def distrib_tcp(port):
- from twisted.web import server, resource, distrib
- root = resource.Resource()
- r = distrib.ResourceSubscription("localhost", port)
- root.putChild('remote', r)
- p = reactor.listenTCP(0, server.Site(root))
- return p
+class DistribTCP:
+ def __init__(self, port):
+ from twisted.web import server, resource, distrib
+ root = resource.Resource()
+ self.r = r = distrib.ResourceSubscription("localhost", port)
+ root.putChild('remote', r)
+ self.p = p = reactor.listenTCP(0, server.Site(root))
+ self.portnum = p.getHost().port
+ def shutdown(self):
+ d = defer.maybeDeferred(self.p.stopListening)
+ d.addCallback(self._shutdown_1)
+ return d
+ def _shutdown_1(self, res):
+ return self.r.publisher.broker.transport.loseConnection()
class WebTest(unittest.TestCase):
@@ -95,14 +106,13 @@
m = ConfiguredMaster("test_web2", cfg)
m.startService()
- p = distrib_unix("test_web2/.web-pb")
- port = p.getHost().port
+ p = DistribUNIX("test_web2/.web-pb")
- d = client.getPage("http://localhost:%d/remote/" % port)
+ d = client.getPage("http://localhost:%d/remote/" % p.portnum)
page = dr(d)
#print page
self.failUnless(page)
- dr(p.stopListening())
+ dr(p.shutdown())
dr(m.stopService())
@@ -116,13 +126,11 @@
m.startService()
dport = list(self.find_waterfall(m)[0])[0]._port.getHost().port
- p = distrib_tcp(dport)
- port = p.getHost().port
+ p = DistribTCP(dport)
- d = client.getPage("http://localhost:%d/remote/" % port)
+ d = client.getPage("http://localhost:%d/remote/" % p.portnum)
page = dr(d)
#print page
self.failUnless(page)
- dr(p.stopListening())
+ dr(p.shutdown())
dr(m.stopService())
-
More information about the Commits
mailing list