simplify waiting for outpost

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens Langhammer
2025-01-16 01:03:26 +01:00
parent e8e42261e3
commit af85ddf60b
5 changed files with 20 additions and 69 deletions

View File

@ -1,7 +1,6 @@
"""LDAP and Outpost e2e tests""" """LDAP and Outpost e2e tests"""
from dataclasses import asdict from dataclasses import asdict
from time import sleep
from guardian.shortcuts import assign_perm from guardian.shortcuts import assign_perm
from ldap3 import ALL, ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES, SUBTREE, Connection, Server from ldap3 import ALL, ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES, SUBTREE, Connection, Server
@ -56,17 +55,7 @@ class TestProviderLDAP(SeleniumTestCase):
outpost.providers.add(ldap) outpost.providers.add(ldap)
self.start_ldap(outpost) self.start_ldap(outpost)
self.wait_for_outpost(outpost)
# Wait until outpost healthcheck succeeds
healthcheck_retries = 0
while healthcheck_retries < 50: # noqa: PLR2004
if len(outpost.state) > 0:
state = outpost.state[0]
if state.last_seen:
break
healthcheck_retries += 1
sleep(0.5)
sleep(5)
return outpost return outpost
@retry() @retry()

View File

@ -7,7 +7,6 @@ from sys import platform
from time import sleep from time import sleep
from unittest.case import skip, skipUnless from unittest.case import skip, skipUnless
from channels.testing import ChannelsLiveServerTestCase
from jwt import decode from jwt import decode
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
@ -87,17 +86,7 @@ class TestProviderProxy(SeleniumTestCase):
outpost.build_user_permissions(outpost.user) outpost.build_user_permissions(outpost.user)
self.start_proxy(outpost) self.start_proxy(outpost)
self.wait_for_outpost(outpost)
# Wait until outpost healthcheck succeeds
healthcheck_retries = 0
while healthcheck_retries < 50: # noqa: PLR2004
if len(outpost.state) > 0:
state = outpost.state[0]
if state.last_seen:
break
healthcheck_retries += 1
sleep(0.5)
sleep(5)
self.driver.get("http://localhost:9000/api") self.driver.get("http://localhost:9000/api")
self.login() self.login()
@ -168,17 +157,7 @@ class TestProviderProxy(SeleniumTestCase):
outpost.build_user_permissions(outpost.user) outpost.build_user_permissions(outpost.user)
self.start_proxy(outpost) self.start_proxy(outpost)
self.wait_for_outpost(outpost)
# Wait until outpost healthcheck succeeds
healthcheck_retries = 0
while healthcheck_retries < 50: # noqa: PLR2004
if len(outpost.state) > 0:
state = outpost.state[0]
if state.last_seen:
break
healthcheck_retries += 1
sleep(0.5)
sleep(5)
self.driver.get("http://localhost:9000/api") self.driver.get("http://localhost:9000/api")
self.login() self.login()
@ -202,7 +181,7 @@ class TestProviderProxy(SeleniumTestCase):
# TODO: Fix flaky test # TODO: Fix flaky test
@skip("Flaky test") @skip("Flaky test")
@skipUnless(platform.startswith("linux"), "requires local docker") @skipUnless(platform.startswith("linux"), "requires local docker")
class TestProviderProxyConnect(ChannelsLiveServerTestCase): class TestProviderProxyConnect(SeleniumTestCase):
"""Test Proxy connectivity over websockets""" """Test Proxy connectivity over websockets"""
@retry(exceptions=[AssertionError]) @retry(exceptions=[AssertionError])
@ -239,16 +218,7 @@ class TestProviderProxyConnect(ChannelsLiveServerTestCase):
) )
outpost.providers.add(proxy) outpost.providers.add(proxy)
outpost.build_user_permissions(outpost.user) outpost.build_user_permissions(outpost.user)
self.wait_for_outpost(outpost)
# Wait until outpost healthcheck succeeds
healthcheck_retries = 0
while healthcheck_retries < 50: # noqa: PLR2004
if len(outpost.state) > 0:
state = outpost.state[0]
if state.last_seen and state.version:
break
healthcheck_retries += 1
sleep(0.5)
state = outpost.state state = outpost.state
self.assertGreaterEqual(len(state), 1) self.assertGreaterEqual(len(state), 1)

View File

@ -76,17 +76,7 @@ class TestProviderProxyForward(SeleniumTestCase):
outpost.build_user_permissions(outpost.user) outpost.build_user_permissions(outpost.user)
self.start_outpost(outpost) self.start_outpost(outpost)
self.wait_for_outpost(outpost)
# Wait until outpost healthcheck succeeds
healthcheck_retries = 0
while healthcheck_retries < 50: # noqa: PLR2004
if len(outpost.state) > 0:
state = outpost.state[0]
if state.last_seen:
break
healthcheck_retries += 1
sleep(0.5)
sleep(5)
@retry() @retry()
def test_traefik(self): def test_traefik(self):

View File

@ -1,7 +1,6 @@
"""Radius e2e tests""" """Radius e2e tests"""
from dataclasses import asdict from dataclasses import asdict
from time import sleep
from pyrad.client import Client from pyrad.client import Client
from pyrad.dictionary import Dictionary from pyrad.dictionary import Dictionary
@ -50,17 +49,7 @@ class TestProviderRadius(SeleniumTestCase):
outpost.providers.add(radius) outpost.providers.add(radius)
self.start_radius(outpost) self.start_radius(outpost)
self.wait_for_outpost(outpost)
# Wait until outpost healthcheck succeeds
healthcheck_retries = 0
while healthcheck_retries < 50: # noqa: PLR2004
if len(outpost.state) > 0:
state = outpost.state[0]
if state.last_seen:
break
healthcheck_retries += 1
sleep(0.5)
sleep(5)
return outpost return outpost
@retry() @retry()

View File

@ -35,6 +35,7 @@ from authentik.core.api.users import UserSerializer
from authentik.core.models import User from authentik.core.models import User
from authentik.core.tests.utils import create_test_admin_user from authentik.core.tests.utils import create_test_admin_user
from authentik.lib.generators import generate_id from authentik.lib.generators import generate_id
from authentik.outposts.models import Outpost
from tests.e2e._process import TestDatabaseProcess from tests.e2e._process import TestDatabaseProcess
RETRIES = int(environ.get("RETRIES", "3")) RETRIES = int(environ.get("RETRIES", "3"))
@ -270,6 +271,18 @@ class SeleniumTestCase(DockerTestCase, ChannelsLiveServerTestCase):
self.assertEqual(user["name"].value, expected_user.name) self.assertEqual(user["name"].value, expected_user.name)
self.assertEqual(user["email"].value, expected_user.email) self.assertEqual(user["email"].value, expected_user.email)
def wait_for_outpost(self, outpost: Outpost, tries=50):
"""Wait until outpost healthcheck succeeds"""
healthcheck_retries = 0
while healthcheck_retries < tries:
if len(outpost.state) > 0:
state = outpost.state[0]
if state.last_seen:
return
healthcheck_retries += 1
sleep(0.5)
raise self.failureException("Outpost failed to become healthy")
@lru_cache @lru_cache
def get_loader(): def get_loader():