From c7a557ba69631770d2036676213713a02c1ddb68 Mon Sep 17 00:00:00 2001 From: nejucomo Date: Sun, 20 Jan 2008 17:09:44 -0700 Subject: [PATCH] tahoe_fuse: system test: Copy the introducer.furl with a possible race condition due to timeout. --- contrib/fuse/runtests.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/contrib/fuse/runtests.py b/contrib/fuse/runtests.py index adb2f911..5c55d9bd 100644 --- a/contrib/fuse/runtests.py +++ b/contrib/fuse/runtests.py @@ -6,7 +6,7 @@ Note: The API design of the python-fuse library makes unit testing much of tahoe-fuse.py tricky business. ''' -import sys, os, shutil, unittest, subprocess, tempfile, re +import sys, os, shutil, unittest, subprocess, tempfile, re, time import tahoe_fuse @@ -132,7 +132,7 @@ class SystemTest (object): pat += r' please copy introducer.furl into the directory\s*$' self.check_tahoe_output(output, pat, self.clientbase) - self.launch_client_layer() + self.configure_client_layer() finally: print 'Removing client directory.' @@ -142,6 +142,32 @@ class SystemTest (object): print 'Exception removing test client directory: %r' % (self.clientbase,) print 'Ignoring cleanup exception: %r' % (e,) + def configure_client_layer(self): + print 'Configuring client.' + + introfurl = os.path.join(self.introbase, 'introducer.furl') + + # FIXME: Is there a better way to handle this race condition? + timeout = 10.0 # Timeout seconds. + pollinterval = 0.2 + totalattempts = int(timeout / pollinterval) + + for attempts in range(totalattempts): + if os.path.isfile(introfurl): + tmpl = '(It took around %.2f seconds before introducer.furl was created.)' + print tmpl % ((attempts + 1) * pollinterval,) + shutil.copy(introfurl, self.clientbase) + + self.launch_client_layer() + return # skip the timeout failure. + + else: + time.sleep(pollinterval) + + tmpl = 'Timeout after waiting for creation of introducer.furl.\n' + tmpl += 'Waited %.2f seconds (%d polls).' + raise self.SetupFailure(tmpl, timeout, totalattempts) + def launch_client_layer(self): print 'Launching client.' # NOTE: We assume if tahoe exist with non-zero status, no separate -- 2.45.2