fix(installer): harden setupSuperUser race and add slow-resource e2e
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import unittest
|
||||
|
||||
from matomo_bootstrap.installers.web import _click_next_with_wait, _count_locator
|
||||
from matomo_bootstrap.installers.web import (
|
||||
_click_next_with_wait,
|
||||
_count_locator,
|
||||
_wait_for_superuser_login_field,
|
||||
)
|
||||
|
||||
|
||||
class _FlakyLocator:
|
||||
@@ -125,6 +129,37 @@ class _NoNextButNamedLoginAppearsPage:
|
||||
self.login_visible = True
|
||||
|
||||
|
||||
class _DelayedSuperuserLoginPage:
|
||||
def __init__(self, *, reveal_after_wait_calls: int | None):
|
||||
self.url = "http://matomo/index.php?action=setupSuperUser&module=Installation"
|
||||
self.login_visible = False
|
||||
self._wait_calls = 0
|
||||
self._reveal_after_wait_calls = reveal_after_wait_calls
|
||||
|
||||
def locator(self, selector: str):
|
||||
return _StaticLocator(self, selector)
|
||||
|
||||
def get_by_role(self, role: str, name: str):
|
||||
return _RoleLocator(0)
|
||||
|
||||
def get_by_text(self, *_args, **_kwargs):
|
||||
return _RoleLocator(0)
|
||||
|
||||
def title(self) -> str:
|
||||
return "setupSuperUser"
|
||||
|
||||
def wait_for_load_state(self, *_args, **_kwargs):
|
||||
return None
|
||||
|
||||
def wait_for_timeout(self, *_args, **_kwargs):
|
||||
self._wait_calls += 1
|
||||
if (
|
||||
self._reveal_after_wait_calls is not None
|
||||
and self._wait_calls >= self._reveal_after_wait_calls
|
||||
):
|
||||
self.login_visible = True
|
||||
|
||||
|
||||
class TestWebInstallerLocatorCountIntegration(unittest.TestCase):
|
||||
def test_retries_transient_navigation_error(self) -> None:
|
||||
locator = _FlakyLocator(
|
||||
@@ -168,6 +203,29 @@ class TestWebInstallerLocatorCountIntegration(unittest.TestCase):
|
||||
self.assertEqual(step, "Installation:setupSuperUser")
|
||||
self.assertTrue(page.login_visible)
|
||||
|
||||
def test_wait_for_superuser_login_field_allows_delayed_form(self) -> None:
|
||||
page = _DelayedSuperuserLoginPage(reveal_after_wait_calls=4)
|
||||
|
||||
visible = _wait_for_superuser_login_field(
|
||||
page,
|
||||
timeout_s=1.0,
|
||||
poll_interval_ms=1,
|
||||
)
|
||||
|
||||
self.assertTrue(visible)
|
||||
self.assertTrue(page.login_visible)
|
||||
|
||||
def test_wait_for_superuser_login_field_times_out_when_absent(self) -> None:
|
||||
page = _DelayedSuperuserLoginPage(reveal_after_wait_calls=None)
|
||||
|
||||
visible = _wait_for_superuser_login_field(
|
||||
page,
|
||||
timeout_s=0.01,
|
||||
poll_interval_ms=1,
|
||||
)
|
||||
|
||||
self.assertFalse(visible)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user