summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Henkel <tobias.henkel@bmw.de>2018-11-27 07:42:48 +0100
committerTobias Henkel <tobias.henkel@bmw.de>2018-11-28 09:30:26 +0100
commite4b1ab790e245545760f2036ed82f91df137f266 (patch)
treeb400e98905e1faa83bc8e517ce4c29156efd7687
parente4f245eb1310935f3acdbf06616e93e7855482f5 (diff)
Fix test race in test_hold_expiration_higher_than_default
Since introducing znode caching the test test_hold_expiration_higher_than_default fails sometimes because the last assertion could get slightly outdated data. Fix the race by leveraging iterate_timeout. Change-Id: Idf76e62b87c29fa827e2fbacef57dbc60e4f3b7b
Notes
Notes (review): Code-Review+2: Monty Taylor <mordred@inaugust.com> Code-Review+2: James E. Blair <corvus@inaugust.com> Code-Review+2: David Shrewsbury <shrewsbury.dave@gmail.com> Workflow+1: David Shrewsbury <shrewsbury.dave@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 28 Nov 2018 18:30:45 +0000 Reviewed-on: https://review.openstack.org/620222 Project: openstack-infra/nodepool Branch: refs/heads/master
-rw-r--r--nodepool/tests/unit/test_launcher.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/nodepool/tests/unit/test_launcher.py b/nodepool/tests/unit/test_launcher.py
index b59732a..4b12ff2 100644
--- a/nodepool/tests/unit/test_launcher.py
+++ b/nodepool/tests/unit/test_launcher.py
@@ -22,6 +22,7 @@ import mock
22from nodepool import tests 22from nodepool import tests
23from nodepool import zk 23from nodepool import zk
24from nodepool.driver.fake import provider as fakeprovider 24from nodepool.driver.fake import provider as fakeprovider
25from nodepool.nodeutils import iterate_timeout
25import nodepool.launcher 26import nodepool.launcher
26 27
27from kazoo import exceptions as kze 28from kazoo import exceptions as kze
@@ -1003,8 +1004,8 @@ class TestLauncher(tests.DBTestCase):
1003 nodes = self.waitForNodes('fake-label', 2) 1004 nodes = self.waitForNodes('fake-label', 2)
1004 self.log.debug("...done waiting for initial pool.") 1005 self.log.debug("...done waiting for initial pool.")
1005 node_custom = nodes[0] 1006 node_custom = nodes[0]
1006 # TODO make it a multiple of fixture's max-hold-age 1007 # Make hold expiration much larger than max hold age.
1007 hold_expiration = 20 1008 hold_expiration = 180
1008 node = nodes[1] 1009 node = nodes[1]
1009 self.log.debug("Holding node %s... (default)" % node.id) 1010 self.log.debug("Holding node %s... (default)" % node.id)
1010 self.log.debug("Holding node %s...(%s seconds)" % (node_custom.id, 1011 self.log.debug("Holding node %s...(%s seconds)" % (node_custom.id,
@@ -1029,9 +1030,21 @@ class TestLauncher(tests.DBTestCase):
1029 # Wait for the instance to be cleaned up 1030 # Wait for the instance to be cleaned up
1030 manager = pool.getProviderManager('fake-provider') 1031 manager = pool.getProviderManager('fake-provider')
1031 self.waitForInstanceDeletion(manager, node.external_id) 1032 self.waitForInstanceDeletion(manager, node.external_id)
1032 # custom node should be deleted as well 1033
1033 held_nodes = [n for n in self.zk.nodeIterator() if n.state == zk.HOLD] 1034 # The custom node should be deleted as well but it may be slightly
1034 self.assertEqual(0, len(held_nodes), held_nodes) 1035 # delayed after the other node. Because of that we have defined a much
1036 # higher hold time than the max hold age. So we can give nodepool a few
1037 # extra seconds to clean it up and still validate that the max hold
1038 # age is not violated.
1039 for _ in iterate_timeout(10, Exception, 'assert custom_node is gone'):
1040 try:
1041 held_nodes = [n for n in self.zk.nodeIterator(cached=False)
1042 if n.state == zk.HOLD]
1043 self.assertEqual(0, len(held_nodes), held_nodes)
1044 break
1045 except AssertionError:
1046 # node still listed, retry
1047 pass
1035 1048
1036 def test_label_provider(self): 1049 def test_label_provider(self):
1037 """Test that only providers listed in the label satisfy the request""" 1050 """Test that only providers listed in the label satisfy the request"""