[ARVADOS] updated: 55ddaaf5c1a43250b218a3ac19323ed0ca57ae0e

git at public.curoverse.com git at public.curoverse.com
Fri Nov 13 18:15:11 EST 2015


Summary of changes:
 sdk/python/arvados/keep.py           |  10 +--
 sdk/python/tests/keepstub.py         |  16 ++---
 sdk/python/tests/test_keep_client.py | 126 +++++------------------------------
 3 files changed, 30 insertions(+), 122 deletions(-)

       via  55ddaaf5c1a43250b218a3ac19323ed0ca57ae0e (commit)
       via  4b0f625c6cd105ee87d77e73545463bf9120ca0e (commit)
       via  ca4ddecc445af64d4705f479eccb8f08b8cd6acc (commit)
      from  a17db371b9cb1fce74b71b4a1cda8bd5e5b740ed (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 55ddaaf5c1a43250b218a3ac19323ed0ca57ae0e
Author: sguthrie <sallyeguthrie at gmail.com>
Date:   Fri Nov 13 18:14:47 2015 -0500

    Remove long-running tests

diff --git a/sdk/python/tests/keepstub.py b/sdk/python/tests/keepstub.py
index 1f7c436..1f2792e 100644
--- a/sdk/python/tests/keepstub.py
+++ b/sdk/python/tests/keepstub.py
@@ -50,8 +50,6 @@ class Server(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer, object):
             todo = wake - time.time()
 
     def _do_delay(self, k):
-        if self.delays[k] > 0:
-            print "Delaying %f seconds for %s delay" % (self.delays[k], k)
         self._sleep_at_least(self.delays[k])
 
 
@@ -66,7 +64,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler, object):
             num_sent_bytes = 0
             while num_sent_bytes < num_bytes:
                 if num_sent_bytes > self.server.bandwidth and not outage_happened:
-                    print "Delaying write %fs" % (self.server.delays['mid_write'])
+                    #print "Delaying write %fs" % (self.server.delays['mid_write'])
                     self.server._do_delay('mid_write')
                     outage_happened = True
                 num_write_bytes = min(BYTES_PER_WRITE, num_bytes - num_sent_bytes)
@@ -74,7 +72,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler, object):
                     wait = 0
                 else:
                     wait = num_write_bytes / self.server.bandwidth
-                print "Bandwidth: %f b/s. Want to write total of %f bytes. Writing %f bytes now. Waiting %f seconds" % (self.server.bandwidth, num_bytes, num_write_bytes, wait)
+                #print "Bandwidth: %f b/s. Want to write total of %f bytes. Writing %f bytes now. Waiting %f seconds" % (self.server.bandwidth, num_bytes, num_write_bytes, wait)
                 self.server._sleep_at_least(wait)
                 self.wfile.write(data_to_write[num_sent_bytes:num_sent_bytes+num_write_bytes])
                 num_sent_bytes += num_write_bytes
@@ -90,7 +88,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler, object):
             bytes_read = 0
             while bytes_to_read > bytes_read:
                 if bytes_read > self.server.bandwidth and not outage_happened:
-                    print "Delaying read %fs" % (self.server.delays['mid_read'])
+                    #print "Delaying read %fs" % (self.server.delays['mid_read'])
                     self.server._do_delay('mid_read')
                     outage_happened = True
                 next_bytes_to_read = min(BYTES_PER_READ, bytes_to_read - bytes_read)
@@ -101,7 +99,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler, object):
                     wait = 0
                 else:
                     wait = next_bytes_to_read / self.server.bandwidth - time_spent_getting_data
-                print "Bandwidth: %f b/s. Wanted total of %f bytes. Now reading %f bytes. Have read %f bytes. Waiting %f seconds" % (self.server.bandwidth, bytes_to_read, next_bytes_to_read, len(data), wait)
+                #print "Bandwidth: %f b/s. Wanted total of %f bytes. Now reading %f bytes. Have read %f bytes. Waiting %f seconds" % (self.server.bandwidth, bytes_to_read, next_bytes_to_read, len(data), wait)
                 if wait > 0:
                     self.server._sleep_at_least(wait)
                 bytes_read += next_bytes_to_read
diff --git a/sdk/python/tests/test_keep_client.py b/sdk/python/tests/test_keep_client.py
index 43921ea..f46b8cf 100644
--- a/sdk/python/tests/test_keep_client.py
+++ b/sdk/python/tests/test_keep_client.py
@@ -550,196 +550,10 @@ class KeepClientRendezvousTestCase(unittest.TestCase, tutil.ApiClientMock):
     def test_put_error_shows_probe_order(self):
         self.check_64_zeros_error_order('put', arvados.errors.KeepWriteError)
 
- at unittest.skip('Takes a long time')
-class KeepClientTimeoutTakesTime(unittest.TestCase, tutil.ApiClientMock):
-    SMALL_DATA = 'x'*2**22
-    MEDIUM_DATA = 'x'*2**22
-    BIG_DATA = 'x' * 2**22
-    #2**16 causes low bandwidth expected failures to not error; allows successes
-    #2**22 causes low bandwidth expected failures to error correctly, but errors on expected successes
-    #2**17 causes all med_bandwidth to behave unexpectedly
-    #2**22 causes
-    #Needs to be above 11 to hit timeout time on lowest bandwidth
-    BANDWIDTH_LOW_LIM = 32
-    BANDWIDTH_DELTA = 1
-    TIMEOUT_TIME = 64
-    #Needs to be low to trigger bandwidth errors before we run out of data
-    TIMEOUT_DELTA = 1
-    #This is a variable determined by trial-and-error which probably depends on
-    #  the implementation of keepstub.py
-    class assertTakesBetween(unittest.TestCase):
-        def __init__(self, tmin, tmax):
-            self.tmin = tmin
-            self.tmax = tmax
-
-        def __enter__(self):
-            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)
-
-    class assertTakesGreater(unittest.TestCase):
-        def __init__(self, tmin):
-            self.tmin = tmin
-
-        def __enter__(self):
-            self.t0 = time.time()
-
-        def __exit__(self, *args, **kwargs):
-            self.assertGreater(time.time() - self.t0, self.tmin)
-
-    def setUp(self):
-        sock = socket.socket()
-        sock.bind(('0.0.0.0', 0))
-        self.port = sock.getsockname()[1]
-        sock.close()
-        self.server = keepstub.Server(('0.0.0.0', self.port), keepstub.Handler)
-        self.thread = threading.Thread(target=self.server.serve_forever)
-        self.thread.daemon = True # Exit thread if main proc exits
-        self.thread.start()
-        self.api_client = self.mock_keep_services(
-            count=1,
-            service_host='localhost',
-            service_port=self.port,
-        )
-
-    def tearDown(self):
-        self.server.shutdown()
-
-    def keepClient(self, timeouts=(0.1, TIMEOUT_TIME, BANDWIDTH_LOW_LIM)):
-        return arvados.KeepClient(
-            api_client=self.api_client,
-            timeout=timeouts)
-
-    def test_low_bandwidth_no_delays_success(self):
-        self.server.setbandwidth(self.BANDWIDTH_LOW_LIM+self.BANDWIDTH_DELTA)
-        kc = self.keepClient()
-        loc = kc.put(self.SMALL_DATA, copies=1, num_retries=0)
-        self.assertEqual(self.SMALL_DATA, kc.get(loc, num_retries=0))
-
-    def test_too_low_bandwidth_no_delays_failure(self):
-        kc = self.keepClient()
-        loc = kc.put(self.SMALL_DATA, copies=1, num_retries=0)
-        self.server.setbandwidth(self.BANDWIDTH_LOW_LIM-self.BANDWIDTH_DELTA)
-        # Check that lessening bandwidth corresponds to failing
-        with self.assertTakesGreater(self.TIMEOUT_TIME):
-            with self.assertRaises(arvados.errors.KeepReadError) as e:
-                kc.get(loc, num_retries=0)
-        with self.assertTakesGreater(self.TIMEOUT_TIME):
-            with self.assertRaises(arvados.errors.KeepWriteError):
-                kc.put(self.SMALL_DATA, copies=1, num_retries=0)
-
-    def test_low_bandwidth_with_server_response_delay_failure(self):
-        kc = self.keepClient()
-        loc = kc.put(self.SMALL_DATA, copies=1, num_retries=0)
-        self.server.setbandwidth(self.BANDWIDTH_LOW_LIM)
-        self.server.setdelays(response=self.TIMEOUT_DELTA)
-        with self.assertTakesGreater(self.TIMEOUT_TIME):
-            with self.assertRaises(arvados.errors.KeepReadError) as e:
-                kc.get(loc, num_retries=0)
-        with self.assertTakesGreater(self.TIMEOUT_TIME):
-            with self.assertRaises(arvados.errors.KeepWriteError):
-                kc.put(self.SMALL_DATA, copies=1, num_retries=0)
-
-    def test_low_bandwidth_with_server_mid_delay_failure(self):
-        kc = self.keepClient()
-        loc = kc.put(self.SMALL_DATA, copies=1, num_retries=0)
-        self.server.setbandwidth(self.BANDWIDTH_LOW_LIM)
-        self.server.setdelays(mid_write=self.TIMEOUT_DELTA, mid_read=self.TIMEOUT_DELTA)
-        with self.assertTakesGreater(self.TIMEOUT_TIME):
-            with self.assertRaises(arvados.errors.KeepReadError) as e:
-                kc.get(loc, num_retries=0)
-        with self.assertTakesGreater(self.TIMEOUT_TIME):
-            with self.assertRaises(arvados.errors.KeepWriteError):
-                kc.put(self.SMALL_DATA, copies=1, num_retries=0)
-
-    def test_med_bandwidth_with_distributed_delays_success(self):
-        safe_delay_time = self.TIMEOUT_TIME/2.0-self.TIMEOUT_DELTA
-        self.server.setbandwidth(2*self.BANDWIDTH_LOW_LIM)
-        self.server.setdelays(response=safe_delay_time,
-            mid_write=safe_delay_time, mid_read=safe_delay_time)
-        kc = self.keepClient()
-        loc = kc.put(self.MEDIUM_DATA, copies=1, num_retries=0)
-        self.assertEqual(self.MEDIUM_DATA, kc.get(loc, num_retries=0))
-
-    def test_med_bandwidth_with_delays_failure(self):
-        safe_delay_time = self.TIMEOUT_TIME/2.0 - self.TIMEOUT_DELTA
-        not_safe_delay_time = self.TIMEOUT_TIME/2.0 + self.TIMEOUT_DELTA
-        kc = self.keepClient()
-        loc = kc.put(self.MEDIUM_DATA, copies=1, num_retries=0)
-        self.server.setbandwidth(2*self.BANDWIDTH_LOW_LIM)
-        self.server.setdelays(response=safe_delay_time, mid_write=not_safe_delay_time, mid_read=not_safe_delay_time)
-        with self.assertTakesGreater(self.TIMEOUT_TIME):
-            with self.assertRaises(arvados.errors.KeepReadError) as e:
-                kc.get(loc, num_retries=0)
-        with self.assertTakesGreater(self.TIMEOUT_TIME):
-            with self.assertRaises(arvados.errors.KeepWriteError):
-                kc.put(self.MEDIUM_DATA, copies=1, num_retries=0)
-
-    def test_high_bandwidth_large_server_delay_failure(self):
-        kc = self.keepClient()
-        loc = kc.put(self.BIG_DATA, copies=1, num_retries=0)
-        self.server.setbandwidth(63*self.BANDWIDTH_LOW_LIM)
-        self.server.setdelays(response=self.TIMEOUT_TIME-2*self.TIMEOUT_DELTA)
-        with self.assertTakesGreater(self.TIMEOUT_TIME):
-            with self.assertRaises(arvados.errors.KeepReadError) as e:
-                kc.get(loc, num_retries=0)
-        with self.assertTakesGreater(self.TIMEOUT_TIME):
-            with self.assertRaises(arvados.errors.KeepWriteError):
-                kc.put(self.BIG_DATA, copies=1, num_retries=0)
-
-    def test_high_bandwidth_large_server_delay_success(self):
-        self.server.setbandwidth(65*self.BANDWIDTH_LOW_LIM)
-        kc = self.keepClient()
-        self.server.setdelays(response=self.TIMEOUT_TIME-2*self.TIMEOUT_DELTA)
-        loc = kc.put(self.BIG_DATA, copies=1, num_retries=0)
-        self.assertEqual(self.BIG_DATA, kc.get(loc, num_retries=0))
-
-    def test_high_bandwidth_server_delay_success(self):
-        self.server.setbandwidth(65*self.BANDWIDTH_LOW_LIM)
-        kc = self.keepClient()
-        self.server.setdelays(response=self.TIMEOUT_TIME-self.TIMEOUT_DELTA*2,
-                    mid_read=self.TIMEOUT_TIME-self.TIMEOUT_DELTA*2,
-                    mid_write=self.TIMEOUT_TIME-self.TIMEOUT_DELTA*2)
-        loc = kc.put(self.BIG_DATA, copies=1, num_retries=0)
-        self.assertEqual(self.BIG_DATA, kc.get(loc, num_retries=0))
-
-    def test_high_bandwidth_server_start_delay_failure(self):
-        #Check that if the response takes a little longer than expected,
-        # get and put fail
-        self.server.setbandwidth(65*self.BANDWIDTH_LOW_LIM)
-        kc = self.keepClient()
-        loc = kc.put(self.BIG_DATA, copies=1, num_retries=0)
-        self.server.setdelays(response=self.TIMEOUT_TIME+self.TIMEOUT_DELTA,
-                    mid_read=self.TIMEOUT_TIME-self.TIMEOUT_DELTA,
-                    mid_write=self.TIMEOUT_TIME-self.TIMEOUT_DELTA)
-        with self.assertTakesGreater(self.TIMEOUT_TIME):
-            with self.assertRaises(arvados.errors.KeepReadError) as e:
-                kc.get(loc, num_retries=0)
-        with self.assertTakesGreater(self.TIMEOUT_TIME):
-            with self.assertRaises(arvados.errors.KeepWriteError):
-                kc.put(self.BIG_DATA, copies=1, num_retries=0)
-
-    def test_high_bandwidth_server_mid_delay_failure(self):
-        #Check that if the server hiccups for too long, get and put fail
-        self.server.setbandwidth(65*self.BANDWIDTH_LOW_LIM)
-        kc = self.keepClient()
-        loc = kc.put(self.BIG_DATA, copies=1, num_retries=0)
-        self.server.setdelays(response=self.TIMEOUT_TIME-self.TIMEOUT_DELTA,
-                    mid_read=self.TIMEOUT_TIME+self.TIMEOUT_DELTA,
-                    mid_write=self.TIMEOUT_TIME+self.TIMEOUT_DELTA)
-        with self.assertTakesGreater(self.TIMEOUT_TIME):
-            with self.assertRaises(arvados.errors.KeepReadError) as e:
-                kc.get(loc, num_retries=0)
-        with self.assertTakesGreater(self.TIMEOUT_TIME):
-            with self.assertRaises(arvados.errors.KeepWriteError):
-                kc.put(self.BIG_DATA, copies=1, num_retries=0)
-
 class KeepClientTimeout(unittest.TestCase, tutil.ApiClientMock):
     DATA = 'x'*2**11
     BANDWIDTH_LOW_LIM = 1024
-    BANDWIDTH_DELTA = 128
+    BANDWIDTH_DELTA = 256
     TIMEOUT_TIME = 1.0
     #Needs to be low to trigger bandwidth errors before we run out of data
     TIMEOUT_DELTA = 0.5

commit 4b0f625c6cd105ee87d77e73545463bf9120ca0e
Author: sguthrie <sallyeguthrie at gmail.com>
Date:   Fri Nov 13 16:59:33 2015 -0500

    Skip long-running and intermittent successful tests. Write new ones running faster to check basic functionality

diff --git a/sdk/python/tests/keepstub.py b/sdk/python/tests/keepstub.py
index 3123922..1f7c436 100644
--- a/sdk/python/tests/keepstub.py
+++ b/sdk/python/tests/keepstub.py
@@ -39,7 +39,7 @@ class Server(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer, object):
 
     def setbandwidth(self, bandwidth):
         """For future requests, impose bandwidth limits."""
-        self.bandwidth = bandwidth*1024.0
+        self.bandwidth = float(bandwidth)
 
     def _sleep_at_least(self, seconds):
         """Sleep for given time, even if signals are received."""
@@ -50,17 +50,17 @@ class Server(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer, object):
             todo = wake - time.time()
 
     def _do_delay(self, k):
-        #if self.delays[k] > 0:
-        #    print "Delaying %f seconds for %s delay" % (self.delays[k], k)
+        if self.delays[k] > 0:
+            print "Delaying %f seconds for %s delay" % (self.delays[k], k)
         self._sleep_at_least(self.delays[k])
 
 
 class Handler(BaseHTTPServer.BaseHTTPRequestHandler, object):
     def wfile_bandwidth_write(self, data_to_write):
