|
1 | 1 | import logging |
| 2 | +import time |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 | from channelfinder import ChannelFinderClient |
|
11 | 12 | create_client_and_wait, |
12 | 13 | wait_for_sync, |
13 | 14 | ) |
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 |
15 | 16 |
|
16 | 17 | PROPERTIES_TO_MATCH = ["pvStatus", "recordType", "recordDesc", "alias", "hostName", "iocName", "recceiverID"] |
17 | 18 |
|
@@ -62,16 +63,44 @@ def check_connection_active(cf_client: ChannelFinderClient) -> bool: |
62 | 63 |
|
63 | 64 |
|
64 | 65 | 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 |
67 | 73 | restart_container(setup_compose, "cf") |
68 | 74 | 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 |
72 | 77 | shutdown_container(setup_compose, "ioc1-1") |
73 | 78 | assert wait_for_sync( |
74 | 79 | cf_client, lambda cf_client: check_channel_property(cf_client, "IOC1-1:Msg-I", INACTIVE_PROPERTY) |
75 | 80 | ) |
76 | 81 | channels_inactive = cf_client.find(property=[("iocName", "IOC1-1")]) |
77 | 82 | 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