Fix sporadic failure in test/unit/obj/test_server.py

In particular, in TestObjectController.test_object_delete_at_async_update

Rarely (<0.1% of the time?), it would fail with:

======================================================================
FAIL: test_object_delete_at_async_update
(test.unit.obj.test_server.TestObjectController)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/vagrant/swift/test/unit/obj/test_server.py", line 4826, in
test_object_delete_at_async_update
    resp = req.get_response(self.object_controller)
  File "/usr/lib/python2.7/contextlib.py", line 24, in __exit__
    self.gen.next()
  File "/vagrant/swift/test/unit/__init__.py", line 1075, in
mocked_http_conn
    raise AssertionError('left over status %r' % left_over_status)
AssertionError: left over status [500, 500]
-------------------- >> begin captured stdout << ---------------------
test INFO: None - - [26/Apr/2017:22:32:13 +0000] "PUT /sda1/p/a/c/o" 400
19 "-" "-" "-" 0.0003 "-" 23801 0

--------------------- >> end captured stdout << ----------------------
>>  raise AssertionError('left over status %r' % [500, 500])

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

Related-Bug: 1514111
Change-Id: I1af4a291fb67cf4b1829f167998a08644117a800
This commit is contained in:
Tim Burke 2017-04-26 15:50:59 -07:00
parent 408500320b
commit 20072570d9
2 changed files with 7 additions and 2 deletions

View File

@ -1075,8 +1075,9 @@ def mocked_http_conn(*args, **kwargs):
raise AssertionError('left over status %r' % left_over_status)
def make_timestamp_iter():
return iter(Timestamp(t) for t in itertools.count(int(time.time())))
def make_timestamp_iter(offset=0):
return iter(Timestamp(t)
for t in itertools.count(int(time.time()) + offset))
class Timeout(object):

View File

@ -4797,6 +4797,9 @@ class TestObjectController(unittest.TestCase):
def capture_updates(ip, port, method, path, headers, *args, **kwargs):
container_updates.append((ip, port, method, path, headers))
# put everything in the future; otherwise setting X-Delete-At may fail
self.ts = make_timestamp_iter(10)
put_timestamp = next(self.ts).internal
delete_at_timestamp = utils.normalize_delete_at_timestamp(
next(self.ts).normal)
@ -4824,6 +4827,7 @@ class TestObjectController(unittest.TestCase):
500, 500, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
self.assertEqual(201, resp.status_int, resp.body)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
self.assertEqual(2, len(container_updates))