[Checkins] SVN: gocept.zeoraid/trunk/src/gocept/zeoraid/ improved thread synchronisation to make tests more stable
Thomas Lotze
tl at gocept.com
Mon Sep 27 09:31:46 EDT 2010
Log message for revision 116984:
improved thread synchronisation to make tests more stable
Changed:
U gocept.zeoraid/trunk/src/gocept/zeoraid/storage.py
U gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_basics.py
U gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_recovery.py
-=-
Modified: gocept.zeoraid/trunk/src/gocept/zeoraid/storage.py
===================================================================
--- gocept.zeoraid/trunk/src/gocept/zeoraid/storage.py 2010-09-27 12:52:32 UTC (rev 116983)
+++ gocept.zeoraid/trunk/src/gocept/zeoraid/storage.py 2010-09-27 13:31:45 UTC (rev 116984)
@@ -182,10 +182,7 @@
def close(self):
"""Close the storage."""
- for thread in self._threads:
- # We give all the threads a chance to get done quickly.
- # This is mostly a convenience for the tests to not annoy.
- thread.join(5)
+ self._join(5)
if self.closed:
# Storage may be closed more than once, e.g. by tear-down methods
@@ -201,10 +198,7 @@
self.closed = True
del self.storages_optimal[:]
- for thread in self._threads:
- # We give all the threads a chance to get done quickly.
- # This is mostly a convenience for the tests to not annoy.
- thread.join(5)
+ self._join(5)
def getName(self):
"""The name of the storage."""
@@ -617,7 +611,7 @@
return 'disabled %r' % (name,)
@ensure_open_storage
- def raid_recover(self, name):
+ def raid_recover(self, name, sync=False):
self._write_lock.acquire()
try:
if self.storage_recovering is not None:
@@ -631,10 +625,13 @@
finally:
self._write_lock.release()
- t = threading.Thread(target=self._recover_impl, args=(name,))
- self._threads.add(t)
- t.setDaemon(True)
- t.start()
+ if sync:
+ self._recover_impl(name)
+ else:
+ t = threading.Thread(target=self._recover_impl, args=(name,))
+ self._threads.add(t)
+ t.setDaemon(True)
+ t.start()
return 'recovering %r' % (name,)
@@ -1000,7 +997,13 @@
else:
zeo_storage.log("Blocked transaction restarted.")
+ def _join(self, timeout=None):
+ # We give all the threads a chance to get done quickly.
+ # This is mostly a convenience for the tests to not annoy.
+ for x in self._threads:
+ x.join(timeout)
+
def optimistic_copy(source, target):
"""Try creating a hard link to source at target. Fall back to copying the
file.
Modified: gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_basics.py
===================================================================
--- gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_basics.py 2010-09-27 12:52:32 UTC (rev 116983)
+++ gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_basics.py 2010-09-27 13:31:45 UTC (rev 116984)
@@ -1173,7 +1173,8 @@
self._disable_storage(0)
self._dostore()
self._dostore()
- self._storage._recover_impl(self._storage.storages_degraded[0])
+ self._storage.raid_recover(
+ self._storage.storages_degraded[0], sync=True)
self.assertEquals('optimal', self._storage.raid_status())
gocept.zeoraid.tests.test_recovery.compare(
self, self._backend(0), self._backend(1))
@@ -1517,7 +1518,7 @@
self._dostore(oid=oid, data='0', already_pickled=True)
# recover the newly added backend
- self._storage._recover_impl('5')
+ self._storage.raid_recover('5', sync=True)
self.assertEquals([], self._storage.storages_degraded)
# ensure that we can still write to the RAID
Modified: gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_recovery.py
===================================================================
--- gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_recovery.py 2010-09-27 12:52:32 UTC (rev 116983)
+++ gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_recovery.py 2010-09-27 13:31:45 UTC (rev 116984)
@@ -352,6 +352,7 @@
self.target.close()
raid = self.setup_raid()
self.assertEquals('degraded', raid.raid_status())
+ raid._join()
raid.raid_recover('target')
for i in xrange(10):
time.sleep(1)
More information about the checkins
mailing list