MonkeyPatch time.sleep in unit tests to avoid wait
There's no need to wait real world seconds when there are no real world servers at the other end of these API calls. We still do wait a little bit of time, in case there is some reliance on actually having called the real time.sleep, but this should feed up test running in a loop quite a bit. Also lowering timeout on rebuild_server as it unnecessarily sleeps for 1 second. Change-Id: Ic26e90af12aedbedfbe0cc468332b921516a8409
This commit is contained in:
parent
4d1707e2c5
commit
0fd99acb5b
|
@ -25,7 +25,7 @@ _TRUE_VALUES = ('true', '1', 'yes')
|
|||
|
||||
class TestCase(testtools.TestCase):
|
||||
|
||||
"""Test case base class for all unit tests."""
|
||||
"""Test case base class for all tests."""
|
||||
|
||||
def setUp(self):
|
||||
"""Run before each test method to initialize test environment."""
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2010-2011 OpenStack Foundation
|
||||
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import time
|
||||
|
||||
import fixtures
|
||||
|
||||
from shade.tests import base
|
||||
|
||||
|
||||
class TestCase(base.TestCase):
|
||||
|
||||
"""Test case base class for all unit tests."""
|
||||
|
||||
def setUp(self):
|
||||
"""Run before each test method to initialize test environment."""
|
||||
|
||||
super(TestCase, self).setUp()
|
||||
|
||||
# Sleeps are for real testing, but unit tests shouldn't need them
|
||||
realsleep = time.sleep
|
||||
|
||||
def _nosleep(seconds):
|
||||
return realsleep(seconds * 0.0001)
|
||||
|
||||
self.sleep_fixture = self.useFixture(fixtures.MonkeyPatch(
|
||||
'time.sleep',
|
||||
_nosleep))
|
|
@ -18,7 +18,7 @@ import os_client_config as occ
|
|||
import yaml
|
||||
|
||||
import shade
|
||||
from shade.tests import base
|
||||
from shade.tests.unit import base
|
||||
|
||||
|
||||
class TestMemoryCache(base.TestCase):
|
||||
|
@ -26,7 +26,7 @@ class TestMemoryCache(base.TestCase):
|
|||
CACHING_CONFIG = {
|
||||
'cache':
|
||||
{
|
||||
'max_age': 10,
|
||||
'max_age': 90,
|
||||
'class': 'dogpile.cache.memory',
|
||||
},
|
||||
'clouds':
|
||||
|
|
|
@ -22,7 +22,7 @@ Tests for the `rebuild_server` command.
|
|||
from mock import patch, Mock
|
||||
from shade import (
|
||||
OpenStackCloud, OpenStackCloudException, OpenStackCloudTimeout)
|
||||
from shade.tests import base
|
||||
from shade.tests.unit import base
|
||||
|
||||
|
||||
class TestRebuildServer(base.TestCase):
|
||||
|
@ -72,7 +72,7 @@ class TestRebuildServer(base.TestCase):
|
|||
OpenStackCloud.nova_client = Mock(**config)
|
||||
self.assertRaises(
|
||||
OpenStackCloudTimeout,
|
||||
self.client.rebuild_server, "a", "b", wait=True, timeout=1)
|
||||
self.client.rebuild_server, "a", "b", wait=True, timeout=0.001)
|
||||
|
||||
def test_rebuild_server_no_wait(self):
|
||||
"""
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
import mock
|
||||
|
||||
import shade
|
||||
from shade.tests import base
|
||||
from shade.tests.unit import base
|
||||
|
||||
|
||||
class TestShade(base.TestCase):
|
||||
|
|
Loading…
Reference in New Issue