[ARVADOS] created: 293618ac3452994f07accea3ffddd4867e4a6176
Git user
git at public.curoverse.com
Fri Sep 23 13:49:25 EDT 2016
at 293618ac3452994f07accea3ffddd4867e4a6176 (commit)
commit 293618ac3452994f07accea3ffddd4867e4a6176
Author: Tom Clegg <tom at curoverse.com>
Date: Fri Sep 23 13:49:17 2016 -0400
10124: Replace "sleep 1, then assert" with "retry assertion for up to 10 seconds".
diff --git a/services/fuse/tests/test_mount.py b/services/fuse/tests/test_mount.py
index 79e7948..97b4ba3 100644
--- a/services/fuse/tests/test_mount.py
+++ b/services/fuse/tests/test_mount.py
@@ -23,6 +23,33 @@ from mount_test_base import MountTestBase
logger = logging.getLogger('arvados.arv-mount')
+class AssertWithin(object):
+ """Allow some time for an assertion to pass."""
+
+ def __init__(self, seconds):
+ self.seconds = seconds
+
+ def __iter__(self):
+ self.deadline = time.time() + self.seconds
+ self.done = False
+ return self
+
+ def next(self):
+ if self.done:
+ raise StopIteration
+ return self.attempt
+
+ def attempt(self, fn, *args, **kwargs):
+ try:
+ fn(*args, **kwargs)
+ except AssertionError:
+ if time.time() > self.deadline:
+ raise
+ time.sleep(0.1)
+ else:
+ self.done = True
+
+
class FuseMountTest(MountTestBase):
def setUp(self):
super(FuseMountTest, self).setUp()
@@ -182,18 +209,18 @@ class FuseTagsUpdateTest(MountTestBase):
bar_uuid = run_test_server.fixture('collections')['bar_file']['uuid']
self.tag_collection(bar_uuid, 'fuse_test_tag')
- time.sleep(1)
- self.assertIn('fuse_test_tag', llfuse.listdir(self.mounttmp))
+ for attempt in AssertWithin(10):
+ attempt(self.assertIn, 'fuse_test_tag', llfuse.listdir(self.mounttmp))
self.assertDirContents('fuse_test_tag', [bar_uuid])
baz_uuid = run_test_server.fixture('collections')['baz_file']['uuid']
l = self.tag_collection(baz_uuid, 'fuse_test_tag')
- time.sleep(1)
- self.assertDirContents('fuse_test_tag', [bar_uuid, baz_uuid])
+ for attempt in AssertWithin(10):
+ attempt(self.assertDirContents, 'fuse_test_tag', [bar_uuid, baz_uuid])
self.api.links().delete(uuid=l['uuid']).execute()
- time.sleep(1)
- self.assertDirContents('fuse_test_tag', [bar_uuid])
+ for attempt in AssertWithin(10):
+ attempt(self.assertDirContents, 'fuse_test_tag', [bar_uuid])
class FuseSharedTest(MountTestBase):
@@ -713,15 +740,8 @@ class FuseUpdateFromEventTest(MountTestBase):
with collection2.open("file1.txt", "w") as f:
f.write("foo")
- # should show up in <10s via event bus notify
- expect = ["file1.txt"]
- for _ in range(100):
- d1 = sorted(llfuse.listdir(os.path.join(self.mounttmp)))
- if d1 == expect:
- break
- time.sleep(0.1)
-
- self.assertEqual(expect, d1)
+ for attempt in AssertWithin(10):
+ attempt(self.assertEqual, ["file1.txt"], llfuse.listdir(os.path.join(self.mounttmp)))
def fuseFileConflictTestHelper(mounttmp):
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list