Преглед изворни кода

Mock time.sleep

Some tested methods perform retries without mocking time.sleep,
which means that the tests wait unnecessarily.

We'll go ahead and mock time.sleep for those tests.
Lucian Petrut пре 2 недеља
родитељ
комит
f729255c07

+ 2 - 1
coriolis/tests/osmorphing/osmount/test_base.py

@@ -910,6 +910,7 @@ class BaseLinuxOSMountToolsTestCase(test_base.CoriolisBaseTestCase):
 
         self.assertEqual(result, ('/tmp/tmp_dir', '/dev/sdb1'))
 
+    @mock.patch("time.sleep")
     @mock.patch.object(base.BaseSSHOSMountTools, '_exec_cmd')
     @mock.patch.object(base.BaseLinuxOSMountTools, '_get_vgs')
     @mock.patch.object(base.BaseLinuxOSMountTools, '_get_mounted_devices')
@@ -924,7 +925,7 @@ class BaseLinuxOSMountToolsTestCase(test_base.CoriolisBaseTestCase):
                               mock_find_dev_with_contents,
                               mock_find_and_mount_root,
                               mock_get_mounted_devices, mock_get_vgs,
-                              mock_exec_cmd):
+                              mock_exec_cmd, mock_sleep):
         mock_get_volume_block_devices.return_value = ["/dev/sda", "/dev/sdb"]
         mock_find_and_mount_root.return_value = ("/tmp/tmp_dir", "/dev/sdb1")
         mock_get_vgs.return_value = {

+ 2 - 1
coriolis/tests/providers/test_backup_writers.py

@@ -940,11 +940,12 @@ class HTTPBackupWriterImplTestCase(test_base.CoriolisBaseTestCase):
         self.assertEqual(self.writer._write_error, False)
         self.assertIsInstance(self.writer._exception, BaseException)
 
+    @mock.patch("time.sleep")
     @mock.patch.object(backup_writers.HTTPBackupWriterImpl, '_ensure_session')
     @mock.patch.object(backup_writers.HTTPBackupWriterImpl, '_uri')
     @mock.patch.object(backup_writers, 'CONF')
     def test__sender_with_exception(self, mock_conf, mock_uri,
-                                    mock_ensure_session):
+                                    mock_ensure_session, mock_sleep):
         self.writer._session = mock.MagicMock()
         self.writer._sender_q = mock.MagicMock()
         mock_response = mock.MagicMock()

+ 2 - 1
coriolis/tests/test_utils.py

@@ -473,7 +473,8 @@ class UtilsTestCase(test_base.CoriolisBaseTestCase):
         ]
         mock_exec_ssh_cmd.assert_has_calls(expected_calls)
 
-    def test_run_xfs_repair_exception(self):
+    @mock.patch("time.sleep")
+    def test_run_xfs_repair_exception(self, mock_sleep):
         self.mock_ssh.exec_command.side_effect = Exception()
 
         with self.assertLogs('coriolis.utils', level=logging.WARN):

+ 2 - 1
coriolis/tests/test_wsman.py

@@ -122,7 +122,8 @@ class WSManConnectionTestCase(test_base.CoriolisBaseTestCase):
             mock.ANY, mock.ANY)
         self.conn._protocol.close_shell.assert_called_once_with(mock.ANY)
 
-    def test__exec_command_invalid_credentials(self):
+    @mock.patch("time.sleep")
+    def test__exec_command_invalid_credentials(self, mock_sleep):
         self.conn._protocol.open_shell.side_effect = (
             wsman.winrm_exceptions.InvalidCredentialsError)