-        BYTES_PER_WRITE = 10
         if self.server.bandwidth == None and self.server.delays['mid_write'] == 0:
             self.wfile.write(data_to_write)
         else:
+            BYTES_PER_WRITE = int(self.server.bandwidth/4.0) or 32768
             outage_happened = False
             num_bytes = len(data_to_write)
             num_sent_bytes = 0
@@ -74,17 +74,17 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler, object):
                     wait = 0
                 else:
                     wait = num_write_bytes / self.server.bandwidth
-                #print "Bandwidth: %f KiB. Want to write total of %f bytes. Writing %f bytes now. Waiting %f seconds" % (self.server.bandwidth/1024.0, num_bytes, num_write_bytes, wait)
+                print "Bandwidth: %f b/s. Want to write total of %f bytes. Writing %f bytes now. Waiting %f seconds" % (self.server.bandwidth, num_bytes, num_write_bytes, wait)
                 self.server._sleep_at_least(wait)
                 self.wfile.write(data_to_write[num_sent_bytes:num_sent_bytes+num_write_bytes])
                 num_sent_bytes += num_write_bytes
         return None
 
     def rfile_bandwidth_read(self, bytes_to_read):
-        BYTES_PER_READ = 10
         if self.server.bandwidth == None and self.server.delays['mid_read'] == 0:
             return self.rfile.read(bytes_to_read)
         else:
