Commit 7e7f38b2 authored by Jeremy Hylton's avatar Jeremy Hylton

Drive asyncore during cache verification in synchronous mode.

If asyncore is not running in a separate thread, the client needs to
call poll() to perform the IO necessary for cache verification to
finish.

This allows us to eliminate several calls to sync() in the test suite.
parent d51bdac5
...@@ -293,18 +293,21 @@ class ClientStorage: ...@@ -293,18 +293,21 @@ class ClientStorage:
break break
log2(INFO, "Wait for cache verification to finish") log2(INFO, "Wait for cache verification to finish")
else: else:
# If there is no mainloop running, this code needs self._wait_sync()
# to call poll() to cause asyncore to handle events.
while 1: def _wait_sync(self):
if self._ready.isSet(): # If there is no mainloop running, this code needs
break # to call poll() to cause asyncore to handle events.
log2(INFO, "Wait for cache verification to finish") while 1:
if self._connection is None: if self._ready.isSet():
# If the connection was closed while we were break
# waiting for it to become ready, start over. log2(INFO, "Wait for cache verification to finish")
return self._wait() if self._connection is None:
else: # If the connection was closed while we were
self._connection.pending(30) # waiting for it to become ready, start over.
return self._wait()
else:
self._connection.pending(30)
def close(self): def close(self):
"""Storage API: finalize the storage, releasing external resources.""" """Storage API: finalize the storage, releasing external resources."""
...@@ -414,6 +417,9 @@ class ClientStorage: ...@@ -414,6 +417,9 @@ class ClientStorage:
self._oids = [] self._oids = []
self._info.update(stub.get_info()) self._info.update(stub.get_info())
self.verify_cache(stub) self.verify_cache(stub)
if not conn.is_async():
log2(INFO, "Waiting for cache verification to finish")
self._wait_sync()
def set_server_addr(self, addr): def set_server_addr(self, addr):
# Normalize server address and convert to string # Normalize server address and convert to string
......
...@@ -205,7 +205,6 @@ class ConnectionTests(CommonSetupTearDown): ...@@ -205,7 +205,6 @@ class ConnectionTests(CommonSetupTearDown):
self._dostore() self._dostore()
break break
except ClientDisconnected: except ClientDisconnected:
self._storage.sync()
time.sleep(0.5) time.sleep(0.5)
def checkReadOnlyClient(self): def checkReadOnlyClient(self):
...@@ -392,7 +391,6 @@ class ConnectionTests(CommonSetupTearDown): ...@@ -392,7 +391,6 @@ class ConnectionTests(CommonSetupTearDown):
"Error after server restart; retrying.", "Error after server restart; retrying.",
error=sys.exc_info()) error=sys.exc_info())
get_transaction().abort() get_transaction().abort()
self._storage.sync()
# XXX This is a bloody pain. We're placing a heavy burden # XXX This is a bloody pain. We're placing a heavy burden
# on users to catch a plethora of exceptions in order to # on users to catch a plethora of exceptions in order to
# write robust code. Need to think about implementing # write robust code. Need to think about implementing
...@@ -645,7 +643,6 @@ class ReconnectionTests(CommonSetupTearDown): ...@@ -645,7 +643,6 @@ class ReconnectionTests(CommonSetupTearDown):
# quickly and the test fails because it doesn't wait # quickly and the test fails because it doesn't wait
# long enough for the client. # long enough for the client.
time.sleep(0.1) time.sleep(0.1)
self._storage.sync()
else: else:
self.fail("Couldn't store after starting a read-write server") self.fail("Couldn't store after starting a read-write server")
......
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