[ARVADOS] created: 3068c6202ba52547f4a5f8c685f47a65e695633d
git at public.curoverse.com
git at public.curoverse.com
Thu Feb 12 19:03:13 EST 2015
at 3068c6202ba52547f4a5f8c685f47a65e695633d (commit)
commit 3068c6202ba52547f4a5f8c685f47a65e695633d
Author: Tom Clegg <tom at curoverse.com>
Date: Thu Feb 12 19:04:01 2015 -0500
5011: Fix unreliable test.
The collection writer was (sometimes) consuming the last 200 response
even though it could write 3 copies without it. This shouldn't fail
the test: the only reason we count the PUT calls is to verify all
three of the 200 responses were consumed (i.e., none of the 500
responses were counted toward the achieved replication level). To
verify this without being sensitive to extra requests, we simply
arrange for the three 200 responses to be the last ones available.
diff --git a/sdk/python/tests/test_collections.py b/sdk/python/tests/test_collections.py
index 4ca8dfe..dbbe3f5 100644
--- a/sdk/python/tests/test_collections.py
+++ b/sdk/python/tests/test_collections.py
@@ -720,10 +720,10 @@ class CollectionWriterTestCase(unittest.TestCase, CollectionTestMixin):
self.mock_keep_services(client, status=200, service_type='disk', count=6)
writer = self.foo_writer(api_client=client, replication=3)
with self.mock_keep(
- None, 200, 500, 200, 500, 200, 200,
+ None, 500, 500, 500, 200, 200, 200,
**{'x-keep-replicas-stored': 1}) as keepmock:
writer.manifest_text()
- self.assertEqual(5, keepmock.call_count)
+ self.assertEqual(6, keepmock.call_count)
def test_write_whole_collection_through_retries(self):
writer = self.foo_writer(num_retries=2)
commit aad2a35331e1290d4ba493d9a537a498474caba7
Author: Tom Clegg <tom at curoverse.com>
Date: Thu Feb 12 18:56:02 2015 -0500
5011: Use a threadsafe_iter wrapper to feed side effects to mocks.
diff --git a/sdk/python/tests/arvados_testutil.py b/sdk/python/tests/arvados_testutil.py
index 124fb35..a7e9ce8 100644
--- a/sdk/python/tests/arvados_testutil.py
+++ b/sdk/python/tests/arvados_testutil.py
@@ -11,6 +11,7 @@ import os
import requests
import shutil
import tempfile
+import threading
import unittest
# Use this hostname when you want to make sure the traffic will be
@@ -19,6 +20,20 @@ TEST_HOST = '100::'
skip_sleep = mock.patch('time.sleep', lambda n: None) # clown'll eat me
+class threadsafe_iter:
+ """A threadsafe iterator that wraps a threadunsafe iterator/generator."""
+ def __init__(self, generator):
+ self._generator = generator
+ self._lock = threading.Lock()
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ with self._lock:
+ return self._generator.next()
+
+
# fake_httplib2_response and mock_responses
# mock calls to httplib2.Http.request()
def fake_httplib2_response(code, **headers):
@@ -27,8 +42,8 @@ def fake_httplib2_response(code, **headers):
return httplib2.Response(headers)
def mock_responses(body, *codes, **headers):
- return mock.patch('httplib2.Http.request', side_effect=(
- (fake_httplib2_response(code, **headers), body) for code in codes))
+ return mock.patch('httplib2.Http.request', side_effect=threadsafe_iter((
+ (fake_httplib2_response(code, **headers), body) for code in codes)))
# fake_requests_response, mock_get_responses and mock_put_responses
# mock calls to requests.get() and requests.put()
@@ -41,16 +56,16 @@ def fake_requests_response(code, body, **headers):
return r
def mock_get_responses(body, *codes, **headers):
- return mock.patch('requests.get', side_effect=(
- fake_requests_response(code, body, **headers) for code in codes))
+ return mock.patch('requests.get', side_effect=threadsafe_iter((
+ fake_requests_response(code, body, **headers) for code in codes)))
def mock_put_responses(body, *codes, **headers):
- return mock.patch('requests.put', side_effect=(
- fake_requests_response(code, body, **headers) for code in codes))
+ return mock.patch('requests.put', side_effect=threadsafe_iter((
+ fake_requests_response(code, body, **headers) for code in codes)))
def mock_requestslib_responses(method, body, *codes, **headers):
- return mock.patch(method, side_effect=(
- fake_requests_response(code, body, **headers) for code in codes))
+ return mock.patch(method, side_effect=threadsafe_iter((
+ fake_requests_response(code, body, **headers) for code in codes)))
class MockStreamReader(object):
def __init__(self, name='.', *data):
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list