Commit 415b1ff3 authored by Kirill Smelkov's avatar Kirill Smelkov Committed by GitHub

tests: Factor "Open another ClientStorage to the same server" into generic...

tests: Factor "Open another ClientStorage to the same server" into generic _new_storage_client() (#170)

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

For the reference: that problem should be fixed by
https://github.com/zopefoundation/ZEO/pull/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 (81f586c4) it came with

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

but nowdays after 03867188 getting to server address is just by ClientStorage._addr.

/reviewed-on https://github.com/zopefoundation/ZEO/pull/170
/reviewed-by @d-maurer
parent 707316c4
...@@ -26,12 +26,6 @@ from ZEO.tests.TestThread import TestThread ...@@ -26,12 +26,6 @@ from ZEO.tests.TestThread import TestThread
ZERO = b'\0'*8 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): class WorkerThread(TestThread):
# run the entire test in a thread so that the blocking call for # run the entire test in a thread so that the blocking call for
...@@ -103,7 +97,7 @@ class CommitLockTests(object): ...@@ -103,7 +97,7 @@ class CommitLockTests(object):
self._threads = [] self._threads = []
for i in range(self.NUM_CLIENTS): for i in range(self.NUM_CLIENTS):
storage = self._duplicate_client() storage = self._new_storage_client()
txn = TransactionMetaData() txn = TransactionMetaData()
tid = self._get_timestamp() tid = self._get_timestamp()
...@@ -122,18 +116,6 @@ class CommitLockTests(object): ...@@ -122,18 +116,6 @@ class CommitLockTests(object):
for t in self._threads: for t in self._threads:
t.cleanup() 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): def _get_timestamp(self):
t = time.time() t = time.time()
t = TimeStamp(*time.gmtime(t)[:5]+(t%60,)) t = TimeStamp(*time.gmtime(t)[:5]+(t%60,))
......
...@@ -190,9 +190,7 @@ class MiscZEOTests(object): ...@@ -190,9 +190,7 @@ class MiscZEOTests(object):
self._dostore(data=obj) self._dostore(data=obj)
def checkZEOInvalidation(self): def checkZEOInvalidation(self):
addr = self._storage._addr storage2 = self._new_storage_client()
storage2 = self._wrap_client(
ClientStorage(addr, wait=1, **self._client_options()))
try: try:
oid = self._storage.new_oid() oid = self._storage.new_oid()
ob = MinPO('first') ob = MinPO('first')
...@@ -220,14 +218,13 @@ class MiscZEOTests(object): ...@@ -220,14 +218,13 @@ class MiscZEOTests(object):
def checkVolatileCacheWithImmediateLastTransaction(self): def checkVolatileCacheWithImmediateLastTransaction(self):
# Earlier, a ClientStorage would not have the last transaction id # Earlier, a ClientStorage would not have the last transaction id
# available right after successful connection, this is required now. # available right after successful connection, this is required now.
addr = self._storage._addr storage2 = self._new_storage_client()
storage2 = ClientStorage(addr, **self._client_options())
self.assertTrue(storage2.is_connected()) self.assertTrue(storage2.is_connected())
self.assertEqual(ZODB.utils.z64, storage2.lastTransaction()) self.assertEqual(ZODB.utils.z64, storage2.lastTransaction())
storage2.close() storage2.close()
self._dostore() self._dostore()
storage3 = ClientStorage(addr, **self._client_options()) storage3 = self._new_storage_client()
self.assertTrue(storage3.is_connected()) self.assertTrue(storage3.is_connected())
self.assertEqual(8, len(storage3.lastTransaction())) self.assertEqual(8, len(storage3.lastTransaction()))
self.assertNotEqual(ZODB.utils.z64, storage3.lastTransaction()) self.assertNotEqual(ZODB.utils.z64, storage3.lastTransaction())
...@@ -262,6 +259,15 @@ class GenericTestBase( ...@@ -262,6 +259,15 @@ class GenericTestBase(
) )
self._storage.registerDB(DummyDB()) 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): def getZEOConfig(self):
return forker.ZEOConfig(('127.0.0.1', 0)) return forker.ZEOConfig(('127.0.0.1', 0))
...@@ -320,8 +326,7 @@ class GenericTests( ...@@ -320,8 +326,7 @@ class GenericTests(
def _do_store_in_separate_thread(self, oid, revid, voted): def _do_store_in_separate_thread(self, oid, revid, voted):
def do_store(): def do_store():
store = ZEO.ClientStorage.ClientStorage( store = self._new_storage_client()
self._storage._addr, **self._client_options())
try: try:
t = transaction.get() t = transaction.get()
store.tpc_begin(t) store.tpc_begin(t)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment