provide enough time to do expires in obj tests

When testing object expiration there are a lot of factors in
play, including the amount of time that rest calls take between
when we set the expiration, and when we eventually want to check.
If the time in the future is too close then our GET calls have
a real chance of 404ing because the object is gone.

So we should provide more slack to begin with (10 seconds) and
then a variable sleep time at the end to check objects 3 seconds
after they should have expired.

Closes-Bug: #1304119

Change-Id: I890bdbc14c926ba07f43d60ef5544ff37069d5df
This commit is contained in:
Sean Dague 2014-06-23 16:19:22 -04:00
parent acee202b28
commit 53ce5ae4d6
1 changed files with 10 additions and 4 deletions

View File

@ -54,14 +54,18 @@ class ObjectExpiryTest(base.BaseObjectTest):
self.assertEqual(resp['status'], '200')
self.assertHeaders(resp, 'Object', 'HEAD')
self.assertIn('x-delete-at', resp)
# we want to ensure that we will sleep long enough for things to
# actually expire, so figure out how many secs in the future that is.
sleepy_time = int(resp['x-delete-at']) - int(time.time())
resp, body = self.object_client.get_object(self.container_name,
self.object_name)
self.assertEqual(resp['status'], '200')
self.assertHeaders(resp, 'Object', 'GET')
self.assertIn('x-delete-at', resp)
# sleep for over 5 seconds, so that object expires
time.sleep(5)
# add a couple of seconds for safety.
time.sleep(sleepy_time + 3)
# object should not be there anymore
self.assertRaises(exceptions.NotFound, self.object_client.get_object,
@ -69,10 +73,12 @@ class ObjectExpiryTest(base.BaseObjectTest):
@test.attr(type='gate')
def test_get_object_after_expiry_time(self):
metadata = {'X-Delete-After': '3'}
# the 10s is important, because the get calls can take 3s each
# some times
metadata = {'X-Delete-After': '10'}
self._test_object_expiry(metadata)
@test.attr(type='gate')
def test_get_object_at_expiry_time(self):
metadata = {'X-Delete-At': str(int(time.time()) + 3)}
metadata = {'X-Delete-At': str(int(time.time()) + 10)}
self._test_object_expiry(metadata)