cli: suppress DeprecationWarnings emitted from importing nevow and twisted. Fixes...
authordavid-sarah <david-sarah@jacaranda.org>
Mon, 1 Feb 2010 00:44:29 +0000 (16:44 -0800)
committerdavid-sarah <david-sarah@jacaranda.org>
Mon, 1 Feb 2010 00:44:29 +0000 (16:44 -0800)
src/allmydata/__init__.py
src/allmydata/test/test_runner.py

index deebb080a1f7ce2d306dc5de490046a8a5b3a4f6..1827adc88e9d72f8e81910ca147e81c7c6a32458 100644 (file)
@@ -6,6 +6,34 @@ maintainer web site: U{http://allmydata.com/}
 community web site: U{http://allmydata.org/}
 """
 
+# This is just to suppress DeprecationWarnings from nevow and twisted.
+# See http://allmydata.org/trac/tahoe/ticket/859 and
+# http://divmod.org/trac/ticket/2994 .
+import warnings
+warnings.filterwarnings("ignore", category=DeprecationWarning,
+    message="object.__new__\(\) takes no parameters",
+    append=True)
+warnings.filterwarnings("ignore", category=DeprecationWarning,
+    message="The popen2 module is deprecated.  Use the subprocess module.",
+    append=True)
+warnings.filterwarnings("ignore", category=DeprecationWarning,
+    message="the md5 module is deprecated; use hashlib instead",
+    append=True)
+warnings.filterwarnings("ignore", category=DeprecationWarning,
+    message="the sha module is deprecated; use the hashlib module instead",
+    append=True)
+try:
+    import nevow
+    from twisted.persisted import sob
+    from twisted.python import filepath
+    hush_pyflakes = (nevow, sob, filepath)
+    del hush_pyflakes
+finally:
+    warnings.filters.pop()
+    warnings.filters.pop()
+    warnings.filters.pop()
+    warnings.filters.pop()
+
 __version__ = "unknown"
 try:
     from _version import __version__
@@ -27,9 +55,6 @@ except ImportError:
 # http://allmydata.org/trac/tahoe/wiki/Versioning
 __full_version__ = __appname__ + '/' + str(__version__)
 
-hush_pyflakes = __version__
-del hush_pyflakes
-
 import _auto_deps
 _auto_deps.require_auto_deps()
 
index 4aef3da074743f81fdcb618586aec79fe73dea7d..011f3fa2081607d91ddf4cf6d49d2711ceb105c9 100644 (file)
@@ -355,6 +355,63 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
         return d
     test_introducer.timeout = 480 # This hit the 120-second timeout on "François Lenny-armv5tel", then it hit a 240-second timeout on our feisty2.5 buildslave: http://allmydata.org/buildbot/builders/feisty2.5/builds/2381/steps/test/logs/test.log
 
+    def test_client_no_noise(self):
+        self.skip_if_cannot_daemonize()
+        basedir = self.workdir("test_client_no_noise")
+        c1 = os.path.join(basedir, "c1")
+        HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
+        TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
+        PORTNUMFILE = os.path.join(c1, "client.port")
+
+        d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1, "--webport", "0"], env=os.environ)
+        def _cb(res):
+            out, err, rc_or_sig = res
+            errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
+            assert rc_or_sig == 0, errstr
+            self.failUnlessEqual(rc_or_sig, 0)
+            # By writing this file, we get forty seconds before the client will exit. This insures
+            # that even if the 'stop' command doesn't work (and the test fails), the client should
+            # still terminate.
+            open(HOTLINE_FILE, "w").write("")
+            open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n")
+            # now it's safe to start the node
+        d.addCallback(_cb)
+
+        def _start(res):
+            return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
+        d.addCallback(_start)
+
+        def _cb2(res):
+            out, err, rc_or_sig = res
+            errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
+            open(HOTLINE_FILE, "w").write("")
+            self.failUnlessEqual(rc_or_sig, 0, errstr)
+            self.failUnlessEqual(out, "", errstr) # If you emit noise, you fail this test.
+            self.failUnlessEqual(err, "", errstr)
+
+            # the parent (twistd) has exited. However, twistd writes the pid
+            # from the child, not the parent, so we can't expect twistd.pid
+            # to exist quite yet.
+
+            # the node is running, but it might not have made it past the
+            # first reactor turn yet, and if we kill it too early, it won't
+            # remove the twistd.pid file. So wait until it does something
+            # that we know it won't do until after the first turn.
+        d.addCallback(_cb2)
+
+        def _node_has_started():
+            return os.path.exists(PORTNUMFILE)
+        d.addCallback(lambda res: self.poll(_node_has_started))
+
+        # now we can kill it. TODO: On a slow machine, the node might kill
+        # itself before we get a chance too, especially if spawning the
+        # 'tahoe stop' command takes a while.
+        def _stop(res):
+            self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
+            return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
+        d.addCallback(_stop)
+        return d
+
     def test_client(self):
         self.skip_if_cannot_daemonize()
         basedir = self.workdir("test_client")