]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/test/test_runner.py
Makefile: add 'make tmpfstest', which uses a tmpfs for _trial_temp.
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / test / test_runner.py
index 1601a04aa13c3ed45ca5a1f393c2a2744d8dd275..596246267773f1f28f7fb4a9e494a6064094d782 100644 (file)
@@ -88,6 +88,10 @@ class BinTahoe(common_util.SignalMixin, unittest.TestCase, RunBinTahoeMixin):
         if os.path.basename(root_from_cwd) == 'src':
             root_from_cwd = os.path.dirname(root_from_cwd)
 
+        # This is needed if we are running in a temporary directory created by 'make tmpfstest'.
+        if os.path.basename(root_from_cwd).startswith('tmp'):
+            root_from_cwd = os.path.dirname(root_from_cwd)
+
         same = (root_from_cwd == root_to_check)
         if not same:
             try:
@@ -105,6 +109,10 @@ class BinTahoe(common_util.SignalMixin, unittest.TestCase, RunBinTahoeMixin):
             if os.path.basename(root_from_cwdu) == u'src':
                 root_from_cwdu = os.path.dirname(root_from_cwdu)
 
+            # This is needed if we are running in a temporary directory created by 'make tmpfstest'.
+            if os.path.basename(root_from_cwdu).startswith(u'tmp'):
+                root_from_cwdu = os.path.dirname(root_from_cwdu)
+
             if not isinstance(root_from_cwd, unicode) and root_from_cwd.decode(get_filesystem_encoding(), 'replace') != root_from_cwdu:
                 msg += ("However, this may be a false alarm because the current directory path\n"
                         "is not representable in the filesystem encoding. Please run the tests\n"
@@ -128,6 +136,8 @@ class BinTahoe(common_util.SignalMixin, unittest.TestCase, RunBinTahoeMixin):
             self._check_right_code(lines[1])
         d.addCallback(_cb)
         return d
+    # The timeout was exceeded on FreeStorm's CentOS5-i386.
+    test_import_in_repl.timeout = 480
 
     def test_path(self):
         d = self.run_bintahoe(["--version-and-path"])
@@ -147,14 +157,16 @@ class BinTahoe(common_util.SignalMixin, unittest.TestCase, RunBinTahoeMixin):
                              "with a _version.py and 'setup.py darcsver' hasn't been run.")
 
             srcdir = os.path.dirname(os.path.dirname(os.path.normcase(os.path.realpath(srcfile))))
-            info = (res, allmydata.__appname__, required_verstr, srcdir)
+            info = repr((res, allmydata.__appname__, required_verstr, srcdir))
 
             appverpath = out.split(')')[0]
             (appver, path) = appverpath.split(' (')
             (app, ver) = appver.split(': ')
 
             self.failUnlessEqual(app, allmydata.__appname__, info)
-            self.failUnlessEqual(normalized_version(ver), normalized_version(required_verstr), info)
+            norm_ver = normalized_version(ver)
+            norm_required = normalized_version(required_verstr)
+            self.failUnlessEqual(norm_ver, norm_required, info)
             self.failUnlessEqual(path, srcdir, info)
         d.addCallback(_cb)
         return d
@@ -190,12 +202,6 @@ class BinTahoe(common_util.SignalMixin, unittest.TestCase, RunBinTahoeMixin):
     def test_version_no_noise(self):
         self.skip_if_cannot_run_bintahoe()
 
-        from allmydata import get_package_versions, normalized_version
-        twisted_ver = get_package_versions()['Twisted']
-
-        if not normalized_version(twisted_ver) >= normalized_version('9.0.0'):
-            raise unittest.SkipTest("We pass this test only with Twisted >= v9.0.0")
-
         d = self.run_bintahoe(["--version"])
         def _cb(res):
             out, err, rc_or_sig = res
@@ -253,6 +259,8 @@ class CreateNode(unittest.TestCase):
                 self.failUnless(re.search(r"\n\[storage\]\n#.*\nenabled = true\n", content), content)
                 self.failUnless("\nreserved_space = 1G\n" in content)
 
+            self.failUnless(re.search(r"\n\[drop_upload\]\n#.*\nenabled = false\n", content), content)
+
         # creating the node a second time should be rejected
         rc, out, err = self.run_tahoe(argv)
         self.failIfEqual(rc, 0, str((out, err, rc)))
