Skip to content

Commit 3db0e34

Browse files
authored
Fixes flaky: test_guest_user_is_not_garbage_collected (#7609)
1 parent 85a2e9d commit 3db0e34

File tree

3 files changed

+50
-29
lines changed

3 files changed

+50
-29
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
⬆️ Upgrade dependencies.
1111
📝 Add or update documentation.
1212
🔨 Add or update development scripts.
13+
✅ Add, update or pass tests.
1314
🔒️ Fix security issues.
1415
⚠️ Changes in ops configuration etc. are required before deploying.
1516
[ Please add a link to the associated ops-issue or PR, such as in https://github.com/ITISFoundation/osparc-ops-environments or https://git.speag.com/oSparc/osparc-infra ]
@@ -28,32 +29,16 @@ or from https://gitmoji.dev/
2829

2930

3031
## Related issue/s
31-
32-
<!-- Link pull request to an issue
33-
SEE https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
34-
35-
- resolves ITISFoundation/osparc-issues#428
36-
- fixes #26
37-
-->
32+
<!-- LINK to other issues and add prefix `closes`, `fixes`, `resolves`-->
3833

3934

4035
## How to test
4136

4237
<!-- Give REVIEWERS some hits or code snippets on how could this be tested -->
4338

44-
## Dev-ops checklist
45-
46-
- [ ] No ENV changes or I properly updated ENV ([read the instruction](https://git.speag.com/oSparc/osparc-ops-deployment-configuration/-/blob/configs/README.md?ref_type=heads#how-to-update-env-variables))
47-
48-
<!-- Some checks that might help your code run stable on production, and help devops assess criticality.
49-
Modified from https://oschvr.com/posts/what-id-like-as-sre/
39+
## Dev-ops
5040

51-
- How can DevOps check the health of the service ?
52-
- How can DevOps safely and gracefully restart the service ?
53-
- How and why would this code fail ?
54-
- What kind of metrics are you exposing ?
55-
- Is there any documentation/design specification for the service ?
56-
- How (e.g. through which loglines) can DevOps detect unexpected situations that require escalation to human ?
57-
- What are the resource limitations (CPU, RAM) expected for this service ?
58-
- Are all relevant variables documented and adjustable via environment variables (i.e. no hardcoded magic numbers) ?
41+
<!--
42+
- No changes /updated ENV. SEE https://git.speag.com/oSparc/osparc-ops-deployment-configuration/-/blob/configs/README.md?ref_type=heads#how-to-update-env-variables)
43+
- SEE docs/devops-checklist.md
5944
-->

docs/devops-checklist.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Devops checklist
2+
3+
- No ENV changes or I properly updated ENV ([read the instruction](https://git.speag.com/oSparc/osparc-ops-deployment-configuration/-/blob/configs/README.md?ref_type=heads#how-to-update-env-variables))
4+
5+
- Some checks that might help your code run stable on production, and help devops assess criticality.
6+
- How can DevOps check the health of the service ?
7+
- How can DevOps safely and gracefully restart the service ?
8+
- How and why would this code fail ?
9+
- What kind of metrics are you exposing ?
10+
- Is there any documentation/design specification for the service ?
11+
- How (e.g. through which loglines) can DevOps detect unexpected situations that require escalation to human ?
12+
- What are the resource limitations (CPU, RAM) expected for this service ?
13+
- Are all relevant variables documented and adjustable via environment variables (i.e. no hardcoded magic numbers) ?
14+
15+
Ref: Modified from https://oschvr.com/posts/what-id-like-as-sre/

services/web/server/tests/unit/with_dbs/04/studies_dispatcher/test_studies_dispatcher_studies_access.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,24 @@ async def _assert_redirected_to_study(
234234
"OSPARC-SIMCORE" in content
235235
), f"Expected front-end rendering workbench's study, got {content!s}"
236236

237-
# Expects fragment to indicate client where to find newly created project
238-
m = re.match(r"/study/([\d\w-]+)", response.real_url.fragment)
239-
assert m, f"Expected /study/uuid, got {response.real_url.fragment}"
237+
# First check if the fragment indicates an error
238+
fragment = response.real_url.fragment
239+
error_match = re.match(r"/error", fragment)
240+
if error_match:
241+
# Parse query parameters to extract error details
242+
query_params = urllib.parse.parse_qs(
243+
fragment.split("?", 1)[1] if "?" in fragment else ""
244+
)
245+
error_message = query_params.get("message", ["Unknown error"])[0]
246+
error_status = query_params.get("status_code", ["Unknown"])[0]
247+
248+
pytest.fail(
249+
f"Redirected to error page: Status={error_status}, Message={error_message}"
250+
)
251+
252+
# Check for study path if not an error
253+
m = re.match(r"/study/([\d\w-]+)", fragment)
254+
assert m, f"Expected /study/uuid, got {fragment}"
240255

241256
# Expects auth cookie for current user
242257
assert _is_user_authenticated(session)
@@ -435,7 +450,17 @@ async def enforce_garbage_collect_guest(uid):
435450

436451

437452
@pytest.mark.flaky(max_runs=3)
438-
@pytest.mark.parametrize("number_of_simultaneous_requests", [1, 2, 32])
453+
@pytest.mark.parametrize(
454+
"number_of_simultaneous_requests",
455+
[
456+
1,
457+
2,
458+
16,
459+
# NOTE: The number of simultaneous anonymous users is limited by system load.
460+
# A GuestUsersLimitError is raised if user creation exceeds the MAX_DELAY_TO_CREATE_USER threshold.
461+
# This test is flaky due to its dependency on app runtime conditions. Avoid increasing simultaneous requests.
462+
],
463+
)
439464
async def test_guest_user_is_not_garbage_collected(
440465
number_of_simultaneous_requests: int,
441466
web_server: TestServer,
@@ -454,9 +479,6 @@ async def test_guest_user_is_not_garbage_collected(
454479

455480
async def _test_guest_user_workflow(request_index):
456481
print("request #", request_index, "-" * 10)
457-
458-
# TODO: heartbeat is missing here!
459-
# TODO: reduce GC activation period to 0.1 secs
460482
# every guest uses different client to preserve it's own authorization/authentication cookies
461483
client: TestClient = await aiohttp_client(web_server)
462484
assert client.app
@@ -495,5 +517,4 @@ async def _test_guest_user_workflow(request_index):
495517
]
496518

497519
await asyncio.gather(*request_tasks)
498-
499520
# and now the garbage collector shall delete our users since we are done...

0 commit comments

Comments
 (0)