From 2ce5fee0d6cc3244db11670379fd7938119919ed Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Wed, 12 Dec 2012 19:25:50 -0800 Subject: Remove sleep in test_consoleauth. test_consoleauth:ConsoleauthTestCase.test_tokens_expire called time.sleep(1.1) in order to test that tokens with a TTL of 1 second expire after one second. Problem is time.sleep() may return before the entire sleep period is complete. Remove the sleep and instead use Oslo's timeutils to override the time and advance it by one second to check that expired tokens do expire. Part of blueprint grizzly-testtools Change-Id: Iae0e678fb12a76757523dc7dbccb4da98cef85e6 --- nova/tests/consoleauth/test_consoleauth.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'nova') diff --git a/nova/tests/consoleauth/test_consoleauth.py b/nova/tests/consoleauth/test_consoleauth.py index 9c6368b4c..1490028ca 100644 --- a/nova/tests/consoleauth/test_consoleauth.py +++ b/nova/tests/consoleauth/test_consoleauth.py @@ -20,16 +20,27 @@ Tests for Consoleauth Code. """ +import fixtures import time from nova.consoleauth import manager from nova import context from nova.openstack.common import log as logging +from nova.openstack.common import timeutils from nova import test LOG = logging.getLogger(__name__) +class TimeOverride(fixtures.Fixture): + """Fixture to start and remove time override.""" + + def setUp(self): + super(TimeOverride, self).setUp() + timeutils.set_time_override() + self.addCleanup(timeutils.clear_time_override) + + class ConsoleauthTestCase(test.TestCase): """Test Case for consoleauth.""" @@ -40,10 +51,11 @@ class ConsoleauthTestCase(test.TestCase): def test_tokens_expire(self): """Test that tokens expire correctly.""" + self.useFixture(TimeOverride()) token = 'mytok' self.flags(console_token_ttl=1) self.manager.authorize_console(self.context, token, 'novnc', '127.0.0.1', 'host', '') self.assertTrue(self.manager.check_token(self.context, token)) - time.sleep(1.1) + timeutils.advance_time_seconds(1) self.assertFalse(self.manager.check_token(self.context, token)) -- cgit