You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kg...@apache.org on 2013/12/09 19:35:57 UTC
svn commit: r1549639 - in /qpid/proton/trunk:
proton-c/bindings/python/proton.py tests/python/proton_tests/engine.py
Author: kgiusti
Date: Mon Dec 9 18:35:56 2013
New Revision: 1549639
URL: http://svn.apache.org/r1549639
Log:
PROTON-475: use seconds-based timeout values
Modified:
qpid/proton/trunk/proton-c/bindings/python/proton.py
qpid/proton/trunk/tests/python/proton_tests/engine.py
Modified: qpid/proton/trunk/proton-c/bindings/python/proton.py
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/python/proton.py?rev=1549639&r1=1549638&r2=1549639&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/python/proton.py (original)
+++ qpid/proton/trunk/proton-c/bindings/python/proton.py Mon Dec 9 18:35:56 2013
@@ -2730,7 +2730,11 @@ class Transport(object):
pn_transport_trace(self._trans, n)
def tick(self, now):
- return pn_transport_tick(self._trans, now)
+ """Process any timed events (like heartbeat generation).
+ now = seconds since epoch (float).
+ """
+ next = pn_transport_tick(self._trans, long(now * 1000))
+ return float(next) / 1000.0
def capacity(self):
c = pn_transport_capacity(self._trans)
@@ -2805,10 +2809,11 @@ Sets the maximum size for received frame
# AMQP 1.0 idle-time-out
def _get_idle_timeout(self):
- return pn_transport_get_idle_timeout(self._trans)
+ msec = pn_transport_get_idle_timeout(self._trans)
+ return float(msec)/1000.0
- def _set_idle_timeout(self, value):
- pn_transport_set_idle_timeout(self._trans, value)
+ def _set_idle_timeout(self, sec):
+ pn_transport_set_idle_timeout(self._trans, long(sec * 1000))
idle_timeout = property(_get_idle_timeout, _set_idle_timeout,
doc="""
@@ -2817,7 +2822,8 @@ The idle timeout of the connection (in m
@property
def remote_idle_timeout(self):
- return pn_transport_get_remote_idle_timeout(self._trans)
+ msec = pn_transport_get_remote_idle_timeout(self._trans)
+ return float(msec)/1000.0
@property
def frames_output(self):
@@ -3092,8 +3098,12 @@ class Driver(object):
pn_driver_free(self._driver)
del self._driver
- def wait(self, timeout):
- return pn_driver_wait(self._driver, timeout)
+ def wait(self, timeout_sec):
+ if timeout_sec is None or timeout_sec < 0.0:
+ t = -1
+ else:
+ t = long(1000*timeout_sec)
+ return pn_driver_wait(self._driver, t)
def wakeup(self):
return pn_driver_wakeup(self._driver)
Modified: qpid/proton/trunk/tests/python/proton_tests/engine.py
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/tests/python/proton_tests/engine.py?rev=1549639&r1=1549638&r2=1549639&view=diff
==============================================================================
--- qpid/proton/trunk/tests/python/proton_tests/engine.py (original)
+++ qpid/proton/trunk/tests/python/proton_tests/engine.py Mon Dec 9 18:35:56 2013
@@ -68,6 +68,7 @@ class Test(common.Test):
c1._transport.max_frame_size = max_frame[0]
c2._transport.max_frame_size = max_frame[1]
if idle_timeout:
+ # idle_timeout in seconds expressed as float
c1._transport.idle_timeout = idle_timeout[0]
c2._transport.idle_timeout = idle_timeout[1]
c1.open()
@@ -866,16 +867,16 @@ class IdleTimeoutTest(Test):
Verify the configuration and negotiation of the idle timeout.
"""
- self.snd, self.rcv = self.link("test-link", idle_timeout=[1000,2000])
+ self.snd, self.rcv = self.link("test-link", idle_timeout=[1.0,2.0])
self.c1 = self.snd.session.connection
self.c2 = self.rcv.session.connection
self.snd.open()
self.rcv.open()
self.pump()
- assert self.rcv.session.connection._transport.idle_timeout == 2000
- assert self.rcv.session.connection._transport.remote_idle_timeout == 1000
- assert self.snd.session.connection._transport.idle_timeout == 1000
- assert self.snd.session.connection._transport.remote_idle_timeout == 2000
+ assert self.rcv.session.connection._transport.idle_timeout == 2.0
+ assert self.rcv.session.connection._transport.remote_idle_timeout == 1.0
+ assert self.snd.session.connection._transport.idle_timeout == 1.0
+ assert self.snd.session.connection._transport.remote_idle_timeout == 2.0
def testTimeout(self):
"""
@@ -883,7 +884,7 @@ class IdleTimeoutTest(Test):
"""
# snd will timeout the Connection if no frame is received within 1000 ticks
- self.snd, self.rcv = self.link("test-link", idle_timeout=[1000,0])
+ self.snd, self.rcv = self.link("test-link", idle_timeout=[1.0,0])
self.c1 = self.snd.session.connection
self.c2 = self.rcv.session.connection
self.snd.open()
@@ -892,32 +893,32 @@ class IdleTimeoutTest(Test):
t_snd = self.snd.session.connection._transport
t_rcv = self.rcv.session.connection._transport
- assert t_rcv.idle_timeout == 0
- assert t_rcv.remote_idle_timeout == 1000
- assert t_snd.idle_timeout == 1000
- assert t_snd.remote_idle_timeout == 0
+ assert t_rcv.idle_timeout == 0.0
+ assert t_rcv.remote_idle_timeout == 1.0
+ assert t_snd.idle_timeout == 1.0
+ assert t_snd.remote_idle_timeout == 0.0
sndr_frames_in = t_snd.frames_input
rcvr_frames_out = t_rcv.frames_output
- # at t+1, nothing should happen:
- clock = 1
- assert t_snd.tick(clock) == 1001, "deadline for remote timeout"
- assert t_rcv.tick(clock) == 501, "deadline to send keepalive"
+ # at t+1msec, nothing should happen:
+ clock = 0.001
+ assert t_snd.tick(clock) == 1.001, "deadline for remote timeout"
+ assert t_rcv.tick(clock) == 0.501, "deadline to send keepalive"
self.pump()
assert sndr_frames_in == t_snd.frames_input, "unexpected received frame"
# at one tick from expected idle frame send, nothing should happen:
- clock = 500
- assert t_snd.tick(clock) == 1001, "deadline for remote timeout"
- assert t_rcv.tick(clock) == 501, "deadline to send keepalive"
+ clock = 0.500
+ assert t_snd.tick(clock) == 1.001, "deadline for remote timeout"
+ assert t_rcv.tick(clock) == 0.501, "deadline to send keepalive"
self.pump()
assert sndr_frames_in == t_snd.frames_input, "unexpected received frame"
# this should cause rcvr to expire and send a keepalive
- clock = 502
- assert t_snd.tick(clock) == 1001, "deadline for remote timeout"
- assert t_rcv.tick(clock) == 1002, "deadline to send keepalive"
+ clock = 0.502
+ assert t_snd.tick(clock) == 1.001, "deadline for remote timeout"
+ assert t_rcv.tick(clock) == 1.002, "deadline to send keepalive"
self.pump()
sndr_frames_in += 1
rcvr_frames_out += 1
@@ -926,14 +927,14 @@ class IdleTimeoutTest(Test):
# since a keepalive was received, sndr will rebase its clock against this tick:
# and the receiver should not change its deadline
- clock = 503
- assert t_snd.tick(clock) == 1503, "deadline for remote timeout"
- assert t_rcv.tick(clock) == 1002, "deadline to send keepalive"
+ clock = 0.503
+ assert t_snd.tick(clock) == 1.503, "deadline for remote timeout"
+ assert t_rcv.tick(clock) == 1.002, "deadline to send keepalive"
self.pump()
assert sndr_frames_in == t_snd.frames_input, "unexpected received frame"
# now expire sndr
- clock = 1504
+ clock = 1.504
t_snd.tick(clock)
try:
self.pump()
@@ -1642,7 +1643,7 @@ class ServerTest(Test):
self.server.start()
self.driver = Driver()
self.cxtr = self.driver.connector(self.server.host, self.server.port)
- self.cxtr.transport.idle_timeout = int(idle_timeout_secs * 1000) #msecs
+ self.cxtr.transport.idle_timeout = idle_timeout_secs
self.cxtr.sasl().mechanisms("ANONYMOUS")
self.cxtr.sasl().client()
self.conn = Connection()
@@ -1659,7 +1660,7 @@ class ServerTest(Test):
while self.conn.state != (Endpoint.LOCAL_ACTIVE | Endpoint.REMOTE_ACTIVE) \
and time() <= deadline:
self.cxtr.process()
- self.driver.wait(1)
+ self.driver.wait(0.001)
self.cxtr.process()
assert self.conn.state == (Endpoint.LOCAL_ACTIVE | Endpoint.REMOTE_ACTIVE), "Connection failed"
@@ -1670,7 +1671,7 @@ class ServerTest(Test):
deadline = time() + duration
while time() <= deadline:
self.cxtr.process()
- self.driver.wait(1)
+ self.driver.wait(0.001)
self.cxtr.process()
assert self.conn.state == (Endpoint.LOCAL_ACTIVE | Endpoint.REMOTE_ACTIVE), "Connection terminated"
@@ -1683,7 +1684,7 @@ class ServerTest(Test):
arrive in a timely manner.
"""
idle_timeout_secs = self.delay
- self.server = common.TestServerDrain(idle_timeout=int(idle_timeout_secs * 1000))
+ self.server = common.TestServerDrain(idle_timeout=idle_timeout_secs)
self.server.start()
self.driver = Driver()
self.cxtr = self.driver.connector(self.server.host, self.server.port)
@@ -1699,7 +1700,7 @@ class ServerTest(Test):
while self.conn.state != (Endpoint.LOCAL_ACTIVE | Endpoint.REMOTE_ACTIVE) \
and time() <= deadline:
self.cxtr.process()
- self.driver.wait(int(self.timeout * 1000))
+ self.driver.wait(self.timeout)
self.cxtr.process()
assert self.conn.state == (Endpoint.LOCAL_ACTIVE | Endpoint.REMOTE_ACTIVE), "Connection failed"
@@ -1711,7 +1712,7 @@ class ServerTest(Test):
deadline = time() + duration
while time() <= deadline:
self.cxtr.process()
- self.driver.wait(int(10 * duration * 1000))
+ self.driver.wait(10 * duration)
self.cxtr.process()
assert self.conn.state == (Endpoint.LOCAL_ACTIVE | Endpoint.REMOTE_ACTIVE), "Connection terminated"
@@ -1726,7 +1727,7 @@ class ServerTest(Test):
deadline = time() + self.timeout
while (self.conn.state & Endpoint.REMOTE_ACTIVE) and time() <= deadline:
self.cxtr.process()
- self.driver.wait(int(self.timeout*1000))
+ self.driver.wait(self.timeout)
self.cxtr.process()
assert self.conn.state & Endpoint.REMOTE_CLOSED, "Connection failed to close"
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org