Make failures in the periodic tests more detailed.

The current tests are very opaque when something fails. This change makes the
failure easier to understand without a debugger. The testtools version is
bumped to get a new HasLength matcher.

Change-Id: Iceafa70f88a8cc31a1b0ba912fe32a9fef1b2f18
This commit is contained in:
Robert Collins 2013-01-22 11:53:38 +13:00
parent a1c1e1bac1
commit 65f9d214d0
2 changed files with 11 additions and 9 deletions

View File

@ -15,9 +15,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import time
import fixtures
import time
from testtools import matchers
from nova import manager
from nova import test
@ -44,10 +45,11 @@ class ManagerMetaTestCase(test.TestCase):
return 'baz'
m = Manager()
self.assertEqual(2, len(m._periodic_tasks))
self.assertThat(m._periodic_tasks, matchers.HasLength(2))
self.assertEqual(None, m._periodic_spacing['foo'])
self.assertEqual(4, m._periodic_spacing['bar'])
self.assertFalse('baz' in m._periodic_spacing)
self.assertThat(
m._periodic_spacing, matchers.Not(matchers.Contains('baz')))
class Manager(test.TestCase):
@ -60,7 +62,7 @@ class Manager(test.TestCase):
return 'bar'
m = Manager()
self.assertEqual(1, len(m._periodic_tasks))
self.assertThat(m._periodic_tasks, matchers.HasLength(1))
self.assertEqual(200, m._periodic_spacing['bar'])
# Now a single pass of the periodic tasks
@ -87,8 +89,8 @@ class Manager(test.TestCase):
m.periodic_tasks(None)
time.sleep(0.1)
idle = m.periodic_tasks(None)
self.assertTrue(idle > 9.7)
self.assertTrue(idle < 9.9)
self.assertThat(idle, matchers.GreaterThan(9.7))
self.assertThat(idle, matchers.LessThan(9.9))
def test_periodic_tasks_disabled(self):
class Manager(manager.Manager):
@ -109,7 +111,7 @@ class Manager(test.TestCase):
return 'bar'
m = Manager()
self.assertEqual(1, len(m._periodic_tasks))
self.assertThat(m._periodic_tasks, matchers.HasLength(1))
def test_external_running_elsewhere(self):
self.flags(run_external_periodic_tasks=False)
@ -120,4 +122,4 @@ class Manager(test.TestCase):
return 'bar'
m = Manager()
self.assertEqual(0, len(m._periodic_tasks))
self.assertEqual([], m._periodic_tasks)

View File

@ -12,4 +12,4 @@ pylint==0.25.2
python-subunit
sphinx>=1.1.2
testrepository>=0.0.13
testtools>=0.9.26
testtools>=0.9.27