Skip to content

Commit 8324d04

Browse files
committed
fix(provider-tck): make ready_timeout actually bound initialisation
TckConfig.ready_timeout was documented but never read by anything, so a provider that hung while connecting would hang the whole pytest session with no useful message, and the documented knob did nothing. api.set_provider initialises synchronously and has no timeout of its own, so the bound comes from running it on a worker thread and giving up on the result. The worker is deliberately not cancelled -- Python cannot interrupt a thread blocked in a socket call -- and is left to finish or die with the process, which is acceptable because a timeout already means the scenario is failing. A config field that claims to do something it does not is exactly the kind of quiet untruth this suite exists to catch, so it is fixed rather than removed. Verified: 56 passed, 7 skipped, 2 xfailed; ruff and mypy --strict clean. Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
1 parent 2ffd333 commit 8324d04

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

  • tools/openfeature-provider-tck/src/openfeature/contrib/tools/provider_tck/steps

‎tools/openfeature-provider-tck/src/openfeature/contrib/tools/provider_tck/steps/provider_steps.py‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
from __future__ import annotations
44

5+
import concurrent.futures
56
import contextlib
67

78
from pytest_bdd import given, parsers
89

910
from openfeature import api
11+
from openfeature.provider import FeatureProvider
1012

1113
from ..state import TckState
1214

@@ -30,7 +32,14 @@ def a_stable_provider(tck_state: TckState) -> None:
3032
raise AssertionError(msg)
3133

3234
try:
33-
api.set_provider(provider, config.domain)
35+
_set_provider_within(provider, config.domain, config.ready_timeout)
36+
except TimeoutError:
37+
msg = (
38+
f"the provider did not become ready within {config.ready_timeout}s. The backend "
39+
f"is up and seeded at this point, so either initialisation is genuinely hanging "
40+
f"or TckConfig.ready_timeout is too short"
41+
)
42+
raise AssertionError(msg) from None
3443
except Exception as exc:
3544
msg = (
3645
f"registering the provider raised {exc!r}. The backend is up and seeded "
@@ -79,3 +88,27 @@ def an_unavailable_provider(tck_state: TckState) -> None:
7988
api.set_provider(provider, config.domain)
8089

8190
tck_state.client = api.get_client(config.domain)
91+
92+
93+
def _set_provider_within(
94+
provider: FeatureProvider, domain: str, timeout: float
95+
) -> None:
96+
"""Register a provider, giving up if initialisation has not returned in time.
97+
98+
``api.set_provider`` initialises synchronously and has no timeout of its own, so a
99+
provider that hangs while connecting would hang the whole session with no useful
100+
message. Running it on a worker thread bounds it.
101+
102+
The worker is deliberately not cancelled on timeout -- Python cannot interrupt a
103+
thread blocked in a socket call -- so it is left to finish or die with the process.
104+
That is acceptable here because a timeout already means the scenario is failing.
105+
"""
106+
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool:
107+
future = pool.submit(api.set_provider, provider, domain)
108+
try:
109+
future.result(timeout=timeout)
110+
except concurrent.futures.TimeoutError:
111+
raise TimeoutError from None
112+
finally:
113+
# Do not block __exit__ on a worker that is still stuck.
114+
pool.shutdown(wait=False)

0 commit comments

Comments
 (0)