Fix flaky tests

This commit is contained in:
Joseph Schorr 2016-06-09 15:04:55 -04:00
parent 496bc59e39
commit 4747dea395

View file

@ -314,6 +314,9 @@ class BaseRegistryMixin(object):
response = self.session.request(method, self.get_server_url() + url, headers=headers, data=data, response = self.session.request(method, self.get_server_url() + url, headers=headers, data=data,
auth=auth_tuple, params=params) auth=auth_tuple, params=params)
if expected_code is None:
return response
if response.status_code != expected_code: if response.status_code != expected_code:
print response.text print response.text
@ -1503,11 +1506,21 @@ class ACIConversionTests(RegistryTestCaseMixin, V1RegistryPushMixin, LiveServerT
return tar, response.content return tar, response.content
def get_converted_signature(self): def get_converted_signature(self):
# Give time for the signature to be written before continuing. counter = 0
time.sleep(2)
response = self.conduct('GET', '/c1/aci/localhost:5000/devtable/newrepo/latest/aci.asc/linux/amd64/', auth='sig') # Give time for the signature to be written before continuing. As we don't exactly know when
# this is (based on CPU conditions when the test is being run), we try a backoff and sleep
# approach.
while counter < 5:
response = self.conduct('GET', '/c1/aci/localhost:5000/devtable/newrepo/latest/aci.asc/linux/amd64/', auth='sig', expected_code=None)
if response.status_code == 202 or response.status_code == 404:
counter += 1
time.sleep(counter * 2)
else:
return response.content return response.content
self.fail('Signature was never created')
def _verify_signature(self, signature, converted): def _verify_signature(self, signature, converted):
sig_bytes = StringIO(signature) sig_bytes = StringIO(signature)
content_bytes = StringIO(converted) content_bytes = StringIO(converted)