Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZEO
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
ZEO
Commits
01d74173
Commit
01d74173
authored
May 26, 2016
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed more tests
parent
1cc3ceb5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
63 deletions
+67
-63
src/ZEO/ClientStorage.py
src/ZEO/ClientStorage.py
+16
-2
src/ZEO/tests/ConnectionTests.py
src/ZEO/tests/ConnectionTests.py
+28
-13
src/ZEO/tests/testConversionSupport.py
src/ZEO/tests/testConversionSupport.py
+23
-48
No files found.
src/ZEO/ClientStorage.py
View file @
01d74173
...
@@ -98,6 +98,8 @@ class ClientStorage(object):
...
@@ -98,6 +98,8 @@ class ClientStorage(object):
wait
=
True
,
wait
=
True
,
drop_cache_rather_verify
=
True
,
drop_cache_rather_verify
=
True
,
username
=
None
,
password
=
None
,
realm
=
None
,
username
=
None
,
password
=
None
,
realm
=
None
,
# For tests:
_client_factory
=
ZEO
.
asyncio
.
client
.
ClientThread
,
):
):
"""ClientStorage constructor.
"""ClientStorage constructor.
...
@@ -256,18 +258,24 @@ class ClientStorage(object):
...
@@ -256,18 +258,24 @@ class ClientStorage(object):
blob_cache_size
*
blob_cache_size_check
//
100
)
blob_cache_size
*
blob_cache_size_check
//
100
)
self
.
_check_blob_size
()
self
.
_check_blob_size
()
self
.
_server
=
ZEO
.
asyncio
.
client
.
ClientThread
(
self
.
_server
=
_client_factory
(
addr
,
self
,
cache
,
storage
,
addr
,
self
,
cache
,
storage
,
ZEO
.
asyncio
.
client
.
Fallback
if
read_only_fallback
else
read_only
,
ZEO
.
asyncio
.
client
.
Fallback
if
read_only_fallback
else
read_only
,
wait_timeout
or
30
,
wait_timeout
or
30
,
)
)
self
.
_server
.
start
()
self
.
_call
=
self
.
_server
.
call
self
.
_call
=
self
.
_server
.
call
self
.
_async
=
self
.
_server
.
async
self
.
_async
=
self
.
_server
.
async
self
.
_async_iter
=
self
.
_server
.
async_iter
self
.
_async_iter
=
self
.
_server
.
async_iter
self
.
_commit_lock
=
threading
.
Lock
()
self
.
_commit_lock
=
threading
.
Lock
()
try
:
self
.
_server
.
start
(
wait
=
wait
)
except
Exception
:
# No point in keeping the server going of the storage creation fails
self
.
_server
.
close
()
raise
def
new_addr
(
self
,
addr
):
def
new_addr
(
self
,
addr
):
self
.
_addr
=
addr
self
.
_addr
=
addr
self
.
_server
.
new_addrs
(
addr
)
self
.
_server
.
new_addrs
(
addr
)
...
@@ -763,6 +771,12 @@ class ClientStorage(object):
...
@@ -763,6 +771,12 @@ class ClientStorage(object):
# all, yet you want to be sure that other abort logic is
# all, yet you want to be sure that other abort logic is
# executed regardless.
# executed regardless.
try
:
try
:
# It's tempting to make an asynchronous call here, but
# it's useful for it to be synchronous because, if we
# failed due to a disconnect, synchronous calls will
# wait a little while in hopes of reconnecting. If
# we're able to reconnect and retry the transaction,
# ten it might succeed!
self
.
_call
(
'tpc_abort'
,
id
(
txn
))
self
.
_call
(
'tpc_abort'
,
id
(
txn
))
except
ClientDisconnected
:
except
ClientDisconnected
:
logger
.
debug
(
"%s ClientDisconnected in tpc_abort() ignored"
,
logger
.
debug
(
"%s ClientDisconnected in tpc_abort() ignored"
,
...
...
src/ZEO/tests/ConnectionTests.py
View file @
01d74173
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
##############################################################################
import
concurrent.futures
import
os
import
os
import
time
import
time
import
socket
import
socket
...
@@ -174,6 +174,7 @@ class CommonSetupTearDown(StorageTestBase):
...
@@ -174,6 +174,7 @@ class CommonSetupTearDown(StorageTestBase):
var
=
'.'
,
var
=
'.'
,
cache_size
=
cache_size
,
cache_size
=
cache_size
,
wait
=
wait
,
wait
=
wait
,
wait_timeout
=
1
,
min_disconnect_poll
=
0.1
,
min_disconnect_poll
=
0.1
,
read_only
=
read_only
,
read_only
=
read_only
,
read_only_fallback
=
read_only_fallback
,
read_only_fallback
=
read_only_fallback
,
...
@@ -454,7 +455,7 @@ class ConnectionTests(CommonSetupTearDown):
...
@@ -454,7 +455,7 @@ class ConnectionTests(CommonSetupTearDown):
def
checkBadMessage1
(
self
):
def
checkBadMessage1
(
self
):
# not even close to a real message
# not even close to a real message
self
.
_bad_message
(
"salty"
)
self
.
_bad_message
(
b
"salty"
)
def
checkBadMessage2
(
self
):
def
checkBadMessage2
(
self
):
# just like a real message, but with an unpicklable argument
# just like a real message, but with an unpicklable argument
...
@@ -474,22 +475,36 @@ class ConnectionTests(CommonSetupTearDown):
...
@@ -474,22 +475,36 @@ class ConnectionTests(CommonSetupTearDown):
self
.
_storage
=
self
.
openClientStorage
()
self
.
_storage
=
self
.
openClientStorage
()
self
.
_dostore
()
self
.
_dostore
()
# break into the internals to send a bogus message
generation
=
self
.
_storage
.
_connection_generation
zrpc_conn
=
self
.
_storage
.
_server
.
rpc
zrpc_conn
.
message_output
(
msg
)
future
=
concurrent
.
futures
.
Future
()
def
write
():
try
:
try
:
self
.
_dostore
(
)
self
.
_storage
.
_server
.
client
.
protocol
.
_write
(
msg
)
except
ClientDisconnected
:
except
Exception
as
exc
:
pass
future
.
set_exception
(
exc
)
else
:
else
:
self
.
_storage
.
close
()
future
.
set_result
(
None
)
self
.
fail
(
"Server did not disconnect after bogus message"
)
self
.
_storage
.
close
()
self
.
_storage
=
self
.
openClientStorage
()
# break into the internals to send a bogus message
self
.
_storage
.
_server
.
loop
.
call_soon_threadsafe
(
write
)
future
.
result
()
# If we manage to call _dostore before the server disconnects
# us, we'll get a ClientDisconnected error. When we retry, it
# will succeed. It will succeed because:
# - _dostore calls tpc_abort
# - tpc_abort makes a synchronous call to the server to abort
# the transaction
# - when disconnected, synchronous calls are blocked for a little
# while while reconnecting (or they timeout of it takes too long).
try
:
self
.
_dostore
()
self
.
_dostore
()
self
.
_storage
.
close
()
except
ClientDisconnected
:
self
.
_dostore
()
self
.
assertTrue
(
self
.
_storage
.
_connection_generation
>
generation
)
# Test case for multiple storages participating in a single
# Test case for multiple storages participating in a single
# transaction. This is not really a connection test, but it needs
# transaction. This is not really a connection test, but it needs
...
...
src/ZEO/tests/testConversionSupport.py
View file @
01d74173
...
@@ -14,6 +14,8 @@
...
@@ -14,6 +14,8 @@
import
doctest
import
doctest
import
unittest
import
unittest
import
ZEO.asyncio.testing
class
FakeStorageBase
:
class
FakeStorageBase
:
def
__getattr__
(
self
,
name
):
def
__getattr__
(
self
,
name
):
...
@@ -85,9 +87,8 @@ The storage info also reflects the fact that record_iternext is supported.
...
@@ -85,9 +87,8 @@ The storage info also reflects the fact that record_iternext is supported.
"""
"""
def
test_client_record_iternext
():
def
test_client_record_iternext
():
"""
\
"""
Test client storage delegation to the network client
The client simply delegates record_iternext calls to it's server stub.
The client simply delegates record_iternext calls to it's server stub.
...
@@ -96,53 +97,28 @@ stuff. I'd rather do a lame test than a really lame test, so here goes.
...
@@ -96,53 +97,28 @@ stuff. I'd rather do a lame test than a really lame test, so here goes.
First, fake out the connection manager so we can make a connection:
First, fake out the connection manager so we can make a connection:
>>> import ZEO.ClientStorage
>>> import ZEO
>>> from ZEO.ClientStorage import ClientStorage
>>> oldConnectionManagerClass = ClientStorage.ConnectionManagerClass
>>> class FauxConnectionManagerClass:
... def __init__(*a, **k):
... pass
... def attempt_connect(self):
... return True
>>> ClientStorage.ConnectionManagerClass = FauxConnectionManagerClass
>>> client = ClientStorage('', wait=False)
>>> ClientStorage.ConnectionManagerClass = oldConnectionManagerClass
Now we'll have our way with it's private _server attr:
>>> client._server = FakeStorage()
>>> next = None
>>> while 1:
... oid, serial, data, next = client.record_iternext(next)
... print(oid)
... if next is None:
... break
1
2
3
4
"""
def
test_server_stub_record_iternext
():
>>> class Client(ZEO.asyncio.testing.ClientRunner):
"""
\
...
... def record_iternext(self, next=None):
... if next == None:
... next = '0'
... next = str(int(next) + 1)
... oid = next
... if next == '4':
... next = None
...
... return oid, oid*8, 'data ' + oid, next
The server stub simply delegates record_iternext calls to it's rpc.
>>> client = ZEO.client(
... '', wait=False, _client_factory=Client)
There's really no decent way to test ZEO without running to much crazy
Now we'll have our way with it's private _server attr:
stuff. I'd rather do a lame test than a really lame test, so here goes.
>>> class FauxRPC:
... storage = FakeStorage()
... def call(self, meth, *args):
... return getattr(self.storage, meth)(*args)
... peer_protocol_version = 1
>>> import ZEO.ServerStub
>>> stub = ZEO.ServerStub.StorageServer(FauxRPC())
>>> next = None
>>> next = None
>>> while 1:
>>> while 1:
... oid, serial, data, next =
stub
.record_iternext(next)
... oid, serial, data, next =
client
.record_iternext(next)
... print(oid)
... print(oid)
... if next is None:
... if next is None:
... break
... break
...
@@ -193,4 +169,3 @@ def test_suite():
...
@@ -193,4 +169,3 @@ def test_suite():
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
(
defaultTest
=
'test_suite'
)
unittest
.
main
(
defaultTest
=
'test_suite'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment