Fix builder shutdown race in tests

The builder intentionally does not attempt to shutdown the uploader
threads since that could take an unreasonable amount of time. This
causes a race in our tests where we can shutdown the ZooKeeper
connection while the upload thread is still in progress, which can
cause the test to fail with a ZooKeeper error. This adds uploader
thread cleanup for the builder used in tests.

Change-Id: I25d4b52e17501e5dc6543adef585dd3b86bd70f9
This commit is contained in:
David Shrewsbury 2019-10-10 14:47:27 -04:00
parent 239cbaeda6
commit e732fec5bf
1 changed files with 9 additions and 0 deletions

View File

@ -311,6 +311,8 @@ class BaseTestCase(testtools.TestCase):
class BuilderFixture(fixtures.Fixture):
log = logging.getLogger("tests.BuilderFixture")
def __init__(self, configfile, cleanup_interval, securefile=None,
num_uploaders=1):
super(BuilderFixture, self).__init__()
@ -332,6 +334,13 @@ class BuilderFixture(fixtures.Fixture):
self.addCleanup(self.cleanup)
def cleanup(self):
# The NodePoolBuilder.stop() method does not intentionally stop the
# upload workers for reasons documented in that method. But we can
# safely do so in tests.
for worker in self.builder._upload_workers:
worker.shutdown()
worker.join()
self.log.debug("Stopped worker %s", worker.name)
self.builder.stop()