Beispiel #1
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()
 async def create_subscription(self, params, callback=None, external=False):
     self.logger.info("create subscription")
     result = ua.CreateSubscriptionResult()
     result.RevisedPublishingInterval = params.RequestedPublishingInterval
     result.RevisedLifetimeCount = params.RequestedLifetimeCount
     result.RevisedMaxKeepAliveCount = params.RequestedMaxKeepAliveCount
     self._sub_id_counter += 1
     result.SubscriptionId = self._sub_id_counter
     internal_sub = InternalSubscription(result, self.aspace, callback=callback, no_acks=not external)
     await internal_sub.start()
     self.subscriptions[result.SubscriptionId] = internal_sub
     return result
    async def create_subscription(self, params, callback):
        self.logger.info("create subscription with callback: %s", callback)
        result = ua.CreateSubscriptionResult()
        result.RevisedPublishingInterval = params.RequestedPublishingInterval
        result.RevisedLifetimeCount = params.RequestedLifetimeCount
        result.RevisedMaxKeepAliveCount = params.RequestedMaxKeepAliveCount
        self._sub_id_counter += 1
        result.SubscriptionId = self._sub_id_counter

        sub = InternalSubscription(self, result, self.aspace, callback)
        await sub.start()
        self.subscriptions[result.SubscriptionId] = sub
        return result