Permalink
Browse files

Merge "Document & reduce potential for race condition (bug 921634)" i…

…nto milestone-proposed
  • Loading branch information...
2 parents fbd1af7 + 8cc0d36 commit a733e4a7e5ede7670116001b4bc158e13f08fdd7 Jenkins committed with openstack-gerrit Jan 26, 2012
Showing with 20 additions and 5 deletions.
  1. +20 −5 keystone/test/unit/test_commands.py
View
25 keystone/test/unit/test_commands.py
@@ -818,8 +818,20 @@ def test_delete_service(self):
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,29 +841,31 @@ def test_create_unscoped_token(self):
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)
self.ob.clear()
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()
tenant_id = self._create_tenant()
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)
self.ob.clear()
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 @@ def test_create_specific_token_id(self):
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):

0 comments on commit a733e4a

Please sign in to comment.