|
1 | 1 | import logging |
| 2 | +import time |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 | from channelfinder import ChannelFinderClient |
5 | 6 | from testcontainers.compose import DockerCompose |
6 | 7 |
|
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 |
| 8 | +from .client_checks import ( |
| 9 | + INACTIVE_PROPERTY, |
| 10 | + channels_match, |
| 11 | + check_channel_property, |
| 12 | + create_client_and_wait, |
| 13 | + wait_for_sync, |
| 14 | +) |
| 15 | +from .docker import restart_container, setup_compose, shutdown_container, start_container # noqa: F401 |
9 | 16 |
|
10 | 17 | PROPERTIES_TO_MATCH = ["pvStatus", "recordType", "recordDesc", "alias", "hostName", "iocName", "recceiverID"] |
11 | 18 |
|
@@ -45,3 +52,55 @@ def test_manual_channels_same_after_restart( |
45 | 52 | channels_end = cf_client.find(name="*") |
46 | 53 | assert len(channels_begin) == len(channels_end) |
47 | 54 | channels_match(channels_begin, channels_end, PROPERTIES_TO_MATCH + ["test_property"]) |
| 55 | + |
| 56 | + |
| 57 | +def check_connection_active(cf_client: ChannelFinderClient) -> bool: |
| 58 | + try: |
| 59 | + cf_client.find(name="*") |
| 60 | + except Exception: |
| 61 | + return False |
| 62 | + return True |
| 63 | + |
| 64 | + |
| 65 | +class TestRestartChannelFinder: |
| 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 |
| 73 | + restart_container(setup_compose, "cf") |
| 74 | + assert wait_for_sync(cf_client, check_connection_active) |
| 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 | + |
| 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