From 20072570d9a58416fbd30a71cf0719c1db3bb686 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Wed, 26 Apr 2017 15:50:59 -0700 Subject: [PATCH] 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 --- test/unit/__init__.py | 5 +++-- test/unit/obj/test_server.py | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/test/unit/__init__.py b/test/unit/__init__.py index c54e77a3ef..16829bbb60 100644 --- a/test/unit/__init__.py +++ b/test/unit/__init__.py @@ -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): diff --git a/test/unit/obj/test_server.py b/test/unit/obj/test_server.py index 7e41d806f2..ecc767e0cd 100644 --- a/test/unit/obj/test_server.py +++ b/test/unit/obj/test_server.py @@ -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))