Skip to content

Commit ee32cd7

Browse files
committed
fixup: make tests run, only 4 tests are missing now
Signed-off-by: Simon Schrottner <[email protected]>
1 parent 7fbc770 commit ee32cd7

File tree

6 files changed

+296
-63
lines changed

6 files changed

+296
-63
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "providers/openfeature-provider-flagd/test-harness"]
55
path = providers/openfeature-provider-flagd/test-harness
66
url = [email protected]:open-feature/flagd-testbed.git
7+
[submodule "providers/openfeature-provider-flagd/spec"]
8+
path = providers/openfeature-provider-flagd/spec
9+
url = https://github.com/open-feature/spec

providers/openfeature-provider-flagd/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ dependencies = [
3737
"coverage[toml]>=6.5",
3838
"pytest",
3939
"pytest-bdd",
40+
"testcontainers",
41+
"asserts",
42+
"grpcio-health-checking==1.60.0",
4043
]
4144
post-install-commands = [
4245
"./scripts/gen_protos.sh"
Submodule spec added at 3c737a6
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from time import sleep
2+
3+
import grpc
4+
from grpc_health.v1 import health_pb2, health_pb2_grpc
5+
from testcontainers.core.container import DockerContainer
6+
from testcontainers.core.waiting_utils import wait_container_is_ready, wait_for_logs
7+
8+
HEALTH_CHECK = 8014
9+
10+
11+
class FlagDContainer(DockerContainer):
12+
def __init__(
13+
self,
14+
image: str = "ghcr.io/open-feature/flagd-testbed:v0.5.10",
15+
port: int = 8013,
16+
**kwargs,
17+
) -> None:
18+
super().__init__(image, **kwargs)
19+
self.port = port
20+
self.with_exposed_ports(self.port, HEALTH_CHECK)
21+
22+
def start(self) -> "FlagDContainer":
23+
super().start()
24+
self._checker()
25+
return self
26+
27+
@wait_container_is_ready(ConnectionError)
28+
def _checker(self) -> None:
29+
# First we wait for Flagd to say it's listening
30+
wait_for_logs(
31+
self,
32+
"Flag IResolver listening at",
33+
5,
34+
)
35+
36+
host, port = self.get_container_host_ip(), self.get_exposed_port(HEALTH_CHECK)
37+
38+
# Second we use the GRPC health check endpoint
39+
with grpc.insecure_channel(host + ":" + port) as channel:
40+
health_stub = health_pb2_grpc.HealthStub(channel)
41+
42+
def health_check_call(stub: health_pb2_grpc.HealthStub):
43+
request = health_pb2.HealthCheckRequest()
44+
resp = stub.Check(request)
45+
if resp.status == health_pb2.HealthCheckResponse.SERVING:
46+
return True
47+
elif resp.status == health_pb2.HealthCheckResponse.NOT_SERVING:
48+
return False
49+
50+
# Should succeed
51+
# Check health status every 1 second for 30 seconds
52+
ok = False
53+
for _ in range(30):
54+
ok = health_check_call(health_stub)
55+
if ok:
56+
break
57+
sleep(1)
58+
59+
if not ok:
60+
raise ConnectionError("flagD not ready in time")

0 commit comments

Comments
 (0)