Browse Source

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
tags/1.34.0
Eric Fried 7 months ago
parent
commit
d9855f0ec4
1 changed files with 5 additions and 0 deletions
  1. 5
    0
      oslo_service/tests/test_loopingcall.py

+ 5
- 0
oslo_service/tests/test_loopingcall.py View File

@@ -18,6 +18,7 @@ import mock
18 18
 from oslotest import base as test_base
19 19
 
20 20
 import oslo_service
21
+from oslo_service import fixture
21 22
 from oslo_service import loopingcall
22 23
 
23 24
 
@@ -72,6 +73,7 @@ class LoopingCallTestCase(test_base.BaseTestCase):
72 73
             raise RuntimeError()
73 74
 
74 75
     def test_do_not_stop_on_exception(self):
76
+        self.useFixture(fixture.SleepFixture())
75 77
         self.num_runs = 2
76 78
 
77 79
         timer = loopingcall.FixedIntervalLoopingCall(self._raise_and_then_done)
@@ -111,6 +113,7 @@ class LoopingCallTestCase(test_base.BaseTestCase):
111 113
         timer.stop()
112 114
 
113 115
     def test_repeat(self):
116
+        self.useFixture(fixture.SleepFixture())
114 117
         self.num_runs = 2
115 118
 
116 119
         timer = loopingcall.FixedIntervalLoopingCall(self._wait_for_zero)
@@ -218,6 +221,7 @@ class DynamicLoopingCallTestCase(test_base.BaseTestCase):
218 221
             raise RuntimeError()
219 222
 
220 223
     def test_do_not_stop_on_exception(self):
224
+        self.useFixture(fixture.SleepFixture())
221 225
         self.num_runs = 2
222 226
 
223 227
         timer = loopingcall.DynamicLoopingCall(self._raise_and_then_done)
@@ -233,6 +237,7 @@ class DynamicLoopingCallTestCase(test_base.BaseTestCase):
233 237
             return sleep_for
234 238
 
235 239
     def test_repeat(self):
240
+        self.useFixture(fixture.SleepFixture())
236 241
         self.num_runs = 2
237 242
 
238 243
         timer = loopingcall.DynamicLoopingCall(self._wait_for_zero)

Loading…
Cancel
Save