Skip to content

Commit 718b7d4

Browse files
committed
Cover case where ioc stops while channelfinder down
1 parent 8fd9423 commit 718b7d4

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

server/tests/docker.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,23 @@ def setup_compose():
4242
compose.stop()
4343

4444

45-
def restart_container(compose: DockerCompose, host_name: str) -> None:
45+
def restart_container(compose: DockerCompose, host_name: str) -> str:
4646
container = compose.get_container(host_name)
4747
docker_client = DockerClient()
4848
docker_client.containers.get(container.ID).stop()
4949
docker_client.containers.get(container.ID).start()
50+
return container.ID
5051

5152

52-
def shutdown_container(compose: DockerCompose, host_name: str) -> None:
53+
def shutdown_container(compose: DockerCompose, host_name: str) -> str:
5354
container = compose.get_container(host_name)
5455
docker_client = DockerClient()
5556
docker_client.containers.get(container.ID).stop()
57+
return container.ID
58+
59+
60+
def start_container(compose: DockerCompose, host_name: str | None = None, container_id: str | None = None) -> None:
61+
container_id = container_id or compose.get_container(host_name).ID
62+
if container_id:
63+
docker_client = DockerClient()
64+
docker_client.containers.get(container_id).start()

server/tests/test_restart.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import time
23

34
import pytest
45
from channelfinder import ChannelFinderClient
@@ -11,7 +12,7 @@
1112
create_client_and_wait,
1213
wait_for_sync,
1314
)
14-
from .docker import restart_container, setup_compose, shutdown_container # noqa: F401
15+
from .docker import restart_container, setup_compose, shutdown_container, start_container # noqa: F401
1516

1617
PROPERTIES_TO_MATCH = ["pvStatus", "recordType", "recordDesc", "alias", "hostName", "iocName", "recceiverID"]
1718

@@ -62,16 +63,44 @@ def check_connection_active(cf_client: ChannelFinderClient) -> bool:
6263

6364

6465
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="*")
66+
def test_status_property_works_after_cf_restart(
67+
self,
68+
setup_compose: DockerCompose, # noqa: F811
69+
cf_client: ChannelFinderClient,
70+
) -> None:
71+
# Arrange
72+
# Act
6773
restart_container(setup_compose, "cf")
6874
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)
75+
76+
# Assert
7277
shutdown_container(setup_compose, "ioc1-1")
7378
assert wait_for_sync(
7479
cf_client, lambda cf_client: check_channel_property(cf_client, "IOC1-1:Msg-I", INACTIVE_PROPERTY)
7580
)
7681
channels_inactive = cf_client.find(property=[("iocName", "IOC1-1")])
7782
assert all(INACTIVE_PROPERTY in ch["properties"] for ch in channels_inactive)
83+
84+
85+
class TestShutdownChannelFinder:
86+
def test_status_property_works_between_cf_down(
87+
self,
88+
setup_compose: DockerCompose, # noqa: F811
89+
cf_client: ChannelFinderClient,
90+
) -> None:
91+
# Arrange
92+
cf_container_id = shutdown_container(setup_compose, "cf")
93+
time.sleep(10) # Wait to ensure CF is down while IOC is down
94+
95+
# Act
96+
shutdown_container(setup_compose, "ioc1-1")
97+
time.sleep(10) # Wait to ensure CF is down while IOC is down
98+
start_container(setup_compose, container_id=cf_container_id)
99+
assert wait_for_sync(cf_client, check_connection_active)
100+
101+
# Assert
102+
assert wait_for_sync(
103+
cf_client, lambda cf_client: check_channel_property(cf_client, "IOC1-1:Msg-I", INACTIVE_PROPERTY)
104+
)
105+
channels_inactive = cf_client.find(property=[("iocName", "IOC1-1")])
106+
assert all(INACTIVE_PROPERTY in ch["properties"] for ch in channels_inactive)

0 commit comments

Comments
 (0)