[Zodb-checkins] CVS: Zope3/src/zodb/storage/tests - base.py:1.10 packable.py:1.6 recovery.py:1.6 test_autopack.py:1.11 undo.py:1.8

Barry Warsaw barry@wooz.org
Fri, 14 Mar 2003 12:55:28 -0500


Update of /cvs-repository/Zope3/src/zodb/storage/tests
In directory cvs.zope.org:/tmp/cvs-serv3945/src/zodb/storage/tests

Modified Files:
	base.py packable.py recovery.py test_autopack.py undo.py 
Log Message:
Factor out the workaround for Windows time.time() potentially
returning the same value on subsequent calls.  zodb.storage.tests.base
now has a snooze() function, which is used wherever we must ensure
that subsequent timestamps always increase.


=== Zope3/src/zodb/storage/tests/base.py 1.9 => 1.10 ===
--- Zope3/src/zodb/storage/tests/base.py:1.9	Thu Mar 13 16:32:29 2003
+++ Zope3/src/zodb/storage/tests/base.py	Fri Mar 14 12:55:26 2003
@@ -22,6 +22,7 @@
 
 import os
 import sys
+import time
 import errno
 import shutil
 import unittest
@@ -37,6 +38,15 @@
 
 DBHOME = 'test-db'
 
+
+def snooze():
+    # In Windows, it's possible that two successive time.time() calls return
+    # the same value.  Tim guarantees that time never runs backwards.  You
+    # usually want to call this before you pack a storage, or must make other
+    # guarantees about increasing timestamps.
+    now = time.time()
+    while now == time.time():
+        sleep(0.1)
 
 def zodb_pickle(obj):
     """Create a pickle in the format expected by ZODB."""


=== Zope3/src/zodb/storage/tests/packable.py 1.5 => 1.6 ===
--- Zope3/src/zodb/storage/tests/packable.py:1.5	Thu Mar 13 16:32:29 2003
+++ Zope3/src/zodb/storage/tests/packable.py	Fri Mar 14 12:55:26 2003
@@ -22,7 +22,7 @@
 from zodb.serialize import getDBRoot, ConnectionObjectReader
 from zodb.ztransaction import Transaction
 from zodb.storage.tests.minpo import MinPO
-from zodb.storage.tests.base import zodb_unpickle
+from zodb.storage.tests.base import zodb_unpickle, snooze
 from zodb.storage.fsdump import dump
 
 
@@ -63,11 +63,8 @@
         data = self._storage.loadSerial(oid, revid3)
         pobj = zodb_unpickle(data)
         eq(pobj.value, 3)
-        # Now pack all transactions; need to sleep a second to make
-        # sure that the pack time is greater than the last commit time.
-        now = int(time.time())
-        while now >= int(time.time()):
-            time.sleep(0.1)
+        # Now pack all transactions
+        snooze()
         self._storage.pack(time.time())
         # All revisions of the object should be gone, since there is no
         # reference from the root object to this object.
@@ -105,9 +102,7 @@
         eq(pobj.value, 3)
         # Now pack just revisions 1 and 2.  The object's current revision
         # should stay alive because it's pointed to by the root.
-        now = int(time.time())
-        while now >= int(time.time()):
-            time.sleep(0.1)
+        snooze()
         self._storage.pack(time.time())
         # Make sure the revisions are gone, but that the root object and
         # revision 3 are still there and correct
@@ -180,10 +175,7 @@
         # Now pack just revisions 1 and 2 of object1.  Object1's current
         # revision should stay alive because it's pointed to by the root, as
         # should Object2's current revision.
-        now = time.time()
-        now = int(time.time())
-        while now >= int(time.time()):
-            time.sleep(0.1)
+        snooze()
         self._storage.pack(time.time())
         # Make sure the revisions are gone, but that object zero, object2, and
         # revision 3 of object1 are still there and correct.


