You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/12/20 19:50:46 UTC

[20/36] git commit: [#6821] Remove any possibility of indefinite blocking and make test more clear

[#6821] Remove any possibility of indefinite blocking and make test more clear

Signed-off-by: Cory Johns <cj...@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/e8d402ba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/e8d402ba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/e8d402ba

Branch: refs/heads/db/6388
Commit: e8d402ba8283e40614ae495078156c0f1c0c3181
Parents: 4070bed
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Mon Dec 16 19:20:34 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Dec 18 22:10: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/e8d402ba/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/e8d402ba/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, {})