tests: show logs for containers on failed e2e tests

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-06-03 22:17:18 +02:00
parent 0eaabbc0f3
commit e9621bae06
3 changed files with 22 additions and 0 deletions

View File

@ -265,6 +265,8 @@ DATABASES = {
"USER": CONFIG.y("postgresql.user"),
"PASSWORD": CONFIG.y("postgresql.password"),
"PORT": int(CONFIG.y("postgresql.port")),
"CONN_MAX_AGE": 300,
"ATOMIC_REQUESTS": True,
}
}

View File

@ -32,6 +32,7 @@ class TestProviderProxy(SeleniumTestCase):
def tearDown(self) -> None:
super().tearDown()
self.output_container_logs(self.proxy_container)
self.proxy_container.kill()
def get_container_specs(self) -> Optional[dict[str, Any]]:
@ -88,6 +89,16 @@ class TestProviderProxy(SeleniumTestCase):
self.proxy_container = self.start_proxy(outpost)
# Wait until outpost healthcheck succeeds
healthcheck_retries = 0
while healthcheck_retries < 50:
if len(outpost.state) > 0:
state = outpost.state[0]
if state.last_seen:
break
healthcheck_retries += 1
sleep(0.5)
self.driver.get("http://localhost:4180")
self.login()
sleep(1)

View File

@ -71,6 +71,14 @@ class SeleniumTestCase(StaticLiveServerTestCase):
self.logger.info("Container failed healthcheck")
sleep(1)
def output_container_logs(self, container: Optional[Container] = None):
"""Output the container logs to our STDOUT"""
ct = container or self.container
self.logger.debug("--------container logs", container=ct.image.tags[0])
for log in ct.logs().decode().split("\n"):
self.logger.debug(log, container=ct.image.tags[0])
self.logger.debug("--------end container logs", container=ct.image.tags[0])
def get_container_specs(self) -> Optional[dict[str, Any]]:
"""Optionally get container specs which will launched on setup, wait for the container to
be healthy, and deleted again on tearDown"""
@ -97,6 +105,7 @@ class SeleniumTestCase(StaticLiveServerTestCase):
)
self.logger.debug("--------end browser logs")
if self.container:
self.output_container_logs()
self.container.kill()
self.driver.quit()
super().tearDown()