[ARVADOS] updated: 4aa4ae976940d7ba11ad7c3391cb03139fb2ef25
git at public.curoverse.com
git at public.curoverse.com
Mon Nov 16 10:37:44 EST 2015
Summary of changes:
sdk/python/tests/keepstub.py | 23 ++++++++++-------------
sdk/python/tests/test_keep_client.py | 10 +++++++---
2 files changed, 17 insertions(+), 16 deletions(-)
via 4aa4ae976940d7ba11ad7c3391cb03139fb2ef25 (commit)
from 17d97ed03bd1199ba7585b251d144a82071f1bf4 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 4aa4ae976940d7ba11ad7c3391cb03139fb2ef25
Author: Tom Clegg <tom at curoverse.com>
Date: Mon Nov 16 10:37:35 2015 -0500
7235: Use millisecond precision (like curl) to measure timeouts. Tweak bandwidth limiters.
diff --git a/sdk/python/tests/keepstub.py b/sdk/python/tests/keepstub.py
index bb46f52..860b2a5 100644
--- a/sdk/python/tests/keepstub.py
+++ b/sdk/python/tests/keepstub.py
@@ -64,17 +64,17 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler, object):
outage_happened = False
num_bytes = len(data_to_write)
num_sent_bytes = 0
+ target_time = time.time()
while num_sent_bytes < num_bytes:
if num_sent_bytes > self.server.bandwidth and not outage_happened:
self.server._do_delay('mid_write')
+ target_time += self.delays['mid_write']
outage_happened = True
num_write_bytes = min(BYTES_PER_WRITE,
num_bytes - num_sent_bytes)
- if self.server.bandwidth == None:
- wait = 0
- else:
- wait = num_write_bytes / self.server.bandwidth
- self.server._sleep_at_least(wait)
+ if self.server.bandwidth is not None:
+ target_time += num_write_bytes / self.server.bandwidth
+ self.server._sleep_at_least(target_time - time.time())
self.wfile.write(data_to_write[
num_sent_bytes:num_sent_bytes+num_write_bytes])
num_sent_bytes += num_write_bytes
@@ -88,21 +88,18 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler, object):
data = ''
outage_happened = False
bytes_read = 0
+ target_time = time.time()
while bytes_to_read > bytes_read:
if bytes_read > self.server.bandwidth and not outage_happened:
self.server._do_delay('mid_read')
+ target_time += self.delays['mid_read']
outage_happened = True
next_bytes_to_read = min(BYTES_PER_READ,
bytes_to_read - bytes_read)
- t0 = time.time()
data += self.rfile.read(next_bytes_to_read)
- time_spent_getting_data = time.time() - t0
- if self.server.bandwidth == None:
- wait = 0
- else:
- wait = next_bytes_to_read/self.server.bandwidth - time_spent_getting_data
- if wait > 0:
- self.server._sleep_at_least(wait)
+ if self.server.bandwidth is not None:
+ target_time += next_bytes_to_read / self.server.bandwidth
+ self.server._sleep_at_least(target_time - time.time())
bytes_read += next_bytes_to_read
return data
diff --git a/sdk/python/tests/test_keep_client.py b/sdk/python/tests/test_keep_client.py
index 51c60e9..752cb6a 100644
--- a/sdk/python/tests/test_keep_client.py
+++ b/sdk/python/tests/test_keep_client.py
@@ -564,8 +564,11 @@ class KeepClientTimeout(unittest.TestCase, tutil.ApiClientMock):
self.t0 = time.time()
def __exit__(self, *args, **kwargs):
- self.assertGreater(time.time() - self.t0, self.tmin)
- self.assertLess(time.time() - self.t0, self.tmax)
+ # Round times to milliseconds, like CURL. Otherwise, we
+ # fail when CURL reaches a 1s timeout at 0.9998s.
+ delta = round(time.time() - self.t0, 3)
+ self.assertGreaterEqual(delta, self.tmin)
+ self.assertLessEqual(delta, self.tmax)
class assertTakesGreater(unittest.TestCase):
def __init__(self, tmin):
@@ -575,7 +578,8 @@ class KeepClientTimeout(unittest.TestCase, tutil.ApiClientMock):
self.t0 = time.time()
def __exit__(self, *args, **kwargs):
- self.assertGreater(time.time() - self.t0, self.tmin)
+ delta = round(time.time() - self.t0, 3)
+ self.assertGreaterEqual(delta, self.tmin)
def setUp(self):
sock = socket.socket()
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list