From 3820e674483ca171dd4bbed63654f2205a2f5490 Mon Sep 17 00:00:00 2001 From: Christian Schwede Date: Mon, 29 Feb 2016 13:14:56 +0000 Subject: [PATCH] Add tests for Recon's object replication_time time unit Adding a simple test to avoid regression. Change-Id: I1503af414b5c557a8a2e2c410b3938e97a644a2e --- test/unit/obj/test_replicator.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/test/unit/obj/test_replicator.py b/test/unit/obj/test_replicator.py index 29c1d142ea..0345189c70 100644 --- a/test/unit/obj/test_replicator.py +++ b/test/unit/obj/test_replicator.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import collections +import json import unittest import os import mock @@ -320,12 +321,31 @@ class TestObjectReplicator(unittest.TestCase): self.assertEqual((start + 1) % 10, replicator.replication_cycle) self.assertFalse(process_errors) self.assertFalse(self.logger.get_lines_for_level('error')) - object_replicator.http_connect = was_connector + + # Returns 0 at first, and 60 on all following .next() calls + def _infinite_gen(): + yield 0 + while True: + yield 60 + with _mock_process(process_arg_checker): - for cycle in range(1, 10): - replicator.run_once() - self.assertEqual((start + 1 + cycle) % 10, - replicator.replication_cycle) + with mock.patch('time.time') as time_mock: + for cycle in range(1, 10): + time_mock.side_effect = _infinite_gen() + replicator.run_once() + self.assertEqual((start + 1 + cycle) % 10, + replicator.replication_cycle) + + self.assertEqual(0, replicator.stats['start']) + recon_fname = os.path.join(self.recon_cache, "object.recon") + with open(recon_fname) as cachefile: + recon = json.loads(cachefile.read()) + self.assertEqual(1, recon.get('replication_time')) + self.assertIn('replication_stats', recon) + self.assertIn('replication_last', recon) + expected = 'Object replication complete (once). (1.00 minutes)' + self.assertIn(expected, self.logger.get_lines_for_level('info')) + object_replicator.http_connect = was_connector # policy 1 def test_run_once_1(self):