Fix race in dib_image_list_json test

Change Ibff0a9016936b461eccb1b48dcf42f5ad8d8434e had an error that
was not caught by testing due to a race in the test code -- the
build might finish before the webapp starts.  This corrects the
test (and a few sibling tests) by starting the webapp first, then
starting the builder.

The actual error is also corrected: ImageBuild.updateFromDict is
implemented.  Further, duplicate fromDict method calls are removed
from several classes and renamed to updateFromDict so that the
APIs match.

Change-Id: I918d1badf838a23d6b0813b5b31dac4888d04ce0
This commit is contained in:
James E. Blair
2023-03-10 13:50:14 -08:00
parent 38177b0a2f
commit ccb530a166
2 changed files with 37 additions and 28 deletions

View File

@@ -34,12 +34,15 @@ class TestWebApp(tests.DBTestCase):
def test_image_list(self):
configfile = self.setup_config('node.yaml')
pool = self.useNodepool(configfile, watermark_sleep=1)
self.useBuilder(configfile)
pool.start()
webapp = self.useWebApp(pool, port=0)
webapp.start()
port = webapp.server.socket.getsockname()[1]
# Start the builder after the pool + webapp so they see the
# cache update
self.useBuilder(configfile)
self.waitForImage('fake-provider', 'fake-image')
self.waitForNodes('fake-label')
@@ -68,12 +71,15 @@ class TestWebApp(tests.DBTestCase):
def test_image_list_filtered(self):
configfile = self.setup_config('node.yaml')
pool = self.useNodepool(configfile, watermark_sleep=1)
self.useBuilder(configfile)
pool.start()
webapp = self.useWebApp(pool, port=0)
webapp.start()
port = webapp.server.socket.getsockname()[1]
# Start the builder after the pool + webapp so they see the
# cache update
self.useBuilder(configfile)
self.waitForImage('fake-provider', 'fake-image')
self.waitForNodes('fake-label')
@@ -90,12 +96,15 @@ class TestWebApp(tests.DBTestCase):
def test_image_list_json(self):
configfile = self.setup_config('node.yaml')
pool = self.useNodepool(configfile, watermark_sleep=1)
self.useBuilder(configfile)
pool.start()
webapp = self.useWebApp(pool, port=0)
webapp.start()
port = webapp.server.socket.getsockname()[1]
# Start the builder after the pool + webapp so they see the
# cache update
self.useBuilder(configfile)
self.waitForImage('fake-provider', 'fake-image')
self.waitForNodes('fake-label')
@@ -115,12 +124,15 @@ class TestWebApp(tests.DBTestCase):
def test_dib_image_list_json(self):
configfile = self.setup_config('node.yaml')
pool = self.useNodepool(configfile, watermark_sleep=1)
self.useBuilder(configfile)
pool.start()
webapp = self.useWebApp(pool, port=0)
webapp.start()
port = webapp.server.socket.getsockname()[1]
# Start the builder after the pool + webapp so they see the
# cache update
self.useBuilder(configfile)
self.waitForImage('fake-provider', 'fake-image')
self.waitForNodes('fake-label')
@@ -141,17 +153,18 @@ class TestWebApp(tests.DBTestCase):
def test_image_status_json(self):
configfile = self.setup_config("node.yaml")
pool = self.useNodepool(configfile, watermark_sleep=1)
builder = self.useBuilder(configfile)
# Make sure we have enough time to test for the build request
# before it's processed by the build worker.
for worker in builder._build_workers:
worker._interval = 60
pool.start()
webapp = self.useWebApp(pool, port=0)
webapp.start()
port = webapp.server.socket.getsockname()[1]
builder = self.useBuilder(configfile)
# Make sure we have enough time to test for the build request
# before it's processed by the build worker.
for worker in builder._build_workers:
worker._interval = 60
self.waitForImage("fake-provider", "fake-image")
self.waitForNodes('fake-label')