summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-12-11 19:00:53 +0000
committerGerrit Code Review <review@openstack.org>2018-12-11 19:00:53 +0000
commit6aa1fff8828b04c14e7fbe3f6840da5facdc4c59 (patch)
treeb4bdb5b23c3fb830fa2f42dc5499c84d2ef3e374
parentcc994d3a6afddf8efcd1562f7a3013653e2dd257 (diff)
parentb75f463280eac224d7752c8ff6fff9497d9cb32a (diff)
Merge "Fix race in test_handler_poll_session_expired"HEADmaster
-rw-r--r--nodepool/tests/unit/test_launcher.py47
1 files changed, 35 insertions, 12 deletions
diff --git a/nodepool/tests/unit/test_launcher.py b/nodepool/tests/unit/test_launcher.py
index f9f0e84..2efea9d 100644
--- a/nodepool/tests/unit/test_launcher.py
+++ b/nodepool/tests/unit/test_launcher.py
@@ -1655,31 +1655,54 @@ class TestLauncher(tests.DBTestCase):
1655 self.assertEqual(req.state, zk.FULFILLED) 1655 self.assertEqual(req.state, zk.FULFILLED)
1656 self.assertEqual(len(req.nodes), 1) 1656 self.assertEqual(len(req.nodes), 1)
1657 1657
1658 @mock.patch( 1658 @mock.patch('nodepool.driver.NodeRequestHandler.poll')
1659 'nodepool.driver.openstack.handler.OpenStackNodeRequestHandler.poll')
1660 def test_handler_poll_session_expired(self, mock_poll): 1659 def test_handler_poll_session_expired(self, mock_poll):
1661 ''' 1660 '''
1662 Test ZK session lost during handler poll(). 1661 Test ZK session lost during handler poll() removes handler.
1663 ''' 1662 '''
1664 mock_poll.side_effect = kze.SessionExpiredError() 1663 req = zk.NodeRequest()
1664 req.state = zk.REQUESTED
1665 req.node_types.append('fake-label')
1666 self.zk.storeNodeRequest(req)
1667
1668 # We need to stop processing of this request so that it does not
1669 # re-enter request handling, so we can then verify that it was
1670 # actually removed from request_handlers in the final assert of
1671 # this test.
1672 def side_effect():
1673 req.state = zk.FAILED
1674 # Intentionally ignore that it is already locked.
1675 self.zk.storeNodeRequest(req)
1676 raise kze.SessionExpiredError()
1677
1678 mock_poll.side_effect = side_effect
1665 1679
1666 # use a config with min-ready of 0 1680 # use a config with min-ready of 0
1667 configfile = self.setup_config('node_launch_retry.yaml') 1681 configfile = self.setup_config('node_launch_retry.yaml')
1668 self.useBuilder(configfile) 1682 self.useBuilder(configfile)
1683
1684 # Wait for the image to exist before starting the launcher, else
1685 # we'll decline the request.
1686 self.waitForImage('fake-provider', 'fake-image')
1687
1669 pool = self.useNodepool(configfile, watermark_sleep=1) 1688 pool = self.useNodepool(configfile, watermark_sleep=1)
1670 pool.cleanup_interval = 60 1689 pool.cleanup_interval = 60
1671 pool.start() 1690 pool.start()
1672 self.waitForImage('fake-provider', 'fake-image')
1673 1691
1674 req = zk.NodeRequest() 1692 # Wait for request handling to occur
1675 req.state = zk.REQUESTED 1693 while not mock_poll.call_count:
1676 req.node_types.append('fake-label') 1694 time.sleep(.1)
1677 self.zk.storeNodeRequest(req) 1695
1696 # Note: The launcher is not setting FAILED state here, but our mock
1697 # side effect should be doing so. Just verify that.
1698 req = self.waitForNodeRequest(req)
1699 self.assertEqual(zk.FAILED, req.state)
1678 1700
1679 # A session loss during handler poll should at least remove the 1701 # A session loss during handler poll should at least remove the
1680 # request from active handlers 1702 # request from active handlers. The session exception from our first
1681 req = self.waitForNodeRequest(req, states=(zk.PENDING,)) 1703 # time through poll() should handle removing the request handler.
1682 self.assertEqual(1, mock_poll.call_count) 1704 # And our mock side effect should ensure it does not re-enter
1705 # request handling before we check it.
1683 self.assertEqual(0, len( 1706 self.assertEqual(0, len(
1684 pool._pool_threads["fake-provider-main"].request_handlers)) 1707 pool._pool_threads["fake-provider-main"].request_handlers))
1685 1708