[ARVADOS] created: 63228003517d7b30fb4d14f24cc7c243dd33ed24

Git user git at public.curoverse.com
Wed Sep 14 10:20:11 EDT 2016


        at  63228003517d7b30fb4d14f24cc7c243dd33ed24 (commit)


commit 63228003517d7b30fb4d14f24cc7c243dd33ed24
Author: Tom Clegg <tom at curoverse.com>
Date:   Wed Sep 14 10:19:21 2016 -0400

    10008: Use mocks to ensure collection is re-fetched.

diff --git a/services/fuse/arvados_fuse/command.py b/services/fuse/arvados_fuse/command.py
index c4b0df3..d15f017 100644
--- a/services/fuse/arvados_fuse/command.py
+++ b/services/fuse/arvados_fuse/command.py
@@ -117,6 +117,7 @@ class Mount(object):
         self.llfuse_thread.daemon = True
         self.llfuse_thread.start()
         self.operations.initlock.wait()
+        return self
 
     def __exit__(self, exc_type, exc_value, traceback):
         subprocess.call(["fusermount", "-u", "-z", self.args.mountpoint])
diff --git a/services/fuse/tests/integration_test.py b/services/fuse/tests/integration_test.py
index 5a45bfc..145789f 100644
--- a/services/fuse/tests/integration_test.py
+++ b/services/fuse/tests/integration_test.py
@@ -48,7 +48,6 @@ class IntegrationTest(unittest.TestCase):
     def setUp(self):
         self.mnt = tempfile.mkdtemp()
         run_test_server.authorize_with('active')
-        self.api = arvados.safeapi.ThreadSafeApiCache(arvados.config.settings())
 
     def tearDown(self):
         os.rmdir(self.mnt)
@@ -64,7 +63,8 @@ class IntegrationTest(unittest.TestCase):
                         arvados_fuse.command.ArgumentParser().parse_args(
                             argv + ['--foreground',
                                     '--unmount-timeout=0.1',
-                                    self.mnt])):
+                                    self.mnt])) as m:
+                    self.mount = m
                     return func(self, *args, **kwargs)
             return wrapper
         return decorator
diff --git a/services/fuse/tests/test_token_expiry.py b/services/fuse/tests/test_token_expiry.py
index 790c819..1b1be18 100644
--- a/services/fuse/tests/test_token_expiry.py
+++ b/services/fuse/tests/test_token_expiry.py
@@ -1,9 +1,12 @@
-import arvados
 import apiclient
+import arvados
+import arvados_fuse
 import logging
 import mock
+import multiprocessing
 import os
 import re
+import sys
 import time
 import unittest
 
@@ -12,33 +15,46 @@ from .integration_test import IntegrationTest
 logger = logging.getLogger('arvados.arv-mount')
 
 class TokenExpiryTest(IntegrationTest):
+    def __init__(self, *args, **kwargs):
+        super(TokenExpiryTest, self).__init__(*args, **kwargs)
+        self.test_start_time = time.time()
+        self.time_now = int(time.time())+1
+
+    def fake_time(self):
+        self.time_now += 1
+        return self.time_now
+
+    orig_open = arvados_fuse.Operations.open
+    def fake_open(self, operations, *args, **kwargs):
+        self.time_now += 86400*13
+        logger.debug('opening file at time=%f', self.time_now)
+        return self.orig_open(operations, *args, **kwargs)
+
+    @mock.patch.object(arvados_fuse.Operations, 'open', autospec=True)
+    @mock.patch('time.time')
     @mock.patch('arvados.keep.KeepClient.get')
     @IntegrationTest.mount(argv=['--mount-by-id', 'zzz'])
-    def test_refresh_old_manifest(self, mocked_get):
+    def test_refresh_old_manifest(self, mocked_get, mocked_time, mocked_open):
         mocked_get.return_value = 'fake data'
+        mocked_time.side_effect = self.fake_time
+        mocked_open.side_effect = self.fake_open
+
+        with mock.patch.object(self.mount.api, 'collections', wraps=self.mount.api.collections) as mocked_collections:
+            mocked_collections.return_value = mocked_collections()
+            with mock.patch.object(self.mount.api.collections(), 'get', wraps=self.mount.api.collections().get) as mocked_get:
+                self.pool_test(os.path.join(self.mnt, 'zzz'))
 
-        self.api._rootDesc["blobSignatureTtl"] = 2
-        old_exp = int(time.time()) + 86400*14
-        self.pool_test(os.path.join(self.mnt, 'zzz'))
-        want_exp = int(time.time()) + 86400*14
-
-        got_loc = mocked_get.call_args[0][0]
-        got_exp = int(
-            re.search(r'\+A[0-9a-f]+@([0-9a-f]+)', got_loc).group(1),
-            16)
-        self.assertGreaterEqual(
-            got_exp, want_exp-2,
-            msg='now+2w = {:x}, but fuse fetched locator {} (old_exp {:x})'.format(
-                want_exp, got_loc, old_exp))
-        self.assertLessEqual(
-            got_exp, want_exp,
-            msg='server is not using the expected 2w TTL; test is ineffective')
+        self.assertEqual(3, mocked_open.call_count)
+        self.assertEqual(
+            4, mocked_get.call_count,
+            'Not enough calls to collections().get(): expected 4, got {!r}'.format(
+                mocked_get.mock_calls))
 
     @staticmethod
     def _test_refresh_old_manifest(self, zzz):
         uuid = 'zzzzz-4zz18-op4e2lbej01tcvu'
         fnm = 'zzzzz-8i9sb-0vsrcqi7whchuil.log.txt'
         os.listdir(os.path.join(zzz, uuid))
