Merge "Fix lock leaks in unit tests"
This commit is contained in:
commit
600784a91e
@ -237,6 +237,7 @@ class TestNodeCacheFind(test_base.NodeTest):
|
|||||||
|
|
||||||
def test_bmc(self):
|
def test_bmc(self):
|
||||||
res = node_cache.find_node(bmc_address='1.2.3.4')
|
res = node_cache.find_node(bmc_address='1.2.3.4')
|
||||||
|
self.addCleanup(res.release_lock)
|
||||||
self.assertEqual(self.uuid, res.uuid)
|
self.assertEqual(self.uuid, res.uuid)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
datetime.datetime.utcnow() - datetime.timedelta(seconds=60)
|
datetime.datetime.utcnow() - datetime.timedelta(seconds=60)
|
||||||
@ -251,8 +252,10 @@ class TestNodeCacheFind(test_base.NodeTest):
|
|||||||
bmc_address='1.2.3.4',
|
bmc_address='1.2.3.4',
|
||||||
mac=self.macs2)
|
mac=self.macs2)
|
||||||
res = node_cache.find_node(bmc_address='1.2.3.4', mac=self.macs)
|
res = node_cache.find_node(bmc_address='1.2.3.4', mac=self.macs)
|
||||||
|
self.addCleanup(res.release_lock)
|
||||||
self.assertEqual(self.uuid, res.uuid)
|
self.assertEqual(self.uuid, res.uuid)
|
||||||
res = node_cache.find_node(bmc_address='1.2.3.4', mac=self.macs2)
|
res = node_cache.find_node(bmc_address='1.2.3.4', mac=self.macs2)
|
||||||
|
self.addCleanup(res.release_lock)
|
||||||
self.assertEqual(uuid2, res.uuid)
|
self.assertEqual(uuid2, res.uuid)
|
||||||
|
|
||||||
def test_same_bmc_raises(self):
|
def test_same_bmc_raises(self):
|
||||||
@ -265,6 +268,7 @@ class TestNodeCacheFind(test_base.NodeTest):
|
|||||||
|
|
||||||
def test_macs(self):
|
def test_macs(self):
|
||||||
res = node_cache.find_node(mac=['11:22:33:33:33:33', self.macs[1]])
|
res = node_cache.find_node(mac=['11:22:33:33:33:33', self.macs[1]])
|
||||||
|
self.addCleanup(res.release_lock)
|
||||||
self.assertEqual(self.uuid, res.uuid)
|
self.assertEqual(self.uuid, res.uuid)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
datetime.datetime.utcnow() - datetime.timedelta(seconds=60)
|
datetime.datetime.utcnow() - datetime.timedelta(seconds=60)
|
||||||
@ -287,6 +291,7 @@ class TestNodeCacheFind(test_base.NodeTest):
|
|||||||
def test_both(self):
|
def test_both(self):
|
||||||
res = node_cache.find_node(bmc_address='1.2.3.4',
|
res = node_cache.find_node(bmc_address='1.2.3.4',
|
||||||
mac=self.macs)
|
mac=self.macs)
|
||||||
|
self.addCleanup(res.release_lock)
|
||||||
self.assertEqual(self.uuid, res.uuid)
|
self.assertEqual(self.uuid, res.uuid)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
datetime.datetime.utcnow() - datetime.timedelta(seconds=60)
|
datetime.datetime.utcnow() - datetime.timedelta(seconds=60)
|
||||||
@ -459,7 +464,7 @@ class TestNodeCacheGetNode(test_base.NodeTest):
|
|||||||
state=istate.States.starting,
|
state=istate.States.starting,
|
||||||
started_at=started_at).save(session)
|
started_at=started_at).save(session)
|
||||||
info = node_cache.get_node(self.uuid, locked=True)
|
info = node_cache.get_node(self.uuid, locked=True)
|
||||||
|
self.addCleanup(info.release_lock)
|
||||||
self.assertEqual(self.uuid, info.uuid)
|
self.assertEqual(self.uuid, info.uuid)
|
||||||
self.assertEqual(started_at, info.started_at)
|
self.assertEqual(started_at, info.started_at)
|
||||||
self.assertIsNone(info.finished_at)
|
self.assertIsNone(info.finished_at)
|
||||||
@ -852,6 +857,7 @@ class TestNodeCacheGetByPath(test_base.NodeTest):
|
|||||||
class TestLock(test_base.NodeTest):
|
class TestLock(test_base.NodeTest):
|
||||||
def test_acquire(self, get_lock_mock):
|
def test_acquire(self, get_lock_mock):
|
||||||
node_info = node_cache.NodeInfo(self.uuid)
|
node_info = node_cache.NodeInfo(self.uuid)
|
||||||
|
self.addCleanup(node_info.release_lock)
|
||||||
self.assertFalse(node_info._locked)
|
self.assertFalse(node_info._locked)
|
||||||
get_lock_mock.assert_called_once_with(self.uuid)
|
get_lock_mock.assert_called_once_with(self.uuid)
|
||||||
self.assertFalse(get_lock_mock.return_value.acquire.called)
|
self.assertFalse(get_lock_mock.return_value.acquire.called)
|
||||||
@ -875,6 +881,7 @@ class TestLock(test_base.NodeTest):
|
|||||||
|
|
||||||
def test_acquire_non_blocking(self, get_lock_mock):
|
def test_acquire_non_blocking(self, get_lock_mock):
|
||||||
node_info = node_cache.NodeInfo(self.uuid)
|
node_info = node_cache.NodeInfo(self.uuid)
|
||||||
|
self.addCleanup(node_info.release_lock)
|
||||||
self.assertFalse(node_info._locked)
|
self.assertFalse(node_info._locked)
|
||||||
get_lock_mock.return_value.acquire.side_effect = iter([False, True])
|
get_lock_mock.return_value.acquire.side_effect = iter([False, True])
|
||||||
|
|
||||||
|
@ -74,6 +74,11 @@ class BaseProcessTest(BaseTest):
|
|||||||
self.cli.node.get.return_value = self.node
|
self.cli.node.get.return_value = self.node
|
||||||
self.process_mock = self.process_fixture.mock
|
self.process_mock = self.process_fixture.mock
|
||||||
self.process_mock.return_value = self.fake_result_json
|
self.process_mock.return_value = self.fake_result_json
|
||||||
|
self.addCleanup(self._cleanup_lock, self.node_info)
|
||||||
|
|
||||||
|
def _cleanup_lock(self, node_info):
|
||||||
|
if node_info._locked:
|
||||||
|
node_info.release_lock()
|
||||||
|
|
||||||
|
|
||||||
class TestProcess(BaseProcessTest):
|
class TestProcess(BaseProcessTest):
|
||||||
|
Loading…
Reference in New Issue
Block a user