Merge "Document & reduce potential for race condition (bug 921634)" into milestone-proposed

This commit is contained in:
Jenkins 2012-01-26 00:16:33 +00:00 committed by Gerrit Code Review
commit a733e4a7e5
1 changed files with 20 additions and 5 deletions

View File

@ -818,8 +818,20 @@ class TestDeleteServiceCommand(CommandTestCase):
class TestCreateTokenCommand(CommandTestCase):
tomorrow = (datetime.datetime.utcnow() +
datetime.timedelta(days=1)).strftime('%Y-%m-%dT%H:%M')
"""Creates tokens and validates their attributes.
This class has a known potential race condition, due to the expected
token expiration being 24 hours after token creation. If the
'create_token' command runs immediately before the minute rolls over,
and the test class produces a timestamp for the subsequent minute, the
test will fail.
"""
@staticmethod
def _get_tomorrow_str():
return (datetime.datetime.utcnow() +
datetime.timedelta(days=1)).strftime('%Y-%m-%dT%H:%M')
def test_no_args(self):
with self.assertRaises(SystemExit):
@ -829,6 +841,7 @@ class TestCreateTokenCommand(CommandTestCase):
user_id = self._create_user()
self.run_cmd(create_token, [
'--user-id', user_id])
tomorrow = TestCreateTokenCommand._get_tomorrow_str()
token_id = self.ob.read_lines()[0]
self.assertEqual(len(token_id), 32)
@ -836,7 +849,7 @@ class TestCreateTokenCommand(CommandTestCase):
self.run_cmd(list_tokens)
self.assertTableContainsRow(self.ob.read(), [token_id, user_id,
str(None), self.tomorrow])
str(None), tomorrow])
def test_create_scoped_token(self):
user_id = self._create_user()
@ -844,6 +857,7 @@ class TestCreateTokenCommand(CommandTestCase):
self.run_cmd(create_token, [
'--user-id', user_id,
'--tenant-id', tenant_id])
tomorrow = TestCreateTokenCommand._get_tomorrow_str()
token_id = self.ob.read_lines()[0]
self.assertEqual(len(token_id), 32)
@ -851,7 +865,7 @@ class TestCreateTokenCommand(CommandTestCase):
self.run_cmd(list_tokens)
self.assertTableContainsRow(self.ob.read(), [token_id, user_id,
tenant_id, self.tomorrow])
tenant_id, tomorrow])
def test_create_expired_token(self):
user_id = self._create_user()
@ -874,13 +888,14 @@ class TestCreateTokenCommand(CommandTestCase):
self.run_cmd(create_token, [
'--id', token_id,
'--user-id', user_id])
tomorrow = TestCreateTokenCommand._get_tomorrow_str()
self.assertEqual(token_id, self.ob.read_lines()[0])
self.ob.clear()
self.run_cmd(list_tokens)
self.assertTableContainsRow(self.ob.read(), [token_id, user_id,
str(None), self.tomorrow])
str(None), tomorrow])
class TestUpdateTokenCommand(CommandTestCase):