-        time.sleep(3)
-        with open(os.path.join(zzz, uuid, fnm)) as f:
-            f.read()
+        for _ in range(3):
+            with open(os.path.join(zzz, uuid, fnm)) as f:
+                f.read()

commit f5d65486546b508fe2b055b37a512f14c4a5498e
Author: Tom Clegg <tom at curoverse.com>
Date:   Thu Sep 8 02:10:34 2016 -0400

    10008: Move token exp test back to IntegrationTest

diff --git a/services/fuse/tests/test_mount.py b/services/fuse/tests/test_mount.py
index 39f1109..2aba2e7 100644
--- a/services/fuse/tests/test_mount.py
+++ b/services/fuse/tests/test_mount.py
@@ -1128,36 +1128,3 @@ class FuseMagicTestPDHOnly(MountTestBase):
 
     def test_with_default_by_id(self):
         self.verify_pdh_only(skip_pdh_only=True)
-
-def _test_refresh_old_manifest(zzz):
-    fnm = 'zzzzz-8i9sb-0vsrcqi7whchuil.log.txt'
-    os.listdir(os.path.join(zzz))
-    time.sleep(3)
-    with open(os.path.join(zzz, fnm)) as f:
-        f.read()
-
-class TokenExpiryTest(MountTestBase):
-    def setUp(self):
-        super(TokenExpiryTest, self).setUp(local_store=False)
-
-    @mock.patch('arvados.keep.KeepClient.get')
-    def runTest(self, mocked_get):
-        self.api._rootDesc = {"blobSignatureTtl": 2}
-        mnt = self.make_mount(fuse.CollectionDirectory, collection_record='zzzzz-4zz18-op4e2lbej01tcvu')
-        mocked_get.return_value = 'fake data'
-
-        old_exp = int(time.time()) + 86400*14
-        self.pool.apply(_test_refresh_old_manifest, (self.mounttmp,))
-        want_exp = int(time.time()) + 86400*14
-
-        got_loc = mocked_get.call_args[0][0]
-        got_exp = int(
-            re.search(r'\+A[0-9a-f]+@([0-9a-f]+)', got_loc).group(1),
-            16)
-        self.assertGreaterEqual(
-            got_exp, want_exp-2,
-            msg='now+2w = {:x}, but fuse fetched locator {} (old_exp {:x})'.format(
-                want_exp, got_loc, old_exp))
-        self.assertLessEqual(
-            got_exp, want_exp,
-            msg='server is not using the expected 2w TTL; test is ineffective')
diff --git a/services/fuse/tests/test_token_expiry.py b/services/fuse/tests/test_token_expiry.py
new file mode 100644
index 0000000..790c819
--- /dev/null
+++ b/services/fuse/tests/test_token_expiry.py
@@ -0,0 +1,44 @@
+import arvados
+import apiclient
+import logging
+import mock
+import os
+import re
+import time
+import unittest
+
+from .integration_test import IntegrationTest
+
+logger = logging.getLogger('arvados.arv-mount')
+
+class TokenExpiryTest(IntegrationTest):
+    @mock.patch('arvados.keep.KeepClient.get')
+    @IntegrationTest.mount(argv=['--mount-by-id', 'zzz'])
+    def test_refresh_old_manifest(self, mocked_get):
+        mocked_get.return_value = 'fake data'
+
+        self.api._rootDesc["blobSignatureTtl"] = 2
+        old_exp = int(time.time()) + 86400*14
+        self.pool_test(os.path.join(self.mnt, 'zzz'))
+        want_exp = int(time.time()) + 86400*14
+
+        got_loc = mocked_get.call_args[0][0]
+        got_exp = int(
+            re.search(r'\+A[0-9a-f]+@([0-9a-f]+)', got_loc).group(1),
+            16)
+        self.assertGreaterEqual(
+            got_exp, want_exp-2,
+            msg='now+2w = {:x}, but fuse fetched locator {} (old_exp {:x})'.format(
+                want_exp, got_loc, old_exp))
+        self.assertLessEqual(
+            got_exp, want_exp,
+            msg='server is not using the expected 2w TTL; test is ineffective')
+
+    @staticmethod
+    def _test_refresh_old_manifest(self, zzz):
+        uuid = 'zzzzz-4zz18-op4e2lbej01tcvu'
+        fnm = 'zzzzz-8i9sb-0vsrcqi7whchuil.log.txt'
+        os.listdir(os.path.join(zzz, uuid))
+        time.sleep(3)
+        with open(os.path.join(zzz, uuid, fnm)) as f:
+            f.read()

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list