Fix flakey test_check_delete_headers_sets_delete_at

It was rare (saw it once in 10k runs running locally), but it's
ocassionally blown up in the gate [1]. With this, no fails locally even
after 100k runs.

[1] http://logs.openstack.org/11/538011/3/gate/swift-tox-py27/06c06f0/job-output.txt.gz#_2018-02-07_03_29_09_578389

Change-Id: I7701d2db2ec82b48559c5b74a2e08c4403fd5dec
Related-Change: Ia126ad6988f387bbd2d1f5ddff0a56d457a1fc9b
This commit is contained in:
Tim Burke 2018-02-07 05:50:12 +00:00
parent 174cef641d
commit 5b30c1f811

View File

@ -360,13 +360,13 @@ class TestConstraints(unittest.TestCase):
self.assertEqual(req.headers['X-Delete-At'], str(int(ts) + 42))
def test_check_delete_headers_sets_delete_at(self):
t = time.time()
expected = str(int(t) + 1000)
ts = utils.Timestamp.now()
expected = str(int(ts) + 1000)
# check delete-at is passed through
headers = {'Content-Length': '0',
'Content-Type': 'text/plain',
'X-Delete-At': expected,
'X-Timestamp': str(t)}
'X-Timestamp': ts.internal}
req = Request.blank('/', headers=headers)
constraints.check_delete_headers(req)
self.assertIn('X-Delete-At', req.headers)
@ -376,19 +376,19 @@ class TestConstraints(unittest.TestCase):
headers = {'Content-Length': '0',
'Content-Type': 'text/plain',
'X-Delete-After': '42',
'X-Timestamp': str(t)}
'X-Timestamp': ts.internal}
req = Request.blank('/', headers=headers)
constraints.check_delete_headers(req)
self.assertIn('X-Delete-At', req.headers)
expected = str(int(t) + 42)
expected = str(int(ts) + 42)
self.assertEqual(req.headers['X-Delete-At'], expected)
# check delete-after takes precedence over delete-at
headers = {'Content-Length': '0',
'Content-Type': 'text/plain',
'X-Delete-After': '42',
'X-Delete-At': str(int(t) + 40),
'X-Timestamp': str(t)}
'X-Delete-At': str(int(ts) + 40),
'X-Timestamp': ts.internal}
req = Request.blank('/', headers=headers)
constraints.check_delete_headers(req)
self.assertIn('X-Delete-At', req.headers)
@ -397,8 +397,8 @@ class TestConstraints(unittest.TestCase):
headers = {'Content-Length': '0',
'Content-Type': 'text/plain',
'X-Delete-After': '42',
'X-Delete-At': str(int(t) + 44),
'X-Timestamp': str(t)}
'X-Delete-At': str(int(ts) + 44),
'X-Timestamp': ts.internal}
req = Request.blank('/', headers=headers)
constraints.check_delete_headers(req)
self.assertIn('X-Delete-At', req.headers)