diff options
| author | Joshua Harlow <harlowja@gmail.com> | 2014-12-27 07:12:08 -0800 |
|---|---|---|
| committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2015-01-27 10:14:40 -0800 |
| commit | 80888c638cc4170ab83d168741743532e2bb5d9f (patch) | |
| tree | d33289756ca6e1659847ef84832034abfd61f51b /taskflow/tests/unit/worker_based | |
| parent | 0ef07e2901fa7a9c415dcf326c180840b6612ef7 (diff) | |
| download | taskflow-80888c638cc4170ab83d168741743532e2bb5d9f.tar.gz | |
Use monotonic time when/if available
Instead of using a time that can change depending on ntpd
or other time adjustments use a monotonically increasing
time if it's available from the underlying python library
to avoid these types of time-shifts problems in the first
place.
Change-Id: Ib775a44026b9828536c905a1ed41f527358c0d39
Diffstat (limited to 'taskflow/tests/unit/worker_based')
| -rw-r--r-- | taskflow/tests/unit/worker_based/test_protocol.py | 12 | ||||
| -rw-r--r-- | taskflow/tests/unit/worker_based/test_types.py | 14 |
2 files changed, 11 insertions, 15 deletions
diff --git a/taskflow/tests/unit/worker_based/test_protocol.py b/taskflow/tests/unit/worker_based/test_protocol.py index e5da38f..5436df3 100644 --- a/taskflow/tests/unit/worker_based/test_protocol.py +++ b/taskflow/tests/unit/worker_based/test_protocol.py @@ -15,7 +15,6 @@ # under the License. from concurrent import futures -from oslo_utils import timeutils from oslo_utils import uuidutils from taskflow.engines.action_engine import executor @@ -24,6 +23,7 @@ from taskflow import exceptions as excp from taskflow import test from taskflow.tests import utils from taskflow.types import failure +from taskflow.types import timing class TestProtocolValidation(test.TestCase): @@ -94,8 +94,8 @@ class TestProtocol(test.TestCase): def setUp(self): super(TestProtocol, self).setUp() - timeutils.set_time_override() - self.addCleanup(timeutils.clear_time_override) + timing.StopWatch.set_now_override() + self.addCleanup(timing.StopWatch.clear_overrides) self.task = utils.DummyTask() self.task_uuid = 'task-uuid' self.task_action = 'execute' @@ -166,19 +166,19 @@ class TestProtocol(test.TestCase): def test_pending_not_expired(self): req = self.request() - timeutils.advance_time_seconds(self.timeout - 1) + timing.StopWatch.set_offset_override(self.timeout - 1) self.assertFalse(req.expired) def test_pending_expired(self): req = self.request() - timeutils.advance_time_seconds(self.timeout + 1) + timing.StopWatch.set_offset_override(self.timeout + 1) self.assertTrue(req.expired) def test_running_not_expired(self): request = self.request() request.transition(pr.PENDING) request.transition(pr.RUNNING) - timeutils.advance_time_seconds(self.timeout + 1) + timing.StopWatch.set_offset_override(self.timeout + 1) self.assertFalse(request.expired) def test_set_result(self): diff --git a/taskflow/tests/unit/worker_based/test_types.py b/taskflow/tests/unit/worker_based/test_types.py index 6541575..e1bf949 100644 --- a/taskflow/tests/unit/worker_based/test_types.py +++ b/taskflow/tests/unit/worker_based/test_types.py @@ -14,12 +14,10 @@ # License for the specific language governing permissions and limitations # under the License. -import datetime import threading import time from oslo.utils import reflection -from oslo.utils import timeutils from taskflow.engines.worker_based import protocol as pr from taskflow.engines.worker_based import types as worker_types @@ -33,6 +31,7 @@ class TestWorkerTypes(test.TestCase): def setUp(self): super(TestWorkerTypes, self).setUp() + self.addCleanup(timing.StopWatch.clear_overrides) self.task = utils.DummyTask() self.task_uuid = 'task-uuid' self.task_action = 'execute' @@ -52,15 +51,12 @@ class TestWorkerTypes(test.TestCase): def test_requests_cache_expiry(self): # Mock out the calls the underlying objects will soon use to return # times that we can control more easily... - now = timeutils.utcnow() overrides = [ - now, - now, - now + datetime.timedelta(seconds=1), - now + datetime.timedelta(seconds=self.timeout + 1), + 0, + 1, + self.timeout + 1, ] - timeutils.set_time_override(overrides) - self.addCleanup(timeutils.clear_time_override) + timing.StopWatch.set_now_override(overrides) cache = worker_types.RequestsCache() cache[self.task_uuid] = self.request() |
