[ARVADOS] updated: c2fdf5d225efe65edcab383b213eca27e2cca30e

Git user git at public.curoverse.com
Fri Sep 23 22:49:34 EDT 2016


Summary of changes:
 services/fuse/tests/test_mount.py | 50 +++++++++++++++++++++++++++------------
 1 file changed, 35 insertions(+), 15 deletions(-)

       via  c2fdf5d225efe65edcab383b213eca27e2cca30e (commit)
       via  9c8cfd22f67f9becfd9e33411b61118b27eb043e (commit)
      from  1ff9f942f8e2f7830b381e7b2c4275ae71b1ae93 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit c2fdf5d225efe65edcab383b213eca27e2cca30e
Merge: 1ff9f94 9c8cfd2
Author: Tom Clegg <tom at curoverse.com>
Date:   Fri Sep 23 22:31:54 2016 -0400

    Merge branch '10124-fix-sleepy-tests' closes #10124


commit 9c8cfd22f67f9becfd9e33411b61118b27eb043e
Author: Tom Clegg <tom at curoverse.com>
Date:   Fri Sep 23 14:50:23 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..8b6d019 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 AssertWithTimeout(object):
+    """Allow some time for an assertion to pass."""
+
+    def __init__(self, timeout=0):
+        self.timeout = timeout
+
+    def __iter__(self):
+        self.deadline = time.time() + self.timeout
+        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 AssertWithTimeout(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 AssertWithTimeout(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 AssertWithTimeout(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 AssertWithTimeout(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