fix(registry): race condition handled with page 'ready'
This commit is contained in:
@@ -436,6 +436,8 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
["secret", "path"],
|
||||
True, # noqa: FBT003
|
||||
),
|
||||
self.mock_call(self.registry.remove, ["path"], True), # noqa: FBT003
|
||||
self.mock_call(self.registry.add, ["path"]),
|
||||
self.expects_error(
|
||||
handler, http.HTTPStatus.BAD_REQUEST, "Invalid tar archive"
|
||||
),
|
||||
@@ -457,6 +459,7 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
["secret", "path"],
|
||||
True, # noqa: FBT003
|
||||
),
|
||||
self.mock_call(self.registry.remove, ["path"], False), # noqa: FBT003
|
||||
self.expects_error(handler, http.HTTPStatus.INTERNAL_SERVER_ERROR, ""),
|
||||
self.seal_mocks(),
|
||||
):
|
||||
@@ -476,8 +479,10 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
True, # noqa: FBT003
|
||||
),
|
||||
self.mock_call_unchecked(self.data_dir.extract_tar_bytes),
|
||||
self.mock_call(self.registry.remove, ["path"], False), # noqa: FBT003
|
||||
self.mock_call(self.registry.add, ["path"]),
|
||||
self.mock_call(self.token_manager.set_token, ["path", "secret"]),
|
||||
self.mock_call(self.registry.mark_ready, ["path"]),
|
||||
self.mock_call(self.registry.get_from_path, ["path"]),
|
||||
self.expects_status_only(
|
||||
handler, http.HTTPStatus.CREATED, "Resource updated"
|
||||
@@ -501,9 +506,11 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
),
|
||||
self.mock_call(self.registry.get_from_host, ["example.com"], Page("path")),
|
||||
self.mock_call_unchecked(self.data_dir.extract_tar_bytes),
|
||||
self.mock_call(self.registry.remove, ["path"], False), # noqa: FBT003
|
||||
self.mock_call(self.registry.add, ["path"]),
|
||||
self.mock_call(self.token_manager.set_token, ["path", "secret"]),
|
||||
self.mock_call(self.registry.set_host, ["path", "example.com"]),
|
||||
self.mock_call(self.registry.mark_ready, ["path"]),
|
||||
self.mock_call(self.registry.get_from_path, ["path"]),
|
||||
self.expects_status_only(
|
||||
handler, http.HTTPStatus.CREATED, "Resource updated"
|
||||
@@ -525,9 +532,11 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
True, # noqa: FBT003
|
||||
),
|
||||
self.mock_call_unchecked(self.data_dir.extract_tar_bytes),
|
||||
self.mock_call(self.registry.remove, ["path"], False), # noqa: FBT003
|
||||
self.mock_call(self.registry.add, ["path"]),
|
||||
self.mock_call(self.token_manager.set_token, ["path", "secret"]),
|
||||
self.mock_call(self.registry.set_spa, ["path", "index.html"]),
|
||||
self.mock_call(self.registry.mark_ready, ["path"]),
|
||||
self.mock_call(self.registry.get_from_path, ["path"]),
|
||||
self.expects_status_only(
|
||||
handler, http.HTTPStatus.CREATED, "Resource updated"
|
||||
@@ -578,6 +587,7 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
),
|
||||
self.mock_call(self.registry.set_redirect, ["path", "https://example.com"]),
|
||||
self.mock_call(self.token_manager.set_token, ["path", "secret"]),
|
||||
self.mock_call(self.registry.mark_ready, ["path"]),
|
||||
self.mock_call(self.registry.get_from_path, ["path"]),
|
||||
self.expects_status_only(
|
||||
handler, http.HTTPStatus.CREATED, "Resource updated"
|
||||
@@ -606,6 +616,7 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
self.mock_call(self.registry.set_redirect, ["path", "https://example.com"]),
|
||||
self.mock_call(self.token_manager.set_token, ["path", "secret"]),
|
||||
self.mock_call(self.registry.set_host, ["path", "example.com"]),
|
||||
self.mock_call(self.registry.mark_ready, ["path"]),
|
||||
self.mock_call(self.registry.get_from_path, ["path"]),
|
||||
self.expects_status_only(
|
||||
handler, http.HTTPStatus.CREATED, "Resource updated"
|
||||
@@ -634,6 +645,7 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
self.mock_call(self.registry.set_redirect, ["path", "https://example.com"]),
|
||||
self.mock_call(self.token_manager.set_token, ["path", "secret"]),
|
||||
self.mock_call(self.registry.set_host_only, ["path", "example.com"]),
|
||||
self.mock_call(self.registry.mark_ready, ["path"]),
|
||||
self.mock_call(self.registry.get_from_path, ["path"]),
|
||||
self.expects_status_only(
|
||||
handler, http.HTTPStatus.CREATED, "Resource updated"
|
||||
@@ -684,6 +696,7 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
),
|
||||
self.mock_call(self.registry.set_proxy, ["path", "https://example.com"]),
|
||||
self.mock_call(self.token_manager.set_token, ["path", "secret"]),
|
||||
self.mock_call(self.registry.mark_ready, ["path"]),
|
||||
self.mock_call(self.registry.get_from_path, ["path"]),
|
||||
self.expects_status_only(
|
||||
handler, http.HTTPStatus.CREATED, "Resource updated"
|
||||
@@ -712,6 +725,7 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
self.mock_call(self.registry.set_proxy, ["path", "https://example.com"]),
|
||||
self.mock_call(self.token_manager.set_token, ["path", "secret"]),
|
||||
self.mock_call(self.registry.set_host, ["path", "example.com"]),
|
||||
self.mock_call(self.registry.mark_ready, ["path"]),
|
||||
self.mock_call(self.registry.get_from_path, ["path"]),
|
||||
self.expects_status_only(
|
||||
handler, http.HTTPStatus.CREATED, "Resource updated"
|
||||
|
||||
+36
-1
@@ -185,6 +185,7 @@ class TestRegistry(BaseTestCase):
|
||||
self.assertEqual(
|
||||
self.registry.pages["test_1"].redirect, "https://new-example.com"
|
||||
)
|
||||
assert not self.registry.pages["test_1"].ready
|
||||
|
||||
def test_set_redirect_no_change(self) -> None:
|
||||
self.registry.pages["test_1"] = Page(
|
||||
@@ -214,6 +215,7 @@ class TestRegistry(BaseTestCase):
|
||||
self.assertEqual(
|
||||
self.registry.pages["test_1"].redirect, "https://new-example.com"
|
||||
)
|
||||
assert not self.registry.pages["test_1"].ready
|
||||
|
||||
def test_set_proxy(self) -> None:
|
||||
self.registry.pages["test_1"] = Page(
|
||||
@@ -233,6 +235,7 @@ class TestRegistry(BaseTestCase):
|
||||
):
|
||||
self.registry.set_proxy("test_1", "https://new-example.com")
|
||||
self.assertEqual(self.registry.pages["test_1"].proxy, "https://new-example.com")
|
||||
assert not self.registry.pages["test_1"].ready
|
||||
|
||||
def test_set_proxy_no_change(self) -> None:
|
||||
self.registry.pages["test_1"] = Page(
|
||||
@@ -260,6 +263,7 @@ class TestRegistry(BaseTestCase):
|
||||
self.registry.set_proxy("test_1", "https://new-example.com")
|
||||
self.assertIn("test_1", self.registry.pages)
|
||||
self.assertEqual(self.registry.pages["test_1"].proxy, "https://new-example.com")
|
||||
assert not self.registry.pages["test_1"].ready
|
||||
|
||||
def test_set_spa(self) -> None:
|
||||
self.registry.pages["test_1"] = Page(
|
||||
@@ -298,9 +302,27 @@ class TestRegistry(BaseTestCase):
|
||||
"test_1",
|
||||
)
|
||||
self.seal_mocks()
|
||||
self.registry.remove("test_1")
|
||||
assert self.registry.remove("test_1")
|
||||
self.assertNotIn("test_1", self.registry.pages)
|
||||
|
||||
def test_remove_not_found(self) -> None:
|
||||
self.seal_mocks()
|
||||
assert not self.registry.remove("test_1")
|
||||
|
||||
def test_mark_ready(self) -> None:
|
||||
self.registry.pages["test_1"] = Page("test_1", ready=False)
|
||||
with (
|
||||
self.seal_mocks(),
|
||||
):
|
||||
self.registry.mark_ready("test_1")
|
||||
assert self.registry.pages["test_1"].ready
|
||||
|
||||
def test_mark_ready_not_found(self) -> None:
|
||||
with (
|
||||
self.seal_mocks(),
|
||||
):
|
||||
self.registry.mark_ready("test_1")
|
||||
|
||||
def test_get_from_path(self) -> None:
|
||||
self.registry.pages["test_1"] = (
|
||||
target := Page(
|
||||
@@ -313,6 +335,14 @@ class TestRegistry(BaseTestCase):
|
||||
self.seal_mocks()
|
||||
self.assertEqual(self.registry.get_from_path("test_1"), target)
|
||||
|
||||
def test_get_from_path_not_ready(self) -> None:
|
||||
self.registry.pages["test_1"] = Page(
|
||||
"test_1",
|
||||
ready=False,
|
||||
)
|
||||
self.seal_mocks()
|
||||
self.assertIsNone(self.registry.get_from_path("test_1"))
|
||||
|
||||
def test_get_from_path_not_found(self) -> None:
|
||||
self.registry.pages["test_1"] = Page(
|
||||
"test_1",
|
||||
@@ -329,6 +359,11 @@ class TestRegistry(BaseTestCase):
|
||||
self.seal_mocks()
|
||||
self.assertEqual(self.registry.get_from_host("host_1"), target)
|
||||
|
||||
def test_get_from_host_not_ready(self) -> None:
|
||||
self.registry.pages["test_1"] = Page("test_1", host="host_1", ready=False)
|
||||
self.seal_mocks()
|
||||
self.assertIsNone(self.registry.get_from_host("host_1"))
|
||||
|
||||
def test_get_from_host_not_found(self) -> None:
|
||||
self.registry.pages["test_1"] = Page("test_1", host="host_1")
|
||||
self.registry.pages["test_2"] = Page("test_2", host="host_2")
|
||||
|
||||
Reference in New Issue
Block a user