Skip to content

Commit 5a93e65

Browse files
committed
Fix _ensure_test_user catching only NextcloudError, not TimeoutError/OSError
1 parent 5413e0d commit 5a93e65

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

tests/integration/test_user_permissions.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
errors instead of crashing or leaking data.
66
"""
77

8+
import asyncio
89
import json
910
import os
1011
from collections.abc import AsyncGenerator
1112

1213
import pytest
1314
from mcp.server.fastmcp.exceptions import ToolError
15+
from urllib3.exceptions import MaxRetryError
1416

1517
from nc_mcp_server.client import NextcloudClient, NextcloudError
1618
from nc_mcp_server.config import Config
@@ -28,17 +30,33 @@
2830

2931
@pytest.fixture(scope="module")
3032
async def _ensure_test_user() -> None:
31-
"""Create the test user via admin client if it doesn't exist."""
33+
"""Create the test user via admin client if it doesn't exist.
34+
35+
Retries the entire operation to handle slow container startup in CI.
36+
The niquests/urllib3 stack may raise TimeoutError, OSError, or
37+
urllib3.exceptions.MaxRetryError (which is none of the above),
38+
so we catch Exception and retry on any connection-level failure.
39+
"""
3240
admin_config = Config(
3341
nextcloud_url=os.environ.get("NEXTCLOUD_URL", "http://nextcloud.ncmcp"),
3442
user=os.environ.get("NEXTCLOUD_USER", "admin"),
3543
password=os.environ.get("NEXTCLOUD_PASSWORD", "admin"),
3644
)
3745
client = NextcloudClient(admin_config)
38-
try:
39-
await client.ocs_get(f"cloud/users/{TEST_USER}")
40-
except NextcloudError:
41-
await client.ocs_post("cloud/users", data={"userid": TEST_USER, "password": TEST_PASS})
46+
last_err: Exception | None = None
47+
for attempt in range(10):
48+
try:
49+
await client.ocs_get(f"cloud/users/{TEST_USER}")
50+
break
51+
except NextcloudError:
52+
await client.ocs_post("cloud/users", data={"userid": TEST_USER, "password": TEST_PASS})
53+
break
54+
except (OSError, TimeoutError, MaxRetryError) as exc:
55+
last_err = exc
56+
if attempt < 9:
57+
await asyncio.sleep(3)
58+
continue
59+
raise last_err from exc
4260
await client.close()
4361

4462

0 commit comments

Comments
 (0)