Optimize server startup speed, client update caching, and HTTP 304 conditional downloads
CI Test Suite / Run Component Tests & Pipeline Verification (push) Failing after 1m28s
CI Test Suite / Run Component Tests & Pipeline Verification (push) Failing after 1m28s
This commit is contained in:
+47
-2
@@ -137,11 +137,34 @@ class TestUpdateSystem(unittest.TestCase):
|
||||
self.assertEqual(chk_resp["latest_version"], "0.3.6.0")
|
||||
|
||||
# 4. Download package endpoint
|
||||
dl_resp = Server.download_client_update_package(os="windows")
|
||||
from starlette.requests import Request as StarletteRequest
|
||||
req_scope = {
|
||||
"type": "http",
|
||||
"method": "GET",
|
||||
"path": "/api/client/update/download",
|
||||
"headers": [],
|
||||
"query_string": b"os=windows"
|
||||
}
|
||||
init_req = StarletteRequest(req_scope)
|
||||
dl_resp = Server.download_client_update_package(request=init_req, os="windows")
|
||||
self.assertEqual(dl_resp.status_code, 200)
|
||||
self.assertIn("X-Checksum-SHA256", dl_resp.headers)
|
||||
self.assertIn("ETag", dl_resp.headers)
|
||||
etag = dl_resp.headers["ETag"]
|
||||
|
||||
# 5. WebUI rendering verification
|
||||
# 5. Conditional GET with ETag (304 Not Modified)
|
||||
cond_scope = {
|
||||
"type": "http",
|
||||
"method": "GET",
|
||||
"path": "/api/client/update/download",
|
||||
"headers": [(b"if-none-match", etag.encode("utf-8"))],
|
||||
"query_string": b"os=windows"
|
||||
}
|
||||
cached_req = StarletteRequest(cond_scope)
|
||||
cached_resp = Server.download_client_update_package(request=cached_req, os="windows")
|
||||
self.assertEqual(cached_resp.status_code, 304)
|
||||
|
||||
# 6. WebUI rendering verification
|
||||
# Simulate server update available
|
||||
self.update_mgr.server_update_available = True
|
||||
self.update_mgr.latest_upstream_version = "0.3.6.0"
|
||||
@@ -155,6 +178,28 @@ class TestUpdateSystem(unittest.TestCase):
|
||||
self.assertIn("tabPane-updates", html)
|
||||
self.assertIn("Client Package Distribution Repository", html)
|
||||
|
||||
def test_update_memoization_and_cache_invalidation(self):
|
||||
"""Tests that package info is served from memory cache and invalidates on update."""
|
||||
dummy_pkg = os.path.join(self.test_dir, "LOGAR_Client_Linux")
|
||||
with open(dummy_pkg, "wb") as f:
|
||||
f.write(b"LINUX_CLIENT_PAYLOAD_V1")
|
||||
|
||||
self.update_mgr.register_client_package("linux", dummy_pkg, version="0.3.6.0")
|
||||
pkgs_1 = self.update_mgr.get_hosted_packages()
|
||||
sha1 = pkgs_1["linux"]["sha256"]
|
||||
|
||||
# Repeated call should hit memory cache with identical hash
|
||||
pkgs_2 = self.update_mgr.get_hosted_packages()
|
||||
self.assertEqual(pkgs_2["linux"]["sha256"], sha1)
|
||||
|
||||
# Invalidate cache on new registration
|
||||
with open(dummy_pkg, "wb") as f:
|
||||
f.write(b"LINUX_CLIENT_PAYLOAD_V2_UPDATED")
|
||||
self.update_mgr.register_client_package("linux", dummy_pkg, version="0.3.7.0")
|
||||
pkgs_3 = self.update_mgr.get_hosted_packages()
|
||||
self.assertEqual(pkgs_3["linux"]["version"], "0.3.7.0")
|
||||
self.assertNotEqual(pkgs_3["linux"]["sha256"], sha1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user