Use SleepFixture in looping call test suite

A recent change [1] created a SleepFixture tailored for consumers of the
loopingcall module to be able to avoid incurring real sleeps while
testing. This patch makes use of the fixture in a couple of
previously-long-running tests in test_loopingcall.

NB: We carefully use the fixture only in specific test cases rather than
over the entire test class because tests in this module may (now and in
the future) be testing things below the mock.

=======
BEFORE:
=======
======
Totals
======
Ran: 31 tests in 13.0000 sec.
 - Passed: 31
 - Skipped: 0
 - Expected Fail: 0
 - Unexpected Success: 0
 - Failed: 0
Sum of execute time for each test: 14.4619 sec.

==============
Worker Balance
==============
 - Worker 0 (1 tests) => 0:00:00.306611
 - Worker 1 (1 tests) => 0:00:00.036168
 - Worker 2 (1 tests) => 0:00:00.029992
 - Worker 3 (4 tests) => 0:00:00.007588
 - Worker 4 (5 tests) => 0:00:00.019243
 - Worker 5 (6 tests) => 0:00:00.017683
 - Worker 6 (7 tests) => 0:00:12.036425
 - Worker 7 (6 tests) => 0:00:02.019783
Test id                                                                                          Runtime (s)
-----------------------------------------------------------------------------------------------  -----------
oslo_service.tests.test_loopingcall.DynamicLoopingCallTestCase.test_repeat                       12.019
oslo_service.tests.test_loopingcall.LoopingCallTestCase.test_do_not_stop_on_exception             1.005
oslo_service.tests.test_loopingcall.LoopingCallTestCase.test_repeat                               1.004
oslo_service.tests.test_loopingcall.LoopingCallTestCase.test_looping_call_timed_out               0.307
oslo_service.tests.test_loopingcall.RetryDecoratorTest.test_retry_with_expected_exceptions        0.036
oslo_service.tests.test_loopingcall.LoopingCallTestCase.test_interval_adjustment                  0.030
oslo_service.tests.test_loopingcall.DynamicLoopingCallTestCase.test_do_not_stop_on_exception      0.007
oslo_service.tests.test_loopingcall.TestBackOffLoopingCall.test_exponential_backoff               0.005
oslo_service.tests.test_loopingcall.DynamicLoopingCallTestCase.test_no_double_start               0.005
oslo_service.tests.test_loopingcall.DynamicLoopingCallTestCase.test_timeout_task_without_return   0.005
_____________________________________________________________________ summary _____________________________________________________________________

======
AFTER:
======
======
Totals
======
Ran: 31 tests in 1.0000 sec.
 - Passed: 31
 - Skipped: 0
 - Expected Fail: 0
 - Unexpected Success: 0
 - Failed: 0
Sum of execute time for each test: 0.4553 sec.

==============
Worker Balance
==============
 - Worker 0 (1 tests) => 0:00:00.005381
 - Worker 1 (1 tests) => 0:00:00.006639
 - Worker 2 (1 tests) => 0:00:00.005145
 - Worker 3 (1 tests) => 0:00:00.308991
 - Worker 4 (1 tests) => 0:00:00.037721
 - Worker 5 (2 tests) => 0:00:00.031293
 - Worker 6 (12 tests) => 0:00:00.034781
 - Worker 7 (12 tests) => 0:00:00.031908
Test id                                                                                             Runtime (s)
--------------------------------------------------------------------------------------------------  -----------
oslo_service.tests.test_loopingcall.LoopingCallTestCase.test_looping_call_timed_out                 0.309
oslo_service.tests.test_loopingcall.RetryDecoratorTest.test_retry_with_expected_exceptions          0.038
oslo_service.tests.test_loopingcall.LoopingCallTestCase.test_interval_adjustment                    0.028
oslo_service.tests.test_loopingcall.DynamicLoopingCallTestCase.test_initial_delay                   0.013
oslo_service.tests.test_loopingcall.LoopingCallTestCase.test_do_not_stop_on_exception               0.007
oslo_service.tests.test_loopingcall.DynamicLoopingCallTestCase.test_do_not_stop_on_exception        0.007
oslo_service.tests.test_loopingcall.DynamicLoopingCallTestCase.test_repeat                          0.005
oslo_service.tests.test_loopingcall.TestBackOffLoopingCall.test_exponential_backoff_negative_value  0.005
oslo_service.tests.test_loopingcall.LoopingCallTestCase.test_repeat                                 0.005
oslo_service.tests.test_loopingcall.RetryDecoratorTest.test_retry_with_max_retries                  0.004
_____________________________________________________________________ summary _____________________________________________________________________

[1] I0089c7778957456db66599abffaaad3a5332243c

Change-Id: I7035abef8d089c9d4cf664daee0af0fde5a6e19c
This commit is contained in:
Eric Fried 2018-11-07 17:12:57 -06:00
parent b85d9353fb
commit d9855f0ec4
1 changed files with 5 additions and 0 deletions

View File

@ -18,6 +18,7 @@ import mock
from oslotest import base as test_base
import oslo_service
from oslo_service import fixture
from oslo_service import loopingcall
@ -72,6 +73,7 @@ class LoopingCallTestCase(test_base.BaseTestCase):
raise RuntimeError()
def test_do_not_stop_on_exception(self):
self.useFixture(fixture.SleepFixture())
self.num_runs = 2
timer = loopingcall.FixedIntervalLoopingCall(self._raise_and_then_done)
@ -111,6 +113,7 @@ class LoopingCallTestCase(test_base.BaseTestCase):
timer.stop()
def test_repeat(self):
self.useFixture(fixture.SleepFixture())
self.num_runs = 2
timer = loopingcall.FixedIntervalLoopingCall(self._wait_for_zero)
@ -218,6 +221,7 @@ class DynamicLoopingCallTestCase(test_base.BaseTestCase):
raise RuntimeError()
def test_do_not_stop_on_exception(self):
self.useFixture(fixture.SleepFixture())
self.num_runs = 2
timer = loopingcall.DynamicLoopingCall(self._raise_and_then_done)
@ -233,6 +237,7 @@ class DynamicLoopingCallTestCase(test_base.BaseTestCase):
return sleep_for
def test_repeat(self):
self.useFixture(fixture.SleepFixture())
self.num_runs = 2
timer = loopingcall.DynamicLoopingCall(self._wait_for_zero)