+            BYTES_PER_READ = int(self.server.bandwidth/4.0) or 32768
             data = ''
             outage_happened = False
             bytes_read = 0
@@ -101,7 +101,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler, object):
                     wait = 0
                 else:
                     wait = next_bytes_to_read / self.server.bandwidth - time_spent_getting_data
-                #print "Bandwidth: %f KiB. Wanted total of %f bytes. Now reading %f bytes. Have read %f bytes. Waiting %f seconds" % (self.server.bandwidth/1024.0, bytes_to_read, next_bytes_to_read, len(data), wait)
+                print "Bandwidth: %f b/s. Wanted total of %f bytes. Now reading %f bytes. Have read %f bytes. Waiting %f seconds" % (self.server.bandwidth, bytes_to_read, next_bytes_to_read, len(data), wait)
                 if wait > 0:
                     self.server._sleep_at_least(wait)
                 bytes_read += next_bytes_to_read
diff --git a/sdk/python/tests/test_keep_client.py b/sdk/python/tests/test_keep_client.py
index 1ecb88d..43921ea 100644
--- a/sdk/python/tests/test_keep_client.py
+++ b/sdk/python/tests/test_keep_client.py
@@ -291,7 +291,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock):
                 int(arvados.KeepClient.DEFAULT_TIMEOUT[1]))
             self.assertEqual(
                 mock.responses[0].getopt(pycurl.LOW_SPEED_LIMIT),
-                int(arvados.KeepClient.DEFAULT_TIMEOUT[2]*1024))
+                int(arvados.KeepClient.DEFAULT_TIMEOUT[2]))
 
     def test_put_timeout(self):
         api_client = self.mock_keep_services(count=1)
