Browse Source

Removes use of timeutils.set_time_override

The set_time_override function in timeutils was written as a
helper function to mock utcnow for unittests before 'mock' was
generally used. Now that we have mock and fixture, we no longer
need to use it.

Change-Id: I8106c27dd839e71fa0e5140f77b098a8872999b8
Closes-Bug:#1266962
tags/10.0.0
zhangyangyang 1 year ago
parent
commit
b263fb17b7
1 changed files with 16 additions and 12 deletions
  1. 16
    12
      ceilometer/tests/unit/pipeline_base.py

+ 16
- 12
ceilometer/tests/unit/pipeline_base.py View File

@@ -949,7 +949,7 @@ class BasePipelineTestCase(base.BaseTestCase):
949 949
         ]
950 950
         self._set_pipeline_cfg('transformers', transformer_cfg)
951 951
         self._set_pipeline_cfg('meters', ['cpu'])
952
-        now = timeutils.utcnow()
952
+        now = datetime.datetime.utcnow()
953 953
         later = now + datetime.timedelta(minutes=offset)
954 954
         um = {'autoscaling_weight': weight} if weight else {}
955 955
         counters = [
@@ -1073,7 +1073,7 @@ class BasePipelineTestCase(base.BaseTestCase):
1073 1073
         ]
1074 1074
         self._set_pipeline_cfg('transformers', transformer_cfg)
1075 1075
         self._set_pipeline_cfg('meters', ['cpu'])
1076
-        now = timeutils.utcnow()
1076
+        now = datetime.datetime.utcnow()
1077 1077
         counters = [
1078 1078
             sample.Sample(
1079 1079
                 name='cpu',
@@ -1119,7 +1119,7 @@ class BasePipelineTestCase(base.BaseTestCase):
1119 1119
             self.cfg2file(self.pipeline_cfg), self.transformer_manager)
1120 1120
         pipe = pipeline_manager.pipelines[0]
1121 1121
 
1122
-        now = timeutils.utcnow()
1122
+        now = datetime.datetime.utcnow()
1123 1123
         now_time = monotonic.monotonic()
1124 1124
         # Simulate a laggy poller
1125 1125
         later = now + datetime.timedelta(seconds=12345)
@@ -1181,7 +1181,7 @@ class BasePipelineTestCase(base.BaseTestCase):
1181 1181
             self.cfg2file(self.pipeline_cfg), self.transformer_manager)
1182 1182
         pipe = pipeline_manager.pipelines[0]
1183 1183
 
1184
-        now = timeutils.utcnow()
1184
+        now = datetime.datetime.utcnow()
1185 1185
         later = now + datetime.timedelta(seconds=10)
1186 1186
         rounding = 12345
1187 1187
 
@@ -1239,7 +1239,7 @@ class BasePipelineTestCase(base.BaseTestCase):
1239 1239
             self.cfg2file(self.pipeline_cfg), self.transformer_manager)
1240 1240
         pipe = pipeline_manager.pipelines[0]
1241 1241
 
1242
-        now = timeutils.utcnow()
1242
+        now = datetime.datetime.utcnow()
1243 1243
         earlier = now - datetime.timedelta(seconds=10)
1244 1244
         later = now + datetime.timedelta(seconds=10)
1245 1245
 
@@ -1293,7 +1293,7 @@ class BasePipelineTestCase(base.BaseTestCase):
1293 1293
         )
1294 1294
 
1295 1295
     def _do_test_rate_of_change_mapping(self, pipe, meters, units):
1296
-        now = timeutils.utcnow()
1296
+        now = datetime.datetime.utcnow()
1297 1297
         base = 1000
1298 1298
         offset = 7
1299 1299
         rate = 42
@@ -1689,8 +1689,10 @@ class BasePipelineTestCase(base.BaseTestCase):
1689 1689
         publisher = pipe.publishers[0]
1690 1690
         self.assertEqual(2, len(publisher.samples))
1691 1691
 
1692
-    def test_aggregator_timed_flush(self):
1693
-        timeutils.set_time_override()
1692
+    @mock.patch.object(timeutils, 'utcnow')
1693
+    def test_aggregator_timed_flush(self, mock_utcnow):
1694
+        now = datetime.datetime.utcnow()
1695
+        mock_utcnow.return_value = now
1694 1696
         transformer_cfg = [
1695 1697
             {
1696 1698
                 'name': 'aggregator',
@@ -1722,7 +1724,7 @@ class BasePipelineTestCase(base.BaseTestCase):
1722 1724
         publisher = pipeline_manager.pipelines[0].publishers[0]
1723 1725
         self.assertEqual(0, len(publisher.samples))
1724 1726
 
1725
-        timeutils.advance_time_seconds(120)
1727
+        mock_utcnow.return_value = now + datetime.timedelta(seconds=120)
1726 1728
         pipe.flush()
1727 1729
         publisher = pipeline_manager.pipelines[0].publishers[0]
1728 1730
         self.assertEqual(1, len(publisher.samples))
@@ -2048,8 +2050,10 @@ class BasePipelineTestCase(base.BaseTestCase):
2048 2050
         self.assertEqual(2, len(publisher.samples))
2049 2051
         self.assertEqual(2050.0, publisher.samples[1].volume)
2050 2052
 
2051
-    def test_aggregator_timed_flush_no_matching_samples(self):
2052
-        timeutils.set_time_override()
2053
+    @mock.patch.object(timeutils, 'utcnow')
2054
+    def test_aggregator_timed_flush_no_matching_samples(self, mock_utcnow):
2055
+        now = datetime.datetime.utcnow()
2056
+        mock_utcnow.return_value = now
2053 2057
         transformer_cfg = [
2054 2058
             {
2055 2059
                 'name': 'aggregator',
@@ -2061,7 +2065,7 @@ class BasePipelineTestCase(base.BaseTestCase):
2061 2065
         pipeline_manager = pipeline.PipelineManager(
2062 2066
             self.CONF,
2063 2067
             self.cfg2file(self.pipeline_cfg), self.transformer_manager)
2064
-        timeutils.advance_time_seconds(200)
2068
+        mock_utcnow.return_value = now + datetime.timedelta(seconds=200)
2065 2069
         pipe = pipeline_manager.pipelines[0]
2066 2070
         pipe.flush()
2067 2071
         publisher = pipeline_manager.pipelines[0].publishers[0]

Loading…
Cancel
Save