Esempio n. 1
0
 def get_subscription_revised_params(
     self,
     params: ua.CreateSubscriptionParameters,
     results: ua.CreateSubscriptionResult,
 ) -> None:
     if (results.RevisedPublishingInterval
             == params.RequestedPublishingInterval and
             results.RevisedLifetimeCount == params.RequestedLifetimeCount
             and results.RevisedMaxKeepAliveCount
             == params.RequestedMaxKeepAliveCount):
         return
     _logger.warning(
         f"Revised values returned differ from subscription values: {results}"
     )
     revised_interval = results.RevisedPublishingInterval
     # Adjust the MaxKeepAliveCount based on the RevisedPublishInterval when necessary
     new_keepalive_count = self.get_keepalive_count(revised_interval)
     if (revised_interval != params.RequestedPublishingInterval
             and new_keepalive_count != params.RequestedMaxKeepAliveCount):
         _logger.info(
             f"KeepAliveCount will be updated to {new_keepalive_count} "
             f"for consistency with RevisedPublishInterval")
         modified_params = ua.ModifySubscriptionParameters()
         # copy the existing subscription parameters
         copy_dataclass_attr(params, modified_params)
         # then override with the revised values
         modified_params.RequestedMaxKeepAliveCount = new_keepalive_count
         modified_params.SubscriptionId = results.SubscriptionId
         modified_params.RequestedPublishingInterval = (
             results.RevisedPublishingInterval)
         # update LifetimeCount but chances are it will be re-revised again
         modified_params.RequestedLifetimeCount = results.RevisedLifetimeCount
         return modified_params
Esempio n. 2
0
async def test_maxkeepalive_count(opc, mocker):
    sub_handler = MySubHandler()
    client, server = opc

    period = 1
    max_keepalive_count = client.get_keepalive_count(period)
    mock_period = 500
    mock_max_keepalive_count = client.get_keepalive_count(mock_period)

    mock_response = ua.CreateSubscriptionResult(
        SubscriptionId=78,
        RevisedPublishingInterval=mock_period,
        RevisedLifetimeCount=10000,
        RevisedMaxKeepAliveCount=2700
    )
    mock_create_subscription = mocker.patch.object(
        client.uaclient,
        "create_subscription",
        new=CoroutineMock(return_value=mock_response)
    )
    mock_update_subscription = mocker.patch.object(
        client.uaclient,
        "update_subscription",
        new=CoroutineMock()
    )

    sub = await client.create_subscription(period, sub_handler)
    assert sub.parameters.RequestedMaxKeepAliveCount == mock_max_keepalive_count
    assert mock_max_keepalive_count != max_keepalive_count
    # mock point to the object at its finale state,
    # here the subscription params have already been updated
    mock_create_subscription.assert_awaited_with(
        ua.CreateSubscriptionParameters(
            RequestedPublishingInterval=mock_period,
            RequestedLifetimeCount=10000,
            RequestedMaxKeepAliveCount=mock_max_keepalive_count,
            MaxNotificationsPerPublish=10000,
            PublishingEnabled=True,
            Priority=0
        ),
        callback=mocker.ANY
    )
    mock_update_subscription.assert_awaited_with(
        ua.ModifySubscriptionParameters(
            SubscriptionId=78,
            RequestedPublishingInterval=mock_period,
            RequestedLifetimeCount=10000,
            RequestedMaxKeepAliveCount=mock_max_keepalive_count,
            MaxNotificationsPerPublish=10000
        )
    )

    # we don't update when sub params == revised params
    mock_update_subscription.reset_mock()
    mock_create_subscription.reset_mock()
    sub = await client.create_subscription(mock_period, sub_handler)
    mock_update_subscription.assert_not_called()