work-around occasional errors deleting test db on windows
authorMark Hammond <mhammond@skippinet.com.au>
Sun, 19 Apr 2009 16:37:57 +1000
changeset 205 ac11c66cb0bcf4da074dd41a41c7099b7a8eb4eb
parent 204 492de4bc289646edf66464e4b09014e31adc4095
child 206 1d5df7b9f952fb27701ff674fc085d181e6080bc
push id24
push usermhammond@skippinet.com.au
push dateMon, 20 Apr 2009 01:22:13 +0000
work-around occasional errors deleting test db on windows
server/python/raindrop/tests/__init__.py
--- a/server/python/raindrop/tests/__init__.py
+++ b/server/python/raindrop/tests/__init__.py
@@ -34,44 +34,54 @@ class TestCaseWithDB(TestCase):
         self.prepare_test_accounts(config)
 
     def prepare_test_db(self):
         # change the name of the DB used.
         config = get_config()
         dbinfo = config.couches['local']
         # then blindly nuke it.
         db = get_db('local', None)
-        def _nuke_failed(failure, *args, **kwargs):
+        def _nuke_failed(failure, retries_left):
+            # worm around a bug on windows in couch 0.9:
+            # https://issues.apache.org/jira/browse/COUCHDB-326
+            # We just need to wait a little and try again...
+            if failure.value.status == '500' and retries_left:
+                import time;time.sleep(0.1)
+                return db.deleteDB(dbinfo['name']
+                    ).addCallbacks(_nuked_ok, _nuke_failed,
+                                   errbackArgs=retries_left-1
+                    )
+
             if failure.value.status != '404':
                 failure.raiseException()
 
         def _nuked_ok(d):
             pass
 
         # This needs more thought - not every test will want the user's
         # accounts (indeed, I expect they will *not* want user's account...)
         return db.deleteDB(dbinfo['name']
-                ).addCallbacks(_nuked_ok, _nuke_failed
+                ).addCallbacks(_nuked_ok, _nuke_failed, errbackArgs=(5,)
                 ).addCallback(fab_db
                 ).addCallback(bootstrap.install_accounts
                 ).addCallback(bootstrap.install_client_files, FakeOptions()
                 ).addCallback(bootstrap.install_views, FakeOptions()
                 ).addCallback(bootstrap.update_apps)
 
     def setUp(self):
         self.prepare_config()
         return self.prepare_test_db()
 
-    def get_last_by_seq(self):
+    def get_last_by_seq(self, n=1):
         def extract_row(result):
             rows = result['rows']
-            assert len(rows)==1
-            return rows[0]
+            assert len(rows)==n
+            return rows
 
-        return get_doc_model().db.listDocsBySeq(limit=1,
+        return get_doc_model().db.listDocsBySeq(limit=n,
                                                 descending=True,
                                                 include_docs=True
                 ).addCallback(extract_row
                 )
 
 
 class TestCaseWithTestDB(TestCaseWithDB):
     """A test case that is setup to work with a temp database pre-populated