Browse Source

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
tags/3.4.0
Tobias Henkel 5 months ago
parent
commit
e4b1ab790e
No account linked to committer's email address
1 changed files with 18 additions and 5 deletions
  1. 18
    5
      nodepool/tests/unit/test_launcher.py

+ 18
- 5
nodepool/tests/unit/test_launcher.py View File

@@ -22,6 +22,7 @@ import mock
22 22
 from nodepool import tests
23 23
 from nodepool import zk
24 24
 from nodepool.driver.fake import provider as fakeprovider
25
+from nodepool.nodeutils import iterate_timeout
25 26
 import nodepool.launcher
26 27
 
27 28
 from kazoo import exceptions as kze
@@ -1003,8 +1004,8 @@ class TestLauncher(tests.DBTestCase):
1003 1004
         nodes = self.waitForNodes('fake-label', 2)
1004 1005
         self.log.debug("...done waiting for initial pool.")
1005 1006
         node_custom = nodes[0]
1006
-        # TODO make it a multiple of fixture's max-hold-age
1007
-        hold_expiration = 20
1007
+        # Make hold expiration much larger than max hold age.
1008
+        hold_expiration = 180
1008 1009
         node = nodes[1]
1009 1010
         self.log.debug("Holding node %s... (default)" % node.id)
1010 1011
         self.log.debug("Holding node %s...(%s seconds)" % (node_custom.id,
@@ -1029,9 +1030,21 @@ class TestLauncher(tests.DBTestCase):
1029 1030
         # Wait for the instance to be cleaned up
1030 1031
         manager = pool.getProviderManager('fake-provider')
1031 1032
         self.waitForInstanceDeletion(manager, node.external_id)
1032
-        # custom node should be deleted as well
1033
-        held_nodes = [n for n in self.zk.nodeIterator() if n.state == zk.HOLD]
1034
-        self.assertEqual(0, len(held_nodes), held_nodes)
1033
+
1034
+        # The custom node should be deleted as well but it may be slightly
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 1049
     def test_label_provider(self):
1037 1050
         """Test that only providers listed in the label satisfy the request"""

Loading…
Cancel
Save