Skip to content

Commit efddc55

Browse files
committed
Test restarting channelfinder works ok
1 parent e663296 commit efddc55

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

server/tests/docker.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ def restart_container(compose: DockerCompose, host_name: str) -> None:
4747
docker_client = DockerClient()
4848
docker_client.containers.get(container.ID).stop()
4949
docker_client.containers.get(container.ID).start()
50+
51+
52+
def shutdown_container(compose: DockerCompose, host_name: str) -> None:
53+
container = compose.get_container(host_name)
54+
docker_client = DockerClient()
55+
docker_client.containers.get(container.ID).stop()

server/tests/test_restart.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
from channelfinder import ChannelFinderClient
55
from testcontainers.compose import DockerCompose
66

7-
from .client_checks import channels_match, check_channel_property, create_client_and_wait, wait_for_sync
8-
from .docker import restart_container, setup_compose # noqa: F401
7+
from .client_checks import (
8+
INACTIVE_PROPERTY,
9+
channels_match,
10+
check_channel_property,
11+
create_client_and_wait,
12+
wait_for_sync,
13+
)
14+
from .docker import restart_container, setup_compose, shutdown_container # noqa: F401
915

1016
PROPERTIES_TO_MATCH = ["pvStatus", "recordType", "recordDesc", "alias", "hostName", "iocName", "recceiverID"]
1117

@@ -45,3 +51,27 @@ def test_manual_channels_same_after_restart(
4551
channels_end = cf_client.find(name="*")
4652
assert len(channels_begin) == len(channels_end)
4753
channels_match(channels_begin, channels_end, PROPERTIES_TO_MATCH + ["test_property"])
54+
55+
56+
def check_connection_active(cf_client: ChannelFinderClient) -> bool:
57+
try:
58+
cf_client.find(name="*")
59+
return True
60+
except Exception:
61+
return False
62+
63+
64+
class TestRestartChannelFinder:
65+
def test_channels_same_after_restart(self, setup_compose: DockerCompose, cf_client: ChannelFinderClient) -> None: # noqa: F811
66+
channels_begin = cf_client.find(name="*")
67+
restart_container(setup_compose, "cf")
68+
assert wait_for_sync(cf_client, check_connection_active)
69+
channels_end = cf_client.find(name="*")
70+
assert len(channels_begin) == len(channels_end)
71+
channels_match(channels_begin, channels_end, PROPERTIES_TO_MATCH)
72+
shutdown_container(setup_compose, "ioc1-1")
73+
assert wait_for_sync(
74+
cf_client, lambda cf_client: check_channel_property(cf_client, "IOC1-1:Msg-I", INACTIVE_PROPERTY)
75+
)
76+
channels_inactive = cf_client.find(property=[("iocName", "IOC1-1")])
77+
assert all(INACTIVE_PROPERTY in ch["properties"] for ch in channels_inactive)

0 commit comments

Comments
 (0)