Skip to content

Commit 32866a5

Browse files
committed
test(flagd): wait for the provider before evaluating under openfeature-sdk 0.10
The TCK moves the workspace lock to openfeature-sdk 0.10, where api.set_provider initialises on a background thread. These tests set a provider and evaluated straight away, so they read PROVIDER_NOT_READY and the caller's default: the FLAG_NOT_FOUND, PARSE_ERROR, DISABLED and metadata assertions all failed, and the deadline test timed a call that no longer blocks. They now use set_provider_and_wait, which raises where initialisation is meant to fail. Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
1 parent 0195e64 commit 32866a5

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎providers/openfeature-provider-flagd/tests/test_errors.py‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import os
23
import time
34

@@ -8,12 +9,14 @@
89
from openfeature.contrib.provider.flagd.config import ResolverType
910
from openfeature.evaluation_context import EvaluationContext
1011
from openfeature.event import ProviderEvent
11-
from openfeature.exception import ErrorCode
12+
from openfeature.exception import ErrorCode, OpenFeatureError
1213
from openfeature.flag_evaluation import Reason
1314

1415

1516
def create_client(provider: FlagdProvider):
16-
api.set_provider(provider)
17+
# Several of these files fail initialisation on purpose, which raises here.
18+
with contextlib.suppress(OpenFeatureError):
19+
api.set_provider_and_wait(provider)
1720
return api.get_client()
1821

1922

@@ -128,13 +131,14 @@ def fail(*args, **kwargs):
128131
api.get_client().add_handler(ProviderEvent.PROVIDER_ERROR, fail)
129132

130133
t = time.time()
131-
api.set_provider(
132-
FlagdProvider(
133-
resolver_type=ResolverType.IN_PROCESS,
134-
port=99999, # dead port to test failure
135-
deadline_ms=wait,
134+
with pytest.raises(OpenFeatureError):
135+
api.set_provider_and_wait(
136+
FlagdProvider(
137+
resolver_type=ResolverType.IN_PROCESS,
138+
port=99999, # dead port to test failure
139+
deadline_ms=wait,
140+
)
136141
)
137-
)
138142

139143
elapsed = time.time() - t
140144
assert abs(elapsed - wait * 0.001) < 0.17

‎providers/openfeature-provider-flagd/tests/test_metadata.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import os
23
import time
34
from time import sleep
@@ -11,7 +12,7 @@
1112
_validate_metadata,
1213
)
1314
from openfeature.event import EventDetails, ProviderEvent
14-
from openfeature.exception import ErrorCode, ParseError
15+
from openfeature.exception import ErrorCode, OpenFeatureError, ParseError
1516

1617

1718
def create_client(file_name):
@@ -21,7 +22,9 @@ def create_client(file_name):
2122
offline_flag_source_path=f"{path}/{file_name}",
2223
)
2324

24-
api.set_provider(provider)
25+
# The invalid-metadata files fail initialisation on purpose, which raises here.
26+
with contextlib.suppress(OpenFeatureError):
27+
api.set_provider_and_wait(provider)
2528
return api.get_client()
2629

2730

0 commit comments

Comments
 (0)