|
51 | 51 | encode_b64j, |
52 | 52 | execute_job, |
53 | 53 | handle_endpoint_invocation_event, |
| 54 | + handle_endpoint_status_event, |
54 | 55 | parse_endpoint_invocation_outputs, |
55 | 56 | preload_interactive_algorithms, |
56 | 57 | remove_container_image_from_registry, |
@@ -1661,6 +1662,88 @@ def test_stop_expired_endpoints( |
1661 | 1662 | assert endpoint_to_stop.status == EndpointStatusChoices.STOPPED |
1662 | 1663 |
|
1663 | 1664 |
|
| 1665 | +@pytest.mark.django_db |
| 1666 | +def test_handle_endpoint_status_in_service_event(settings): |
| 1667 | + endpoint = EndpointFactory( |
| 1668 | + status=EndpointStatusChoices.STARTING, |
| 1669 | + ) |
| 1670 | + event = { |
| 1671 | + "EndpointName": f"{settings.COMPONENTS_REGISTRY_PREFIX}-AE-{endpoint.pk}", |
| 1672 | + "EndpointStatus": "IN_SERVICE", |
| 1673 | + } |
| 1674 | + |
| 1675 | + handle_endpoint_status_event(event=event) |
| 1676 | + endpoint.refresh_from_db() |
| 1677 | + |
| 1678 | + assert endpoint.status == EndpointStatusChoices.RUNNING |
| 1679 | + |
| 1680 | + |
| 1681 | +@pytest.mark.django_db |
| 1682 | +def test_handle_endpoint_status_failed_events(settings, mocker): |
| 1683 | + endpoint = EndpointFactory( |
| 1684 | + status=EndpointStatusChoices.STARTING, |
| 1685 | + ) |
| 1686 | + event = { |
| 1687 | + "EndpointName": f"{settings.COMPONENTS_REGISTRY_PREFIX}-AE-{endpoint.pk}", |
| 1688 | + "EndpointStatus": "FAILED", |
| 1689 | + } |
| 1690 | + mock_deprovision = mocker.patch.object( |
| 1691 | + EndpointOrchestrator, |
| 1692 | + "deprovision", |
| 1693 | + ) |
| 1694 | + |
| 1695 | + handle_endpoint_status_event(event=event) |
| 1696 | + endpoint.refresh_from_db() |
| 1697 | + |
| 1698 | + mock_deprovision.assert_called_once() |
| 1699 | + assert endpoint.status == EndpointStatusChoices.FAILED |
| 1700 | + assert endpoint.error_message == SystemErrorMessages.UNEXPECTED_ERROR |
| 1701 | + |
| 1702 | + |
| 1703 | +@pytest.mark.django_db |
| 1704 | +def test_handle_endpoint_status_invalid_events(settings, mocker): |
| 1705 | + endpoint = EndpointFactory( |
| 1706 | + status=EndpointStatusChoices.STARTING, |
| 1707 | + ) |
| 1708 | + event = { |
| 1709 | + "EndpointName": f"{settings.COMPONENTS_REGISTRY_PREFIX}-AE-{endpoint.pk}", |
| 1710 | + "EndpointStatus": "some invalid status", |
| 1711 | + } |
| 1712 | + mock_deprovision = mocker.patch.object( |
| 1713 | + EndpointOrchestrator, |
| 1714 | + "deprovision", |
| 1715 | + ) |
| 1716 | + |
| 1717 | + handle_endpoint_status_event(event=event) |
| 1718 | + endpoint.refresh_from_db() |
| 1719 | + |
| 1720 | + mock_deprovision.assert_called_once() |
| 1721 | + assert endpoint.status == EndpointStatusChoices.FAILED |
| 1722 | + assert endpoint.error_message == SystemErrorMessages.UNEXPECTED_ERROR |
| 1723 | + |
| 1724 | + |
| 1725 | +@pytest.mark.parametrize( |
| 1726 | + "status", |
| 1727 | + set(EndpointStatusChoices).difference([EndpointStatusChoices.STARTING]), |
| 1728 | +) |
| 1729 | +@pytest.mark.django_db |
| 1730 | +def test_handle_endpoint_status_wrong_state_ignored(mocker, settings, status): |
| 1731 | + endpoint = EndpointFactory(status=status) |
| 1732 | + event = { |
| 1733 | + "EndpointName": f"{settings.COMPONENTS_REGISTRY_PREFIX}-AE-{endpoint.pk}", |
| 1734 | + } |
| 1735 | + mock_handle_status_event = mocker.patch.object( |
| 1736 | + EndpointOrchestrator, |
| 1737 | + "handle_status_event", |
| 1738 | + ) |
| 1739 | + |
| 1740 | + handle_endpoint_status_event(event=event) |
| 1741 | + endpoint.refresh_from_db() |
| 1742 | + |
| 1743 | + mock_handle_status_event.assert_not_called() |
| 1744 | + assert endpoint.status == status |
| 1745 | + |
| 1746 | + |
1664 | 1747 | @pytest.mark.django_db |
1665 | 1748 | def test_handle_endpoint_invocation_completed_event(settings): |
1666 | 1749 | invocation = InvocationFactory( |
|
0 commit comments