Skip to content

Commit

Permalink
tests: Factor "Open another ClientStorage to the same server" into ge…
Browse files Browse the repository at this point in the history
…neric _new_storage_client()

This allows ZODB tests to recognize ZEO as client-server storage and so
make "load vs external invalidate" test added in
zopefoundation/ZODB#345 to reproduce data
corruption problem reported at
zopefoundation#155.

For the reference: that problem should be fixed by
zopefoundation#169.

We drop

    # It's hard to find the actual address.
    # The rpc mgr addr attribute is a list.  Each element in the
    # list is a socket domain (AF_INET, AF_UNIX, etc.) and an
    # address.

note because at the time it was added (81f586c) it came with

    addr = self._storage._rpc_mgr.addr[0][1]

but nowdays after 0386718 getting to server address is just by ClientStorage._addr.
  • Loading branch information
navytux committed Apr 16, 2021
1 parent 3d90ed4 commit 5c53624
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
20 changes: 1 addition & 19 deletions src/ZEO/tests/CommitLockTests.py
Expand Up @@ -26,12 +26,6 @@

ZERO = b'\0'*8

class DummyDB(object):
def invalidate(self, *args, **kwargs):
pass

transform_record_data = untransform_record_data = lambda self, data: data

class WorkerThread(TestThread):

# run the entire test in a thread so that the blocking call for
Expand Down Expand Up @@ -103,7 +97,7 @@ def _begin_threads(self):
self._threads = []

for i in range(self.NUM_CLIENTS):
storage = self._duplicate_client()
storage = self._new_storage_client()
txn = TransactionMetaData()
tid = self._get_timestamp()

Expand All @@ -122,18 +116,6 @@ def _finish_threads(self):
for t in self._threads:
t.cleanup()

def _duplicate_client(self):
"Open another ClientStorage to the same server."
# It's hard to find the actual address.
# The rpc mgr addr attribute is a list. Each element in the
# list is a socket domain (AF_INET, AF_UNIX, etc.) and an
# address.
addr = self._storage._addr
new = ZEO.ClientStorage.ClientStorage(
addr, wait=1, **self._client_options())
new.registerDB(DummyDB())
return new

def _get_timestamp(self):
t = time.time()
t = TimeStamp(*time.gmtime(t)[:5]+(t%60,))
Expand Down
21 changes: 13 additions & 8 deletions src/ZEO/tests/testZEO.py
Expand Up @@ -190,9 +190,7 @@ def checkLargeUpdate(self):
self._dostore(data=obj)

def checkZEOInvalidation(self):
addr = self._storage._addr
storage2 = self._wrap_client(
ClientStorage(addr, wait=1, **self._client_options()))
storage2 = self._new_storage_client()
try:
oid = self._storage.new_oid()
ob = MinPO('first')
Expand Down Expand Up @@ -220,14 +218,13 @@ def checkZEOInvalidation(self):
def checkVolatileCacheWithImmediateLastTransaction(self):
# Earlier, a ClientStorage would not have the last transaction id
# available right after successful connection, this is required now.
addr = self._storage._addr
storage2 = ClientStorage(addr, **self._client_options())
storage2 = self._new_storage_client()
self.assertTrue(storage2.is_connected())
self.assertEqual(ZODB.utils.z64, storage2.lastTransaction())
storage2.close()

self._dostore()
storage3 = ClientStorage(addr, **self._client_options())
storage3 = self._new_storage_client()
self.assertTrue(storage3.is_connected())
self.assertEqual(8, len(storage3.lastTransaction()))
self.assertNotEqual(ZODB.utils.z64, storage3.lastTransaction())
Expand Down Expand Up @@ -262,6 +259,15 @@ def setUp(self):
)
self._storage.registerDB(DummyDB())

# _new_storage_client opens another ClientStorage to the same storage server
# self._storage is connected to. It is used by both ZEO and ZODB tests.
def _new_storage_client(self):
client = ZEO.ClientStorage.ClientStorage(
self._storage._addr, wait=1, **self._client_options())
client = self._wrap_client(client)
client.registerDB(DummyDB())
return client

def getZEOConfig(self):
return forker.ZEOConfig(('127.0.0.1', 0))

Expand Down Expand Up @@ -320,8 +326,7 @@ def checkSortKey(self):
def _do_store_in_separate_thread(self, oid, revid, voted):

def do_store():
store = ZEO.ClientStorage.ClientStorage(
self._storage._addr, **self._client_options())
store = self._new_storage_client()
try:
t = transaction.get()
store.tpc_begin(t)
Expand Down

0 comments on commit 5c53624

Please sign in to comment.