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
7cdcc013
Commit
7cdcc013
authored
Jul 17, 2016
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated connect/verify to use generators
parent
f96776b3
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
123 additions
and
148 deletions
+123
-148
src/ZEO/asyncio/client.py
src/ZEO/asyncio/client.py
+94
-100
src/ZEO/asyncio/tests.py
src/ZEO/asyncio/tests.py
+29
-48
No files found.
src/ZEO/asyncio/client.py
View file @
7cdcc013
This diff is collapsed.
Click to expand it.
src/ZEO/asyncio/tests.py
View file @
7cdcc013
...
@@ -72,6 +72,10 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
...
@@ -72,6 +72,10 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
maxDiff
=
None
maxDiff
=
None
def
tearDown
(
self
):
self
.
client
.
close
()
super
(
ClientTests
,
self
)
def
start
(
self
,
def
start
(
self
,
addrs
=
((
'127.0.0.1'
,
8200
),
),
loop_addrs
=
None
,
addrs
=
((
'127.0.0.1'
,
8200
),
),
loop_addrs
=
None
,
read_only
=
False
,
read_only
=
False
,
...
@@ -96,12 +100,9 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
...
@@ -96,12 +100,9 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
if
finish_start
:
if
finish_start
:
protocol
.
data_received
(
sized
(
b'Z3101'
))
protocol
.
data_received
(
sized
(
b'Z3101'
))
self
.
assertEqual
(
self
.
pop
(
2
,
False
),
b'Z3101'
)
self
.
assertEqual
(
self
.
pop
(
2
,
False
),
b'Z3101'
)
self
.
assertEqual
(
self
.
pop
(),
[(
1
,
False
,
'register'
,
(
'TEST'
,
False
)),
(
2
,
False
,
'lastTransaction'
,
()),
])
self
.
respond
(
1
,
None
)
self
.
respond
(
1
,
None
)
self
.
respond
(
2
,
'a'
*
8
)
self
.
respond
(
2
,
'a'
*
8
)
self
.
pop
(
4
)
self
.
assertEqual
(
self
.
pop
(),
(
3
,
False
,
'get_info'
,
()))
self
.
assertEqual
(
self
.
pop
(),
(
3
,
False
,
'get_info'
,
()))
self
.
respond
(
3
,
dict
(
length
=
42
))
self
.
respond
(
3
,
dict
(
length
=
42
))
...
@@ -135,12 +136,9 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
...
@@ -135,12 +136,9 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
# The client sends back a handshake, and registers the
# The client sends back a handshake, and registers the
# storage, and requests the last transaction.
# storage, and requests the last transaction.
self
.
assertEqual
(
self
.
pop
(
2
,
False
),
b'Z5'
)
self
.
assertEqual
(
self
.
pop
(
2
,
False
),
b'Z5'
)
self
.
assertEqual
(
self
.
pop
(),
self
.
assertEqual
(
self
.
pop
(),
(
1
,
False
,
'register'
,
(
'TEST'
,
False
)))
[(
1
,
False
,
'register'
,
(
'TEST'
,
False
)),
(
2
,
False
,
'lastTransaction'
,
()),
])
#
Actually, t
he client isn't connected until it initializes it's cache:
#
T
he client isn't connected until it initializes it's cache:
self
.
assertFalse
(
client
.
connected
.
done
()
or
transport
.
data
)
self
.
assertFalse
(
client
.
connected
.
done
()
or
transport
.
data
)
# If we try to make calls while the client is *initially*
# If we try to make calls while the client is *initially*
...
@@ -163,9 +161,13 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
...
@@ -163,9 +161,13 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
# The wrapper object (ClientStorage) hasn't been notified:
# The wrapper object (ClientStorage) hasn't been notified:
self
.
assertFalse
(
wrapper
.
notify_connected
.
called
)
self
.
assertFalse
(
wrapper
.
notify_connected
.
called
)
# Let's respond to those first 2 calls:
# Let's respond to the register call:
self
.
respond
(
1
,
None
)
self
.
respond
(
1
,
None
)
# The client requests the last transaction:
self
.
assertEqual
(
self
.
pop
(),
(
2
,
False
,
'lastTransaction'
,
()))
# We respond
self
.
respond
(
2
,
'a'
*
8
)
self
.
respond
(
2
,
'a'
*
8
)
# After verification, the client requests info:
# After verification, the client requests info:
...
@@ -298,15 +300,14 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
...
@@ -298,15 +300,14 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
# protocol:
# protocol:
protocol
.
data_received
(
sized
(
b'Z310'
))
protocol
.
data_received
(
sized
(
b'Z310'
))
self
.
assertEqual
(
self
.
unsized
(
transport
.
pop
(
2
)),
b'Z310'
)
self
.
assertEqual
(
self
.
unsized
(
transport
.
pop
(
2
)),
b'Z310'
)
self
.
assertEqual
(
self
.
pop
(),
self
.
assertEqual
(
self
.
pop
(),
(
1
,
False
,
'register'
,
(
'TEST'
,
False
)))
[(
1
,
False
,
'register'
,
(
'TEST'
,
False
)),
(
2
,
False
,
'lastTransaction'
,
()),
])
self
.
assertFalse
(
wrapper
.
notify_connected
.
called
)
self
.
assertFalse
(
wrapper
.
notify_connected
.
called
)
self
.
respond
(
1
,
None
)
self
.
respond
(
2
,
b'e'
*
8
)
# If the register response is a tid, then the client won't
self
.
assertEqual
(
self
.
pop
(),
(
3
,
False
,
'get_info'
,
()))
# request lastTransaction
self
.
respond
(
3
,
dict
(
length
=
42
))
self
.
respond
(
1
,
b'e'
*
8
)
self
.
assertEqual
(
self
.
pop
(),
(
2
,
False
,
'get_info'
,
()))
self
.
respond
(
2
,
dict
(
length
=
42
))
# Because the server tid matches the cache tid, we're done connecting
# Because the server tid matches the cache tid, we're done connecting
wrapper
.
notify_connected
.
assert_called_with
(
client
,
{
'length'
:
42
})
wrapper
.
notify_connected
.
assert_called_with
(
client
,
{
'length'
:
42
})
...
@@ -335,12 +336,9 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
...
@@ -335,12 +336,9 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
self
.
assertFalse
(
client
.
connected
.
done
()
or
transport
.
data
)
self
.
assertFalse
(
client
.
connected
.
done
()
or
transport
.
data
)
protocol
.
data_received
(
sized
(
b'Z3101'
))
protocol
.
data_received
(
sized
(
b'Z3101'
))
self
.
assertEqual
(
self
.
unsized
(
transport
.
pop
(
2
)),
b'Z3101'
)
self
.
assertEqual
(
self
.
unsized
(
transport
.
pop
(
2
)),
b'Z3101'
)
self
.
assertEqual
(
self
.
pop
(),
[(
1
,
False
,
'register'
,
(
'TEST'
,
False
)),
(
2
,
False
,
'lastTransaction'
,
()),
])
self
.
respond
(
1
,
None
)
self
.
respond
(
1
,
None
)
self
.
respond
(
2
,
b'e'
*
8
)
self
.
respond
(
2
,
b'e'
*
8
)
self
.
pop
(
4
)
# We have to verify the cache, so we're not done connecting:
# We have to verify the cache, so we're not done connecting:
self
.
assertFalse
(
client
.
connected
.
done
())
self
.
assertFalse
(
client
.
connected
.
done
())
...
@@ -373,12 +371,9 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
...
@@ -373,12 +371,9 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
self
.
assertFalse
(
client
.
connected
.
done
()
or
transport
.
data
)
self
.
assertFalse
(
client
.
connected
.
done
()
or
transport
.
data
)
protocol
.
data_received
(
sized
(
b'Z3101'
))
protocol
.
data_received
(
sized
(
b'Z3101'
))
self
.
assertEqual
(
self
.
unsized
(
transport
.
pop
(
2
)),
b'Z3101'
)
self
.
assertEqual
(
self
.
unsized
(
transport
.
pop
(
2
)),
b'Z3101'
)
self
.
assertEqual
(
self
.
pop
(),
[(
1
,
False
,
'register'
,
(
'TEST'
,
False
)),
(
2
,
False
,
'lastTransaction'
,
()),
])
self
.
respond
(
1
,
None
)
self
.
respond
(
1
,
None
)
self
.
respond
(
2
,
b'e'
*
8
)
self
.
respond
(
2
,
b'e'
*
8
)
self
.
pop
(
4
)
# We have to verify the cache, so we're not done connecting:
# We have to verify the cache, so we're not done connecting:
self
.
assertFalse
(
client
.
connected
.
done
())
self
.
assertFalse
(
client
.
connected
.
done
())
...
@@ -445,12 +440,9 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
...
@@ -445,12 +440,9 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
cache
.
setLastTid
(
'b'
*
8
)
cache
.
setLastTid
(
'b'
*
8
)
protocol
.
data_received
(
sized
(
b'Z3101'
))
protocol
.
data_received
(
sized
(
b'Z3101'
))
self
.
assertEqual
(
self
.
unsized
(
transport
.
pop
(
2
)),
b'Z3101'
)
self
.
assertEqual
(
self
.
unsized
(
transport
.
pop
(
2
)),
b'Z3101'
)
self
.
assertEqual
(
self
.
pop
(),
[(
1
,
False
,
'register'
,
(
'TEST'
,
False
)),
(
2
,
False
,
'lastTransaction'
,
()),
])
self
.
respond
(
1
,
None
)
self
.
respond
(
1
,
None
)
self
.
respond
(
2
,
'a'
*
8
)
self
.
respond
(
2
,
'a'
*
8
)
self
.
pop
()
self
.
assertFalse
(
client
.
connected
.
done
()
or
transport
.
data
)
self
.
assertFalse
(
client
.
connected
.
done
()
or
transport
.
data
)
delay
,
func
,
args
,
_
=
loop
.
later
.
pop
(
1
)
# first in later is heartbeat
delay
,
func
,
args
,
_
=
loop
.
later
.
pop
(
1
)
# first in later is heartbeat
self
.
assert_
(
8
<
delay
<
10
)
self
.
assert_
(
8
<
delay
<
10
)
...
@@ -462,12 +454,9 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
...
@@ -462,12 +454,9 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
transport
=
loop
.
transport
transport
=
loop
.
transport
protocol
.
data_received
(
sized
(
b'Z3101'
))
protocol
.
data_received
(
sized
(
b'Z3101'
))
self
.
assertEqual
(
self
.
unsized
(
transport
.
pop
(
2
)),
b'Z3101'
)
self
.
assertEqual
(
self
.
unsized
(
transport
.
pop
(
2
)),
b'Z3101'
)
self
.
assertEqual
(
self
.
pop
(),
[(
1
,
False
,
'register'
,
(
'TEST'
,
False
)),
(
2
,
False
,
'lastTransaction'
,
()),
])
self
.
respond
(
1
,
None
)
self
.
respond
(
1
,
None
)
self
.
respond
(
2
,
'b'
*
8
)
self
.
respond
(
2
,
'b'
*
8
)
self
.
pop
(
4
)
self
.
assertEqual
(
self
.
pop
(),
(
3
,
False
,
'get_info'
,
()))
self
.
assertEqual
(
self
.
pop
(),
(
3
,
False
,
'get_info'
,
()))
self
.
respond
(
3
,
dict
(
length
=
42
))
self
.
respond
(
3
,
dict
(
length
=
42
))
self
.
assert_
(
client
.
connected
.
done
()
and
not
transport
.
data
)
self
.
assert_
(
client
.
connected
.
done
()
and
not
transport
.
data
)
...
@@ -493,12 +482,10 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
...
@@ -493,12 +482,10 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
self
.
assertTrue
(
self
.
is_read_only
())
self
.
assertTrue
(
self
.
is_read_only
())
# The client tries for a read-only connection:
# The client tries for a read-only connection:
self
.
assertEqual
(
self
.
pop
(),
self
.
assertEqual
(
self
.
pop
(),
(
2
,
False
,
'register'
,
(
'TEST'
,
True
)))
[(
2
,
False
,
'register'
,
(
'TEST'
,
True
)),
(
3
,
False
,
'lastTransaction'
,
()),
])
# We respond with successfully:
# We respond with successfully:
self
.
respond
(
2
,
None
)
self
.
respond
(
2
,
None
)
self
.
pop
(
2
)
self
.
respond
(
3
,
'b'
*
8
)
self
.
respond
(
3
,
'b'
*
8
)
self
.
assertTrue
(
self
.
is_read_only
())
self
.
assertTrue
(
self
.
is_read_only
())
...
@@ -525,12 +512,12 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
...
@@ -525,12 +512,12 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
# We respond and the writable connection succeeds:
# We respond and the writable connection succeeds:
self
.
respond
(
1
,
None
)
self
.
respond
(
1
,
None
)
self
.
assertFalse
(
self
.
is_read_only
())
# at this point, a lastTransaction request is emitted:
# at this point, a lastTransaction request is emitted:
self
.
assertEqual
(
self
.
parse
(
loop
.
transport
.
pop
()),
self
.
assertEqual
(
self
.
parse
(
loop
.
transport
.
pop
()),
(
2
,
False
,
'lastTransaction'
,
()))
(
2
,
False
,
'lastTransaction'
,
()))
self
.
assertFalse
(
self
.
is_read_only
())
# Now, the original protocol is closed, and the client is
# Now, the original protocol is closed, and the client is
# no-longer ready:
# no-longer ready:
...
@@ -554,11 +541,8 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
...
@@ -554,11 +541,8 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
wrapper
,
cache
,
loop
,
client
,
protocol
,
transport
=
self
.
start
()
wrapper
,
cache
,
loop
,
client
,
protocol
,
transport
=
self
.
start
()
protocol
.
data_received
(
sized
(
b'Z3101'
))
protocol
.
data_received
(
sized
(
b'Z3101'
))
self
.
assertEqual
(
self
.
unsized
(
transport
.
pop
(
2
)),
b'Z3101'
)
self
.
assertEqual
(
self
.
unsized
(
transport
.
pop
(
2
)),
b'Z3101'
)
self
.
assertEqual
(
self
.
pop
(),
[(
1
,
False
,
'register'
,
(
'TEST'
,
False
)),
(
2
,
False
,
'lastTransaction'
,
()),
])
self
.
respond
(
1
,
None
)
self
.
respond
(
1
,
None
)
self
.
pop
(
4
)
self
.
send
(
'invalidateTransaction'
,
b'b'
*
8
,
[
b'1'
*
8
],
called
=
False
)
self
.
send
(
'invalidateTransaction'
,
b'b'
*
8
,
[
b'1'
*
8
],
called
=
False
)
self
.
respond
(
2
,
b'a'
*
8
)
self
.
respond
(
2
,
b'a'
*
8
)
self
.
send
(
'invalidateTransaction'
,
b'c'
*
8
,
[
b'1'
*
8
],
no_output
=
False
)
self
.
send
(
'invalidateTransaction'
,
b'c'
*
8
,
[
b'1'
*
8
],
no_output
=
False
)
...
@@ -575,11 +559,8 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
...
@@ -575,11 +559,8 @@ class ClientTests(Base, setupstack.TestCase, ClientRunner):
protocol
.
data_received
(
sized
(
b'Z3101'
))
protocol
.
data_received
(
sized
(
b'Z3101'
))
self
.
assertEqual
(
self
.
unsized
(
transport
.
pop
(
2
)),
b'Z3101'
)
self
.
assertEqual
(
self
.
unsized
(
transport
.
pop
(
2
)),
b'Z3101'
)
self
.
assertEqual
(
self
.
pop
(),
[(
1
,
False
,
'register'
,
(
'TEST'
,
False
)),
(
2
,
False
,
'lastTransaction'
,
()),
])
self
.
respond
(
1
,
None
)
self
.
respond
(
1
,
None
)
self
.
pop
(
4
)
self
.
send
(
'invalidateTransaction'
,
b'd'
*
8
,
[
b'1'
*
8
],
called
=
False
)
self
.
send
(
'invalidateTransaction'
,
b'd'
*
8
,
[
b'1'
*
8
],
called
=
False
)
self
.
respond
(
2
,
b'c'
*
8
)
self
.
respond
(
2
,
b'c'
*
8
)
self
.
send
(
'invalidateTransaction'
,
b'e'
*
8
,
[
b'1'
*
8
],
no_output
=
False
)
self
.
send
(
'invalidateTransaction'
,
b'e'
*
8
,
[
b'1'
*
8
],
no_output
=
False
)
...
...
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