You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/02/16 12:44:34 UTC

[03/37] allura git commit: [#7795] ticket:717 Fix test failure due to mim access from two threads

[#7795] ticket:717 Fix test failure due to mim access from two threads


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

Branch: refs/heads/ib/4542
Commit: 78b0707396d45deea91de1eeff4dfe5fe82c4b84
Parents: c9577b9
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Feb 3 12:09:31 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Feb 3 12:09:31 2015 +0000

----------------------------------------------------------------------
 ForgeWiki/forgewiki/tests/test_models.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/78b07073/ForgeWiki/forgewiki/tests/test_models.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/test_models.py b/ForgeWiki/forgewiki/tests/test_models.py
index ac07669..5c10e50 100644
--- a/ForgeWiki/forgewiki/tests/test_models.py
+++ b/ForgeWiki/forgewiki/tests/test_models.py
@@ -30,18 +30,24 @@ class TestPageSnapshots(TestController):
         # details https://sourceforge.net/p/allura/tickets/7647/
         import time
         import random
-        from threading import Thread
+        from threading import Thread, Lock
 
         page = Page.upsert('test-page')
         page.commit()
 
+        lock = Lock()
         def run(n):
             setup_global_objects()
             for i in range(10):
                 page = Page.query.get(title='test-page')
                 page.text = 'Test Page %s.%s' % (n, i)
                 time.sleep(random.random())
-                page.commit()
+                # tests use mim (mongo-in-memory), which isn't thread-safe
+                lock.acquire()
+                try:
+                    page.commit()
+                finally:
+                    lock.release()
 
         t1 = Thread(target=lambda: run(1))
         t2 = Thread(target=lambda: run(2))