[Neo-report] r2033 vincent - in /trunk/neo: connection.py tests/testConnection.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Apr 27 17:11:48 CEST 2010
Author: vincent
Date: Tue Apr 27 17:11:46 2010
New Revision: 2033
Log:
Fix cases where ping would fire immediately after sending a packet.
If a first packet is sent and its answer received in time, then a second
packet is sent after more than PING_DELAY seconds, a ping will be emitted
right after that second packet, because _ping_time was still set.
This change resets it when there is no pending requests.
Also, as required to have a consistent view of _handlers, check that lock
is properly held in the MT variant of the class.
Modified:
trunk/neo/connection.py
trunk/neo/tests/testConnection.py
Modified: trunk/neo/connection.py
==============================================================================
--- trunk/neo/connection.py [iso-8859-1] (original)
+++ trunk/neo/connection.py [iso-8859-1] Tue Apr 27 17:11:46 2010
@@ -165,6 +165,12 @@
""" Keep track of connection-level timeouts """
def __init__(self):
+ self.clear()
+
+ def clear(self):
+ """
+ There is no pending request, reset ping times.
+ """
self._ping_time = None
self._critical_time = None
@@ -446,7 +452,11 @@
"""
# check out packet and process it with current handler
packet = self._queue.pop(0)
- self._handlers.handle(packet)
+ handlers = self._handlers
+ handlers.handle(packet)
+ if not handlers.isPending():
+ # We are not expecting any other response, clear timeout
+ self._timeout.clear()
def pending(self):
return self.connector is not None and self.write_buf
@@ -695,3 +705,7 @@
finally:
self.release()
+ @lockCheckWrapper
+ def process(self, *args, **kw):
+ return super(MTClientConnection, self).process(*args, **kw)
+
Modified: trunk/neo/tests/testConnection.py
==============================================================================
--- trunk/neo/tests/testConnection.py [iso-8859-1] (original)
+++ trunk/neo/tests/testConnection.py [iso-8859-1] Tue Apr 27 17:11:46 2010
@@ -999,13 +999,16 @@
def setUp(self):
self.current = time()
self.timeout = Timeout()
- self.timeout.update(self.current)
+ self._updateAt(0)
self.assertTrue(PING_DELAY > PING_TIMEOUT) # Sanity check
def _checkAt(self, n, soft, hard):
at = self.current + n
self.assertEqual(soft, self.timeout.softExpired(at))
self.assertEqual(hard, self.timeout.hardExpired(at))
+
+ def _updateAt(self, n):
+ self.timeout.update(self.current + n)
def _refreshAt(self, n):
self.timeout.refresh(self.current + n)
@@ -1030,6 +1033,13 @@
self._checkAt(PING_DELAY + 0.5, False, False)
# ...but it will happen again after PING_DELAY after that answer
self._checkAt(answer_time + PING_DELAY + 0.5, True, False)
+ # if there is no more pending requests, a clear will happen so next
+ # send doesn't immediately trigger a ping
+ self.timeout.clear()
+ new_request_time = answer_time + PING_DELAY * 2
+ self._updateAt(new_request_time)
+ self._checkAt(new_request_time + PING_DELAY - 0.5, False, False)
+ self._checkAt(new_request_time + PING_DELAY + 0.5, True, False)
def testHardTimeout(self):
"""
More information about the Neo-report
mailing list