Procházet zdrojové kódy

Add a monitoreditem to the subscription lifetimecount test

Julius Pfrommer před 6 roky
rodič
revize
b6d6685bc6

+ 2 - 2
src/server/ua_session.c

@@ -70,7 +70,7 @@ void UA_Session_deleteMembersCleanup(UA_Session *session, UA_Server* server) {
     UA_Subscription *currents, *temps;
     LIST_FOREACH_SAFE(currents, &session->serverSubscriptions, listEntry, temps) {
         LIST_REMOVE(currents, listEntry);
-        UA_Subscription_deleteMembers(currents, server);
+        UA_Subscription_deleteMembers(server, currents);
         UA_free(currents);
     }
     UA_PublishResponseEntry *entry;
@@ -129,7 +129,7 @@ void UA_Session_addSubscription(UA_Session *session, UA_Subscription *newSubscri
 static void
 removeSubscriptionCallback(UA_Server *server, void *data) {
     UA_Subscription *sub = (UA_Subscription*)data;
-    UA_Subscription_deleteMembers(sub, server);
+    UA_Subscription_deleteMembers(server, sub);
     UA_free(sub);
 }
 

+ 10 - 7
src/server/ua_subscription.c

@@ -37,26 +37,29 @@ UA_Subscription_new(UA_Session *session, UA_UInt32 subscriptionId) {
 }
 
 void
-UA_Subscription_deleteMembers(UA_Subscription *subscription, UA_Server *server) {
-    Subscription_unregisterPublishCallback(server, subscription);
+UA_Subscription_deleteMembers(UA_Server *server, UA_Subscription *sub) {
+    UA_LOG_DEBUG_SESSION(server->config.logger, sub->session,
+                         "Subscription %u | Delete the subscription",
+                         sub->subscriptionId);
+
+    Subscription_unregisterPublishCallback(server, sub);
 
     /* Delete monitored Items */
     UA_MonitoredItem *mon, *tmp_mon;
-    LIST_FOREACH_SAFE(mon, &subscription->monitoredItems,
-                      listEntry, tmp_mon) {
+    LIST_FOREACH_SAFE(mon, &sub->monitoredItems, listEntry, tmp_mon) {
         LIST_REMOVE(mon, listEntry);
         MonitoredItem_delete(server, mon);
     }
 
     /* Delete Retransmission Queue */
     UA_NotificationMessageEntry *nme, *nme_tmp;
-    TAILQ_FOREACH_SAFE(nme, &subscription->retransmissionQueue,
+    TAILQ_FOREACH_SAFE(nme, &sub->retransmissionQueue,
                        listEntry, nme_tmp) {
-        TAILQ_REMOVE(&subscription->retransmissionQueue, nme, listEntry);
+        TAILQ_REMOVE(&sub->retransmissionQueue, nme, listEntry);
         UA_NotificationMessage_deleteMembers(&nme->message);
         UA_free(nme);
     }
-    subscription->retransmissionQueueSize = 0;
+    sub->retransmissionQueueSize = 0;
 }
 
 UA_MonitoredItem *

+ 1 - 1
src/server/ua_subscription.h

@@ -142,7 +142,7 @@ struct UA_Subscription {
 };
 
 UA_Subscription * UA_Subscription_new(UA_Session *session, UA_UInt32 subscriptionId);
-void UA_Subscription_deleteMembers(UA_Subscription *subscription, UA_Server *server);
+void UA_Subscription_deleteMembers(UA_Server *server, UA_Subscription *subscription);
 UA_StatusCode Subscription_registerPublishCallback(UA_Server *server, UA_Subscription *sub);
 UA_StatusCode Subscription_unregisterPublishCallback(UA_Server *server, UA_Subscription *sub);
 

+ 6 - 0
src/server/ua_subscription_datachange.c

@@ -32,6 +32,12 @@ UA_MonitoredItem_new(UA_MonitoredItemType monType) {
 
 void
 MonitoredItem_delete(UA_Server *server, UA_MonitoredItem *monitoredItem) {
+    UA_Subscription *sub = monitoredItem->subscription;
+    UA_LOG_WARNING_SESSION(server->config.logger, sub->session,
+                           "Subscription %u | MonitoredItem %i | "
+                           "Delete the MonitoredItem",
+                           sub->subscriptionId, monitoredItem->itemId);
+
     if(monitoredItem->monitoredItemType == UA_MONITOREDITEMTYPE_CHANGENOTIFY) {
         /* Remove the sampling callback */
         MonitoredItem_unregisterSampleCallback(server, monitoredItem);

+ 44 - 11
tests/server/check_services_subscriptions.c

@@ -533,17 +533,49 @@ START_TEST(Server_lifeTimeCount) {
     Service_CreateSubscription(server, &adminSession, &request, &response);
     ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
     ck_assert_uint_eq(response.revisedMaxKeepAliveCount, 2);
-    /* revisedLifetimeCount is revised to 3*MaxKeepAliveCount */
+    /* revisedLifetimeCount is revised to 3*MaxKeepAliveCount == 3 */
     ck_assert_uint_eq(response.revisedLifetimeCount, 6);
     UA_Double publishingInterval = response.revisedPublishingInterval;
     ck_assert(publishingInterval > 0.0f);
+    subscriptionId = response.subscriptionId;
     UA_CreateSubscriptionResponse_deleteMembers(&response);
 
-    UA_Server_run_iterate(server, false);
+    /* Add a MonitoredItem to the second subscription */
+    UA_CreateMonitoredItemsRequest mrequest;
+    UA_CreateMonitoredItemsRequest_init(&mrequest);
+    mrequest.subscriptionId = subscriptionId;
+    mrequest.timestampsToReturn = UA_TIMESTAMPSTORETURN_SERVER;
+    UA_MonitoredItemCreateRequest item;
+    UA_MonitoredItemCreateRequest_init(&item);
+    UA_ReadValueId rvi;
+    UA_ReadValueId_init(&rvi);
+    rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER);
+    rvi.attributeId = UA_ATTRIBUTEID_BROWSENAME;
+    rvi.indexRange = UA_STRING_NULL;
+    item.itemToMonitor = rvi;
+    item.requestedParameters.samplingInterval = publishingInterval / 5.0;
+    item.monitoringMode = UA_MONITORINGMODE_REPORTING;
+    UA_MonitoringParameters params;
+    UA_MonitoringParameters_init(&params);
+    item.requestedParameters = params;
+    mrequest.itemsToCreateSize = 1;
+    mrequest.itemsToCreate = &item;
+
+    UA_CreateMonitoredItemsResponse mresponse;
+    UA_CreateMonitoredItemsResponse_init(&mresponse);
+    Service_CreateMonitoredItems(server, &adminSession, &mrequest, &mresponse);
+    ck_assert_uint_eq(mresponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
+    ck_assert_uint_eq(mresponse.resultsSize, 1);
+    ck_assert_uint_eq(mresponse.results[0].statusCode, UA_STATUSCODE_GOOD);
+    monitoredItemId = mresponse.results[0].monitoredItemId;
+    ck_assert_uint_gt(monitoredItemId, 0);
+    UA_MonitoredItemCreateRequest_deleteMembers(&item);
+    UA_CreateMonitoredItemsResponse_deleteMembers(&mresponse);
 
+    UA_Server_run_iterate(server, false);
     UA_UInt32 count = 0;
     UA_Subscription *sub;
-    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
+    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry) {
         ck_assert_uint_eq(sub->currentLifetimeCount, 0);
         count++;
     }
@@ -553,7 +585,7 @@ START_TEST(Server_lifeTimeCount) {
     UA_Server_run_iterate(server, false);
 
     count = 0;
-    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
+    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry) {
         ck_assert_uint_eq(sub->currentLifetimeCount, 1);
         count++;
     }
@@ -564,7 +596,7 @@ START_TEST(Server_lifeTimeCount) {
     UA_Server_run_iterate(server, false);
 
     count = 0;
-    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
+    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry) {
         ck_assert_uint_eq(sub->currentLifetimeCount, 2);
         count++;
     }
@@ -575,7 +607,7 @@ START_TEST(Server_lifeTimeCount) {
     UA_Server_run_iterate(server, false);
 
     count = 0;
-    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
+    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry) {
         ck_assert_uint_eq(sub->currentLifetimeCount, 3);
         count++;
     }
@@ -586,7 +618,7 @@ START_TEST(Server_lifeTimeCount) {
     UA_Server_run_iterate(server, false);
 
     count = 0;
-    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
+    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry) {
         ck_assert_uint_eq(sub->currentLifetimeCount, 4);
         count++;
     }
@@ -597,7 +629,7 @@ START_TEST(Server_lifeTimeCount) {
     UA_Server_run_iterate(server, false);
 
     count = 0;
-    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
+    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry) {
         ck_assert_uint_eq(sub->currentLifetimeCount, 5);
         count++;
     }
@@ -608,18 +640,19 @@ START_TEST(Server_lifeTimeCount) {
     UA_Server_run_iterate(server, false);
 
     count = 0;
-    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
+    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry) {
         ck_assert_uint_eq(sub->currentLifetimeCount, 6);
         count++;
     }
     ck_assert_uint_eq(count, 1);
 
-    /* Sleep until the publishing interval times out */
+    /* Sleep until the publishing interval times out. The next iteration removes
+     * the subscription. */
     UA_fakeSleep((UA_UInt32)publishingInterval + 1);
     UA_Server_run_iterate(server, false);
 
     count = 0;
-    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
+    LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry) {
         count++;
     }
     ck_assert_uint_eq(count, 0);