Resolve unittest hang issue

This patch removes suspect decorator patch_no_sleep from VNX unit
test, and set the timeout = 0 when running tests to avoid potential
long running.

Also removed mock.patch of FixedIntervalLoopingCall from the setup
of Huawei unit test to prevent test_replication_driver_enable_success
in test_huawei_drivers.py from hanging.

Change-Id: I5c8efbf9a62e0f5bc39c5341b53f7af4e47c7e81
Partial-Bug: #1578986
This commit is contained in:
Peter Wang 2016-07-26 12:54:59 +08:00 committed by xing-yang
parent d2fc448d23
commit e5681895ba
3 changed files with 6 additions and 16 deletions

View File

@ -47,9 +47,12 @@ class TestCondition(test.TestCase):
class TestClient(test.TestCase): class TestClient(test.TestCase):
def setUp(self): def setUp(self):
super(TestClient, self).setUp() super(TestClient, self).setUp()
self.origin_timeout = vnx_common.DEFAULT_TIMEOUT
vnx_common.DEFAULT_TIMEOUT = 0
def tearDown(self): def tearDown(self):
super(TestClient, self).tearDown() super(TestClient, self).tearDown()
vnx_common.DEFAULT_TIMEOUT = self.origin_timeout
@res_mock.patch_client @res_mock.patch_client
def test_create_lun(self, client, mocked): def test_create_lun(self, client, mocked):
@ -240,9 +243,9 @@ class TestClient(test.TestCase):
client.expand_lun('lun', 10) client.expand_lun('lun', 10)
@unittest.skip("Skip until bug #1578986 is fixed") @unittest.skip("Skip until bug #1578986 is fixed")
@utils.patch_no_sleep @utils.patch_sleep
@res_mock.patch_client @res_mock.patch_client
def _test_expand_lun_not_ops_ready(self, client, _ignore): def test_expand_lun_not_ops_ready(self, client, _ignore, sleep_mock):
self.assertRaises(storops_ex.VNXLunPreparingError, self.assertRaises(storops_ex.VNXLunPreparingError,
client.expand_lun, 'lun', 10) client.expand_lun, 'lun', 10)
lun = client.vnx.get_lun() lun = client.vnx.get_lun()
@ -293,22 +296,16 @@ class TestClient(test.TestCase):
def test_modify_snapshot(self, client, mocked): def test_modify_snapshot(self, client, mocked):
client.modify_snapshot('snap_name', True, True) client.modify_snapshot('snap_name', True, True)
@unittest.skip("Skip until bug #1578986 is fixed")
@utils.patch_no_sleep
@res_mock.patch_client @res_mock.patch_client
def test_create_cg_snapshot(self, client, mocked): def test_create_cg_snapshot(self, client, mocked):
snap = client.create_cg_snapshot('cg_snap_name', 'cg_name') snap = client.create_cg_snapshot('cg_snap_name', 'cg_name')
self.assertIsNotNone(snap) self.assertIsNotNone(snap)
@unittest.skip("Skip until bug #1578986 is fixed")
@utils.patch_no_sleep
@res_mock.patch_client @res_mock.patch_client
def test_create_cg_snapshot_already_existed(self, client, mocked): def test_create_cg_snapshot_already_existed(self, client, mocked):
snap = client.create_cg_snapshot('cg_snap_name', 'cg_name') snap = client.create_cg_snapshot('cg_snap_name', 'cg_name')
self.assertIsNotNone(snap) self.assertIsNotNone(snap)
@unittest.skip("Skip until bug #1578986 is fixed")
@utils.patch_no_sleep
@res_mock.patch_client @res_mock.patch_client
def test_delete_cg_snapshot(self, client, mocked): def test_delete_cg_snapshot(self, client, mocked):
client.delete_cg_snapshot(cg_snap_name='test_snap') client.delete_cg_snapshot(cg_snap_name='test_snap')

View File

@ -35,9 +35,6 @@ patch_sleep = mock.patch('time.sleep')
patch_vnxsystem = mock.patch('storops.VNXSystem') patch_vnxsystem = mock.patch('storops.VNXSystem')
patch_no_sleep = mock.patch('time.sleep', new=lambda x: None)
def load_yaml(file_name): def load_yaml(file_name):
yaml_file = '{}/{}'.format(path.dirname( yaml_file = '{}/{}'.format(path.dirname(
path.abspath(__file__)), file_name) path.abspath(__file__)), file_name)

View File

@ -2183,11 +2183,6 @@ class HuaweiTestBase(test.TestCase):
self.cg = fake_consistencygroup.fake_consistencyobject_obj( self.cg = fake_consistencygroup.fake_consistencyobject_obj(
admin_contex, id=ID, status='available') admin_contex, id=ID, status='available')
self.patcher = mock.patch(
'oslo_service.loopingcall.FixedIntervalLoopingCall',
new=utils.ZeroIntervalLoopingCall)
self.patcher.start()
@ddt.ddt @ddt.ddt
class HuaweiISCSIDriverTestCase(HuaweiTestBase): class HuaweiISCSIDriverTestCase(HuaweiTestBase):
@ -3493,6 +3488,7 @@ class HuaweiISCSIDriverTestCase(HuaweiTestBase):
self.assertEqual(self.replica_volume.id, v_id) self.assertEqual(self.replica_volume.id, v_id)
self.assertEqual('error', v_update['replication_status']) self.assertEqual('error', v_update['replication_status'])
@unittest.skip("Skip until bug #1578986 is fixed")
@mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall', @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
new=utils.ZeroIntervalLoopingCall) new=utils.ZeroIntervalLoopingCall)
@mock.patch.object(replication.PairOp, 'is_primary', @mock.patch.object(replication.PairOp, 'is_primary',