incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [2/2] git commit: [#6821] Remove any possibility of indefinite blocking and make test more clear
Date Mon, 16 Dec 2013 19:21:53 GMT
[#6821] Remove any possibility of indefinite blocking and make test more clear

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/77d18b12
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/77d18b12
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/77d18b12

Branch: refs/heads/cj/6821
Commit: 77d18b1293304d6a3c7474e9a8a1befba2b08514
Parents: 3379635
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Mon Dec 16 19:20:34 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Mon Dec 16 19:20:34 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/repository.py                | 11 ++++++++++-
 ForgeGit/forgegit/tests/model/test_repository.py |  7 ++++---
 2 files changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/77d18b12/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 169b365..2aeef64 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -288,7 +288,16 @@ class RepositoryImplementation(object):
             for i in range(num_threads):
                 t = Thread(target=get_ids)
                 t.start()
-            chunks.join()
+            # reimplement chunks.join() but with a timeout
+            # see: http://bugs.python.org/issue9634
+            # (giving threads a bit of extra cleanup time in case they timeout)
+            chunks.all_tasks_done.acquire()
+            try:
+                endtime = time() + timeout + 0.5
+                while chunks.unfinished_tasks and endtime > time():
+                    chunks.all_tasks_done.wait(endtime - time())
+            finally:
+                chunks.all_tasks_done.release()
         return result
 
 class Repository(Artifact, ActivityObject):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/77d18b12/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 8569025..4f4f56f 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -456,13 +456,14 @@ class TestGitImplementation(unittest.TestCase):
         with h.push_config(tg.config, lcd_thread_chunk_size=1):
             self.test_last_commit_ids()
 
-    def test_last_commit_ids_threaded_error(self):
-        with h.push_config(tg.config, lcd_thread_chunk_size=1):
+    @mock.patch('forgegit.model.git_repo.GitImplementation._git', new_callable=mock.PropertyMock)
+    def test_last_commit_ids_threaded_error(self, _git):
+        with h.push_config(tg.config, lcd_thread_chunk_size=1, lcd_timeout=2):
             repo_dir = pkg_resources.resource_filename(
                 'forgegit', 'tests/data/testrename.git')
             repo = mock.Mock(full_fs_path=repo_dir)
+            _git.side_effect = ValueError
             impl = GM.git_repo.GitImplementation(repo)
-            impl._git = None
             lcds = impl.last_commit_ids(mock.Mock(_id='13951944969cf45a701bf90f83647b309815e6d5'),
['f2.txt', 'f3.txt'])
             self.assertEqual(lcds, {})
 


Mime
View raw message