@@ -308,7 +308,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock):
                 int(arvados.KeepClient.DEFAULT_TIMEOUT[1]))
             self.assertEqual(
                 mock.responses[0].getopt(pycurl.LOW_SPEED_LIMIT),
-                int(arvados.KeepClient.DEFAULT_TIMEOUT[2]*1024))
+                int(arvados.KeepClient.DEFAULT_TIMEOUT[2]))
 
     def test_proxy_get_timeout(self):
         api_client = self.mock_keep_services(service_type='proxy', count=1)
@@ -325,7 +325,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock):
                 int(arvados.KeepClient.DEFAULT_PROXY_TIMEOUT[1]))
             self.assertEqual(
                 mock.responses[0].getopt(pycurl.LOW_SPEED_LIMIT),
-                int(arvados.KeepClient.DEFAULT_PROXY_TIMEOUT[2]*1024))
+                int(arvados.KeepClient.DEFAULT_PROXY_TIMEOUT[2]))
 
     def test_proxy_put_timeout(self):
         api_client = self.mock_keep_services(service_type='proxy', count=1)
@@ -342,7 +342,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock):
                 int(arvados.KeepClient.DEFAULT_PROXY_TIMEOUT[1]))
             self.assertEqual(
                 mock.responses[0].getopt(pycurl.LOW_SPEED_LIMIT),
-                int(arvados.KeepClient.DEFAULT_PROXY_TIMEOUT[2]*1024))
+                int(arvados.KeepClient.DEFAULT_PROXY_TIMEOUT[2]))
 
     def check_no_services_error(self, verb, exc_class):
         api_client = mock.MagicMock(name='api_client')
@@ -550,8 +550,8 @@ class KeepClientRendezvousTestCase(unittest.TestCase, tutil.ApiClientMock):
     def test_put_error_shows_probe_order(self):
         self.check_64_zeros_error_order('put', arvados.errors.KeepWriteError)
 
-
-class KeepClientTimeout(unittest.TestCase, tutil.ApiClientMock):
+ at unittest.skip('Takes a long time')
+class KeepClientTimeoutTakesTime(unittest.TestCase, tutil.ApiClientMock):
     SMALL_DATA = 'x'*2**22
     MEDIUM_DATA = 'x'*2**22
     BIG_DATA = 'x' * 2**22
@@ -612,18 +612,6 @@ class KeepClientTimeout(unittest.TestCase, tutil.ApiClientMock):
             api_client=self.api_client,
             timeout=timeouts)
 
-    def test_timeout_slow_connect(self):
-        # Can't simulate TCP delays with our own socket. Leave our
-        # stub server running uselessly, and try to connect to an
-        # unroutable IP address instead.
-        self.api_client = self.mock_keep_services(
-            count=1,
-            service_host='240.0.0.0',
-        )
-        with self.assertTakesBetween(0.1, 0.5):
-            with self.assertRaises(arvados.errors.KeepWriteError):
-                self.keepClient().put(self.SMALL_DATA, copies=1, num_retries=0)
-
     def test_low_bandwidth_no_delays_success(self):
         self.server.setbandwidth(self.BANDWIDTH_LOW_LIM+self.BANDWIDTH_DELTA)
         kc = self.keepClient()