@@ -366,7 +374,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
             # by writing this file, we get ten seconds before the node will
             # exit. This insures that even if the test fails (and the 'stop'
             # command doesn't work), the client should still terminate.
-            open(HOTLINE_FILE, "w").write("")
+            fileutil.write(HOTLINE_FILE, "")
             # now it's safe to start the node
         d.addCallback(_cb)
 
@@ -377,7 +385,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
         def _cb2(res):
             out, err, rc_or_sig = res
 
-            open(HOTLINE_FILE, "w").write("")
+            fileutil.write(HOTLINE_FILE, "")
             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
             self.failUnlessEqual(rc_or_sig, 0, errstr)
             self.failUnlessEqual(out, "", errstr)
@@ -404,7 +412,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
             self.failUnless(os.path.exists(PORTNUM_FILE))
             self.portnum = fileutil.read(PORTNUM_FILE)
 
-            open(HOTLINE_FILE, "w").write("")
+            fileutil.write(HOTLINE_FILE, "")
             self.failUnless(os.path.exists(TWISTD_PID_FILE))
             self.failUnless(os.path.exists(NODE_URL_FILE))
 
@@ -415,7 +423,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
 
         def _then(res):
             out, err, rc_or_sig = res
-            open(HOTLINE_FILE, "w").write("")
+            fileutil.write(HOTLINE_FILE, "")
             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
             self.failUnlessEqual(rc_or_sig, 0, errstr)
             self.failUnlessEqual(out, "", errstr)
@@ -426,13 +434,12 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
         # so poll until it is. This time INTRODUCER_FURL_FILE already
         # exists, so we check for the existence of NODE_URL_FILE instead.
         def _node_has_restarted():
-            return os.path.exists(NODE_URL_FILE)
+            return os.path.exists(NODE_URL_FILE) and os.path.exists(PORTNUM_FILE)
         d.addCallback(lambda res: self.poll(_node_has_restarted))
 
         def _check_same_furl_and_port(res):
             self.failUnless(os.path.exists(INTRODUCER_FURL_FILE))
             self.failUnlessEqual(self.furl, fileutil.read(INTRODUCER_FURL_FILE))
-            self.failUnless(os.path.exists(PORTNUM_FILE))
             self.failUnlessEqual(self.portnum, fileutil.read(PORTNUM_FILE))
         d.addCallback(_check_same_furl_and_port)
 
@@ -440,7 +447,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
         # itself before we get a chance to, especially if spawning the
         # 'tahoe stop' command takes a while.
         def _stop(res):
-            open(HOTLINE_FILE, "w").write("")
+            fileutil.write(HOTLINE_FILE, "")
             self.failUnless(os.path.exists(TWISTD_PID_FILE))
 
             return self.run_bintahoe(["--quiet", "stop", c1])
@@ -448,7 +455,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
 
         def _after_stopping(res):
             out, err, rc_or_sig = res
-            open(HOTLINE_FILE, "w").write("")
+            fileutil.write(HOTLINE_FILE, "")
             # the parent has exited by now
             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
             self.failUnlessEqual(rc_or_sig, 0, errstr)
@@ -459,26 +466,15 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
             # gone by now.
             self.failIf(os.path.exists(TWISTD_PID_FILE))
         d.addCallback(_after_stopping)
-
-        def _remove_hotline(res):
-            os.unlink(HOTLINE_FILE)
-            return res
-        d.addBoth(_remove_hotline)
+        d.addBoth(self._remove, HOTLINE_FILE)
         return d
+    # This test has hit a 240-second timeout on our feisty2.5 buildslave, and a 480-second timeout
+    # on Francois's Lenny-armv5tel buildslave.
     test_introducer.timeout = 960
 
-    # This test hit the 120-second timeout on "Francois 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
-    # Then it hit the 480 second timeout on Francois's machine: http://tahoe-lafs.org/buildbot/builders/FranXois%20lenny-armv5tel/builds/449/steps/test/logs/stdio
-
     def test_client_no_noise(self):
         self.skip_if_cannot_daemonize()
 
-        from allmydata import get_package_versions, normalized_version
-        twisted_ver = get_package_versions()['Twisted']
-
-        if not normalized_version(twisted_ver) >= normalized_version('9.0.0'):
-            raise unittest.SkipTest("We pass this test only with Twisted >= v9.0.0")
-
         basedir = self.workdir("test_client_no_noise")
         c1 = os.path.join(basedir, "c1")
         HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
