diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-01-26 00:16:33 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2012-01-26 00:16:33 +0000 |
commit | a733e4a7e5ede7670116001b4bc158e13f08fdd7 (patch) | |
tree | 176b9df889ebb6f68953d56b8b19439fbf9f4704 | |
parent | fbd1af73eb8dfff646326e698c28e5045519b9be (diff) | |
parent | 8cc0d3647a69912ebe5917314f5b0dfe62a733af (diff) | |
download | keystone-a733e4a7e5ede7670116001b4bc158e13f08fdd7.tar.gz |
Merge "Document & reduce potential for race condition (bug 921634)" into milestone-proposedessex-3
-rw-r--r-- | keystone/test/unit/test_commands.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/keystone/test/unit/test_commands.py b/keystone/test/unit/test_commands.py index 9a8060d21..2c498116b 100644 --- a/keystone/test/unit/test_commands.py +++ b/keystone/test/unit/test_commands.py @@ -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): |