Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
neoppod
Commits
4bde7d76
Commit
4bde7d76
authored
Mar 07, 2017
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code clean up: Connection
parent
dfa346a6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
42 deletions
+10
-42
neo/lib/connection.py
neo/lib/connection.py
+10
-22
neo/tests/master/testElectionHandler.py
neo/tests/master/testElectionHandler.py
+0
-20
No files found.
neo/lib/connection.py
View file @
4bde7d76
...
...
@@ -719,29 +719,17 @@ class MTClientConnection(ClientConnection):
with
lock
:
super
(
MTClientConnection
,
self
).
__init__
(
*
args
,
**
kwargs
)
# Alias without lock (cheaper than super())
_ask
=
ClientConnection
.
ask
.
__func__
def
ask
(
self
,
packet
,
timeout
=
CRITICAL_TIMEOUT
,
on_timeout
=
None
,
queue
=
None
,
**
kw
):
with
self
.
lock
:
if
self
.
isClosed
():
raise
ConnectionClosed
# XXX: Here, we duplicate Connection.ask because we need to call
# self.dispatcher.register after setId is called and before
# _addPacket is called.
msg_id
=
self
.
_getNextId
()
packet
.
setId
(
msg_id
)
if
queue
is
None
:
if
type
(
packet
)
is
not
Packets
.
Ping
:
raise
TypeError
,
'Only Ping packet can be asked '
\
'without a queue, got a %r.'
%
(
packet
,
)
else
:
self
.
dispatcher
.
register
(
self
,
msg_id
,
queue
)
self
.
_addPacket
(
packet
)
handlers
=
self
.
_handlers
t
=
None
if
handlers
.
isPending
()
else
time
()
handlers
.
emit
(
packet
,
timeout
,
on_timeout
,
kw
)
if
not
self
.
_queue
:
next_timeout
=
self
.
_next_timeout
self
.
updateTimeout
(
t
)
if
self
.
_next_timeout
<
next_timeout
:
self
.
em
.
wakeup
()
return
msg_id
if
type
(
packet
)
is
Packets
.
Ping
:
return
self
.
_ask
(
packet
,
timeout
,
on_timeout
,
**
kw
)
raise
TypeError
(
'Only Ping packet can be asked'
' without a queue, got a %r.'
%
packet
)
msg_id
=
self
.
_ask
(
packet
,
timeout
,
on_timeout
,
**
kw
)
self
.
dispatcher
.
register
(
self
,
msg_id
,
queue
)
return
msg_id
neo/tests/master/testElectionHandler.py
View file @
4bde7d76
...
...
@@ -25,12 +25,6 @@ from neo.master.handlers.election import ClientElectionHandler, \
from
neo.lib.exception
import
ElectionFailure
from
neo.lib.connection
import
ClientConnection
# patch connection so that we can register _addPacket messages
# in mock object
def
_addPacket
(
self
,
packet
):
if
self
.
connector
is
not
None
:
self
.
connector
.
_addPacket
(
packet
)
class
MasterClientElectionTestBase
(
NeoUnitTestBase
):
def
setUp
(
self
):
...
...
@@ -67,13 +61,6 @@ class MasterClientElectionTests(MasterClientElectionTestBase):
self
.
election
=
ClientElectionHandler
(
self
.
app
)
self
.
app
.
unconnected_master_node_set
=
set
()
self
.
app
.
negotiating_master_node_set
=
set
()
# apply monkey patches
ClientConnection
.
_addPacket
=
_addPacket
def
_tearDown
(
self
,
success
):
# restore patched methods
del
ClientConnection
.
_addPacket
NeoUnitTestBase
.
_tearDown
(
self
,
success
)
def
_checkUnconnected
(
self
,
node
):
addr
=
node
.
getAddress
()
...
...
@@ -223,13 +210,6 @@ class MasterServerElectionTests(MasterClientElectionTestBase):
self
.
client_address
=
(
self
.
local_ip
,
1000
)
self
.
storage_address
=
(
self
.
local_ip
,
2000
)
self
.
master_address
=
(
self
.
local_ip
,
3000
)
# apply monkey patches
ClientConnection
.
_addPacket
=
_addPacket
def
_tearDown
(
self
,
success
):
NeoUnitTestBase
.
_tearDown
(
self
,
success
)
# restore environment
del
ClientConnection
.
_addPacket
def
test_requestIdentification1
(
self
):
""" A non-master node request identification """
...
...
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