Browse Source

Fix race with test_provider_removal unit test

The artificial sleep() call was sometimes not long enough for the
test to succeed. Switch to using iterate_timeout().

Change-Id: I7ebdabe1a6e8ba3a01593c7b63aa784a23aca2d3
David Shrewsbury 2 weeks ago
parent
commit
df466435fe
1 changed files with 9 additions and 3 deletions
  1. 9
    3
      nodepool/tests/unit/test_launcher.py

+ 9
- 3
nodepool/tests/unit/test_launcher.py View File

@@ -1438,9 +1438,15 @@ class TestLauncher(tests.DBTestCase):
1438 1438
         self.assertEqual(2, len(pool._pool_threads))
1439 1439
 
1440 1440
         self.replace_config(configfile, 'launcher_two_provider_remove.yaml')
1441
-        # wait longer than our watermark_sleep time for the config to change
1442
-        time.sleep(1)
1443
-        self.assertEqual(1, len(pool._pool_threads))
1441
+
1442
+        # Our provider pool thread count should eventually be reduced to 1
1443
+        for _ in iterate_timeout(10, Exception,
1444
+                                 'provider pool threads to reduce to 1'):
1445
+            try:
1446
+                self.assertEqual(1, len(pool._pool_threads))
1447
+                break
1448
+            except AssertionError:
1449
+                pass
1444 1450
 
1445 1451
     def test_failed_provider(self):
1446 1452
         """Test that broken provider doesn't fail node requests."""

Loading…
Cancel
Save