=== Zope3/src/zodb/storage/tests/recovery.py 1.5 => 1.6 ===
--- Zope3/src/zodb/storage/tests/recovery.py:1.5	Thu Mar 13 16:32:29 2003
+++ Zope3/src/zodb/storage/tests/recovery.py	Fri Mar 14 12:55:26 2003
@@ -22,7 +22,7 @@
 from zodb.db import DB
 from zodb.ztransaction import Transaction
 from zodb.storage.tests.iterator import IteratorDeepCompare
-from zodb.storage.tests.base import MinPO, zodb_unpickle
+from zodb.storage.tests.base import MinPO, zodb_unpickle, snooze
 from zodb.serialize import findrefs
 
 
@@ -191,7 +191,8 @@
         txn.commit()
         # Now copy the transactions to the destination
         self._dst.copyTransactionsFrom(self._storage)
-        # Now pack the destination
+        # Now pack the destination.
+        snooze()
         self._dst.pack(time.time())
         # And check to see that the root object exists, but not the other
         # objects.


=== Zope3/src/zodb/storage/tests/test_autopack.py 1.10 => 1.11 ===
--- Zope3/src/zodb/storage/tests/test_autopack.py:1.10	Thu Mar 13 16:32:29 2003
+++ Zope3/src/zodb/storage/tests/test_autopack.py	Fri Mar 14 12:55:26 2003
@@ -24,7 +24,7 @@
 from zodb.timestamp import TimeStamp
 from zodb.ztransaction import Transaction
 from zodb.storage.base import ZERO, berkeley_is_available
-from zodb.storage.tests.base import zodb_pickle, zodb_unpickle
+from zodb.storage.tests.base import zodb_pickle, zodb_unpickle, snooze
 from zodb.storage.tests.minpo import MinPO
 
 if berkeley_is_available:
@@ -292,9 +292,7 @@
         # Now, acquire the condvar lock and start a thread that will do a
         # pack, up to the _sweep call.  Wait for the _mark() call to
         # complete.
-        now = time.time()
-        while now == time.time():
-            time.sleep(0.1)
+        snooze()
         self._cv.acquire()
         packthread = self._getPackThread(storage)
         packthread.start()
@@ -344,9 +342,7 @@
         # Now, acquire the condvar lock and start a thread that will do a
         # pack, up to the _sweep call.  Wait for the _mark() call to
         # complete.
-        now = time.time()
-        while now == time.time():
-            time.sleep(0.1)
+        snooze()
         self._cv.acquire()
         packthread = self._getPackThread(storage)
         packthread.start()


=== Zope3/src/zodb/storage/tests/undo.py 1.7 => 1.8 ===
--- Zope3/src/zodb/storage/tests/undo.py:1.7	Thu Mar 13 16:32:29 2003
+++ Zope3/src/zodb/storage/tests/undo.py	Fri Mar 14 12:55:26 2003
@@ -12,7 +12,7 @@
 from zodb.db import DB
 
 from zodb.storage.tests.minpo import MinPO
-from zodb.storage.tests.base import zodb_pickle, zodb_unpickle
+from zodb.storage.tests.base import zodb_pickle, zodb_unpickle, snooze
 
 from persistence import Persistent
 from transaction import get_transaction
@@ -451,18 +451,11 @@
         obj, root, revid0 = self._linked_newobj()
         oid = obj._p_oid
         revid1 = self._dostore(oid, data=MinPO(51), revid=obj._p_serial)
-        # For the pack(), we need a timestamp greater than revid1's timestamp.
-        # The semantics of pack()'s `t' argument is that all non-current
-        # revisions with an earlier timestamp will be packed away.  If they
-        # were equal (because the Windows clock resolution is too coarse),
-        # then we won't pack away the first revision.
-        now = packtime = time.time()
-        while packtime <= now:
-            packtime = time.time()
-            time.sleep(0.1)
+        # Get a packtime greater than revid1's timestamp
+        snooze()
+        packtime = time.time()
         # Now be sure that revid2 has a timestamp after packtime
-        while packtime >= time.time():
-            time.sleep(0.1)
+        snooze()
         revid2 = self._dostore(oid, revid=revid1, data=MinPO(52))
         revid3 = self._dostore(oid, revid=revid2, data=MinPO(53))
         # Now get the undo log