Skip to content

Commit e497561

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

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

server/tests/docker.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,9 @@ def shutdown_container(compose: DockerCompose, host_name: str) -> None:
5353
container = compose.get_container(host_name)
5454
docker_client = DockerClient()
5555
docker_client.containers.get(container.ID).stop()
56+
57+
58+
def start_container(compose: DockerCompose, host_name: str) -> None:
59+
container = compose.get_container(host_name)
60+
docker_client = DockerClient()
61+
docker_client.containers.get(container.ID).start()

server/tests/test_restart.py

Lines changed: 33 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,14 +63,40 @@ 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
77+
shutdown_container(setup_compose, "ioc1-1")
78+
assert wait_for_sync(
79+
cf_client, lambda cf_client: check_channel_property(cf_client, "IOC1-1:Msg-I", INACTIVE_PROPERTY)
80+
)
81+
channels_inactive = cf_client.find(property=[("iocName", "IOC1-1")])
82+
assert all(INACTIVE_PROPERTY in ch["properties"] for ch in channels_inactive)
83+
84+
def test_status_property_works_between_cf_down(
85+
self,
86+
setup_compose: DockerCompose, # noqa: F811
87+
cf_client: ChannelFinderClient,
88+
) -> None:
89+
# Arrange
90+
shutdown_container(setup_compose, "cf")
91+
time.sleep(10) # Wait to ensure CF is down while IOC is down
92+
93+
# Act
7294
shutdown_container(setup_compose, "ioc1-1")
95+
time.sleep(10) # Wait to ensure CF is down while IOC is down
96+
start_container(setup_compose, "cf")
97+
assert wait_for_sync(cf_client, check_connection_active)
98+
99+
# Assert
73100
assert wait_for_sync(
74101
cf_client, lambda cf_client: check_channel_property(cf_client, "IOC1-1:Msg-I", INACTIVE_PROPERTY)
75102
)

0 commit comments

Comments
 (0)