@@ -748,6 +736,114 @@ class KeepClientTimeout(unittest.TestCase, tutil.ApiClientMock):
             with self.assertRaises(arvados.errors.KeepWriteError):
                 kc.put(self.BIG_DATA, copies=1, num_retries=0)
 
+class KeepClientTimeout(unittest.TestCase, tutil.ApiClientMock):
+    DATA = 'x'*2**11
+    BANDWIDTH_LOW_LIM = 1024
+    BANDWIDTH_DELTA = 128
+    TIMEOUT_TIME = 1.0
+    #Needs to be low to trigger bandwidth errors before we run out of data
+    TIMEOUT_DELTA = 0.5
+    #This is a variable determined by trial-and-error which probably depends on
+    #  the implementation of keepstub.py
+    class assertTakesBetween(unittest.TestCase):
+        def __init__(self, tmin, tmax):
+            self.tmin = tmin
+            self.tmax = tmax
+
+        def __enter__(self):
+            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)
+
+    class assertTakesGreater(unittest.TestCase):
+        def __init__(self, tmin):
+            self.tmin = tmin
+
+        def __enter__(self):
+            self.t0 = time.time()
+
+        def __exit__(self, *args, **kwargs):
+            self.assertGreater(time.time() - self.t0, self.tmin)
+
+    def setUp(self):
+        sock = socket.socket()
+        sock.bind(('0.0.0.0', 0))
+        self.port = sock.getsockname()[1]
+        sock.close()
+        self.server = keepstub.Server(('0.0.0.0', self.port), keepstub.Handler)
+        self.thread = threading.Thread(target=self.server.serve_forever)
+        self.thread.daemon = True # Exit thread if main proc exits
+        self.thread.start()
+        self.api_client = self.mock_keep_services(
+            count=1,
+            service_host='localhost',
+            service_port=self.port,
+        )
+
+    def tearDown(self):
+        self.server.shutdown()
+
+    def keepClient(self, timeouts=(0.1, TIMEOUT_TIME, BANDWIDTH_LOW_LIM)):
+        return arvados.KeepClient(
+            api_client=self.api_client,
+            timeout=timeouts)
+
+    def test_timeout_slow_connect(self):
+        # Can't simulate TCP delays with our own socket. Leave our
+        # stub server running uselessly, and try to connect to an
+        # unroutable IP address instead.
+        self.api_client = self.mock_keep_services(
+            count=1,
+            service_host='240.0.0.0',
+        )
+        with self.assertTakesBetween(0.1, 0.5):
+            with self.assertRaises(arvados.errors.KeepWriteError):
+                self.keepClient().put(self.DATA, copies=1, num_retries=0)
+
+    def test_low_bandwidth_no_delays_success(self):
+        self.server.setbandwidth(self.BANDWIDTH_LOW_LIM+self.BANDWIDTH_DELTA)
+        kc = self.keepClient()
+        loc = kc.put(self.DATA, copies=1, num_retries=0)
+        self.assertEqual(self.DATA, kc.get(loc, num_retries=0))
+
+    def test_too_low_bandwidth_no_delays_failure(self):
+        kc = self.keepClient()
+        loc = kc.put(self.DATA, copies=1, num_retries=0)
+        self.server.setbandwidth(self.BANDWIDTH_LOW_LIM-self.BANDWIDTH_DELTA)
+        # Check that lessening bandwidth corresponds to failing
+        with self.assertTakesGreater(self.TIMEOUT_TIME):
+            with self.assertRaises(arvados.errors.KeepReadError) as e:
+                kc.get(loc, num_retries=0)
+        with self.assertTakesGreater(self.TIMEOUT_TIME):
+            with self.assertRaises(arvados.errors.KeepWriteError):
+                kc.put(self.DATA, copies=1, num_retries=0)
+
+    def test_low_bandwidth_with_server_response_delay_failure(self):
+        kc = self.keepClient()
+        loc = kc.put(self.DATA, copies=1, num_retries=0)
+        self.server.setbandwidth(self.BANDWIDTH_LOW_LIM)
+        self.server.setdelays(response=self.TIMEOUT_DELTA)
+        with self.assertTakesGreater(self.TIMEOUT_TIME):
+            with self.assertRaises(arvados.errors.KeepReadError) as e:
+                kc.get(loc, num_retries=0)
+        with self.assertTakesGreater(self.TIMEOUT_TIME):
+            with self.assertRaises(arvados.errors.KeepWriteError):
+                kc.put(self.DATA, copies=1, num_retries=0)
+
+    def test_low_bandwidth_with_server_mid_delay_failure(self):
+        kc = self.keepClient()
+        loc = kc.put(self.DATA, copies=1, num_retries=0)
+        self.server.setbandwidth(self.BANDWIDTH_LOW_LIM)
+        self.server.setdelays(mid_write=self.TIMEOUT_DELTA, mid_read=self.TIMEOUT_DELTA)
+        with self.assertTakesGreater(self.TIMEOUT_TIME):
+            with self.assertRaises(arvados.errors.KeepReadError) as e:
+                kc.get(loc, num_retries=0)
+        with self.assertTakesGreater(self.TIMEOUT_TIME):
+            with self.assertRaises(arvados.errors.KeepWriteError):
+                kc.put(self.DATA, copies=1, num_retries=0)
+
 class KeepClientGatewayTestCase(unittest.TestCase, tutil.ApiClientMock):
     def mock_disks_and_gateways(self, disks=3, gateways=1):
         self.gateways = [{

commit ca4ddecc445af64d4705f479eccb8f08b8cd6acc
Author: sguthrie <sallyeguthrie at gmail.com>
Date:   Fri Nov 13 16:58:53 2015 -0500

    User specifies bandwidth in terms of bytes, not KiB.

diff --git a/sdk/python/arvados/keep.py b/sdk/python/arvados/keep.py
index 78f8cf2..2e19f06 100644
--- a/sdk/python/arvados/keep.py
+++ b/sdk/python/arvados/keep.py
@@ -226,12 +226,12 @@ class KeepClient(object):
 
     # Default Keep server connection timeout:  2 seconds
     # Default Keep server read timeout:       64 seconds
-    # Default Keep server bandwidth minimum:  32 KiB per second
+    # Default Keep server bandwidth minimum:  32768 bytes per second
     # Default Keep proxy connection timeout:  20 seconds
     # Default Keep proxy read timeout:        64 seconds
-    # Default Keep proxy bandwidth minimum:   32 KiB per second
-    DEFAULT_TIMEOUT = (2, 64, 32)
-    DEFAULT_PROXY_TIMEOUT = (20, 64, 32)
+    # Default Keep proxy bandwidth minimum:   32768 bytes per second
+    DEFAULT_TIMEOUT = (2, 64, 32768)
+    DEFAULT_PROXY_TIMEOUT = (20, 64, 32768)
 
     class ThreadLimiter(object):
         """
@@ -498,7 +498,7 @@ class KeepClient(object):
                 bandwidth_kib_per_s = self.DEFAULT_TIMEOUT[2]
             curl.setopt(pycurl.CONNECTTIMEOUT_MS, int(conn_t*1000))
             curl.setopt(pycurl.LOW_SPEED_TIME, int(xfer_t))
-            curl.setopt(pycurl.LOW_SPEED_LIMIT, int(bandwidth_kib_per_s*1024))
+            curl.setopt(pycurl.LOW_SPEED_LIMIT, int(bandwidth_kib_per_s))
 
         def _headerfunction(self, header_line):
             header_line = header_line.decode('iso-8859-1')

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list