@@ -495,7 +491,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
             # By writing this file, we get two minutes before the client will exit. This ensures
             # that even if the 'stop' command doesn't work (and the test fails), the client should
             # still terminate.
-            open(HOTLINE_FILE, "w").write("")
+            fileutil.write(HOTLINE_FILE, "")
             # now it's safe to start the node
         d.addCallback(_cb)
 
@@ -506,7 +502,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
         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("")
+            fileutil.write(HOTLINE_FILE, "")
             self.failUnlessEqual(rc_or_sig, 0, errstr)
             self.failUnlessEqual(out, "", errstr) # If you emit noise, you fail this test.
             errlines = err.split("\n")
@@ -536,6 +532,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
             self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
             return self.run_bintahoe(["--quiet", "stop", c1])
         d.addCallback(_stop)
+        d.addBoth(self._remove, HOTLINE_FILE)
         return d
 
     def test_client(self):
@@ -560,7 +557,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
             # By writing this file, we get two minutes before the client will exit. This ensures
             # that even if the 'stop' command doesn't work (and the test fails), the client should
             # still terminate.
-            open(HOTLINE_FILE, "w").write("")
+            fileutil.write(HOTLINE_FILE, "")
             # now it's safe to start the node
         d.addCallback(_cb)
 
@@ -570,7 +567,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
 
         def _cb2(res):
             out, err, rc_or_sig = res
-            open(HOTLINE_FILE, "w").write("")
+            fileutil.write(HOTLINE_FILE, "")
             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
             self.failUnlessEqual(rc_or_sig, 0, errstr)
             self.failUnlessEqual(out, "", errstr)
@@ -587,7 +584,8 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
         d.addCallback(_cb2)
 
         def _node_has_started():
-            return os.path.exists(NODE_URL_FILE)
+            # this depends upon both files being created atomically
+            return os.path.exists(NODE_URL_FILE) and os.path.exists(PORTNUM_FILE)
         d.addCallback(lambda res: self.poll(_node_has_started))
 
         def _started(res):
@@ -595,7 +593,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
             # don't change on restart
             self.portnum = fileutil.read(PORTNUM_FILE)
 
-            open(HOTLINE_FILE, "w").write("")
+            fileutil.write(HOTLINE_FILE, "")
             self.failUnless(os.path.exists(TWISTD_PID_FILE))
 
             # rm this so we can detect when the second incarnation is ready
@@ -606,7 +604,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
         def _cb3(res):
             out, err, rc_or_sig = res
 
-            open(HOTLINE_FILE, "w").write("")
+            fileutil.write(HOTLINE_FILE, "")
             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
             self.failUnlessEqual(rc_or_sig, 0, errstr)
             self.failUnlessEqual(out, "", errstr)
@@ -625,15 +623,17 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
         # itself before we get a chance to, especially if spawning the
         # 'tahoe stop' command takes a while.
         def _stop(res):
-            open(HOTLINE_FILE, "w").write("")
-            self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
+            fileutil.write(HOTLINE_FILE, "")
+            self.failUnless(os.path.exists(TWISTD_PID_FILE),
+                            (TWISTD_PID_FILE,
+                             os.listdir(os.path.dirname(TWISTD_PID_FILE))))
             return self.run_bintahoe(["--quiet", "stop", c1])
         d.addCallback(_stop)
 
         def _cb4(res):
             out, err, rc_or_sig = res
 
-            open(HOTLINE_FILE, "w").write("")
+            fileutil.write(HOTLINE_FILE, "")
             # the parent has exited by now
             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
             self.failUnlessEqual(rc_or_sig, 0, errstr)
@@ -644,12 +644,13 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
             # gone by now.
             self.failIf(os.path.exists(TWISTD_PID_FILE))
         d.addCallback(_cb4)
-        def _remove_hotline(res):
-            os.unlink(HOTLINE_FILE)
-            return res
-        d.addBoth(_remove_hotline)
+        d.addBoth(self._remove, HOTLINE_FILE)
         return d
 
+    def _remove(self, res, file):
+        fileutil.remove(file)
+        return res
+
     def test_baddir(self):
         self.skip_if_cannot_daemonize()
         basedir = self.workdir("test_baddir")