Merge "Unit test improvement - Fixed dealy replaced with waiting function in one...
[ric-plt/submgr.git] / pkg / control / ut_messaging_test.go
index 19680e8..2c90513 100644 (file)
@@ -96,7 +96,8 @@ func TestRESTSubReqAfterE2ConnBreak(t *testing.T) {
        mainCtrl.SetE2State(t, "RAN_NAME_1_CONNECTED")
 
        mainCtrl.VerifyCounterValues(t)
-       //os.Exit(1)
+       mainCtrl.VerifyAllClean(t)
+       //os.Exit(0)
 }
 
 //-----------------------------------------------------------------------------
@@ -175,6 +176,7 @@ func TestRESTSubReqE2ConnBreak(t *testing.T) {
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -251,6 +253,7 @@ func TestRESTSubscriptionDeleteAfterE2ConnectionBreak(t *testing.T) {
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -314,6 +317,7 @@ func TestRESTOtherE2ConnectionChanges(t *testing.T) {
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -363,6 +367,7 @@ func TestRESTSubReqAndDeleteOkWithE2apUtWrapper(t *testing.T) {
        deleteSubscription(t, xappConn1, e2termConn1, &restSubId)
 
        waitSubsCleanup(t, e2SubsId, 10)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -409,6 +414,7 @@ func TestRESTSubReqAndE1apDeleteReqPackingError(t *testing.T) {
        defer e2ap_wrapper.AllowE2apToProcess(e2ap_wrapper.SUB_DEL_REQ, true)
 
        waitSubsCleanup(t, e2SubsId, 10)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -471,6 +477,7 @@ func TestRESTSubReqAndE1apDeleteRespUnpackingError(t *testing.T) {
        defer e2ap_wrapper.AllowE2apToProcess(e2ap_wrapper.SUB_DEL_RESP, true)
 
        waitSubsCleanup(t, e2SubsId, 10)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -668,7 +675,6 @@ func TestSubDelReqAndRouteDeleteNok(t *testing.T) {
        xappConn2.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
-
        mainCtrl.VerifyCounterValues(t)
 }
 
@@ -2368,9 +2374,6 @@ func TestSubReqRetransmissionWithSameSubIdDiffXid(t *testing.T) {
 func TestSubReqNokAndSubDelOkWithRestartInMiddle(t *testing.T) {
        CaseBegin("TestSubReqNokAndSubDelOkWithRestartInMiddle")
 
-       // Remove possible existing subscrition
-       mainCtrl.removeExistingSubscriptions(t)
-
        mainCtrl.SetResetTestFlag(t, true) // subs.DoNotWaitSubResp will be set TRUE for the subscription
        xappConn1.SendSubsReq(t, nil, nil)
        e2termConn1.RecvSubsReq(t)
@@ -2452,6 +2455,10 @@ func TestSubReqAndSubDelOkWithRestartInMiddle(t *testing.T) {
        mainCtrl.SimulateRestart(t)
        xapp.Logger.Debug("mainCtrl.SimulateRestart done")
 
+       // ReadE2Subscriptions() for testing is running in own go routine (go mainCtrl.c.ReadE2Subscriptions())
+       // That needs to be completed before successful subscription query is possible
+       <-time.After(time.Second * 1)
+
        // Check that subscription is restored correctly after restart
        resp, _ = xapp.Subscription.QuerySubscriptions()
        assert.Equal(t, resp[0].SubscriptionID, int64(e2SubsId))
@@ -2546,7 +2553,7 @@ func TestSubReqAndSubDelOkSameActionWithRestartsInMiddle(t *testing.T) {
        e2SubsId2 := xappConn2.RecvSubsResp(t, cretrans2)
 
        // Check subscription
-       resp, _ := xapp.Subscription.QuerySubscriptions() ////////////////////////////////
+       resp, _ := xapp.Subscription.QuerySubscriptions()
        assert.Equal(t, resp[0].SubscriptionID, int64(e2SubsId1))
        assert.Equal(t, resp[0].Meid, "RAN_NAME_1")
        assert.Equal(t, resp[0].ClientEndpoint, []string{"localhost:13560", "localhost:13660"})
@@ -2554,6 +2561,10 @@ func TestSubReqAndSubDelOkSameActionWithRestartsInMiddle(t *testing.T) {
        mainCtrl.SimulateRestart(t)
        xapp.Logger.Debug("mainCtrl.SimulateRestart done")
 
+       // ReadE2Subscriptions() for testing is running in own go routine (go mainCtrl.c.ReadE2Subscriptions())
+       // That needs to be completed before successful subscription query is possible
+       <-time.After(time.Second * 1)
+
        // Check that subscription is restored correctly after restart
        resp, _ = xapp.Subscription.QuerySubscriptions()
        assert.Equal(t, resp[0].SubscriptionID, int64(e2SubsId1))
@@ -2569,6 +2580,10 @@ func TestSubReqAndSubDelOkSameActionWithRestartsInMiddle(t *testing.T) {
        mainCtrl.SimulateRestart(t)
        xapp.Logger.Debug("mainCtrl.SimulateRestart done")
 
+       // ReadE2Subscriptions() for testing is running in own go routine (go mainCtrl.c.ReadE2Subscriptions())
+       // Submgr need be ready before successful subscription deletion is possible
+       <-time.After(time.Second * 1)
+
        //Del2
        deltrans2 := xappConn2.SendSubsDelReq(t, nil, e2SubsId2)
        delreq2, delmsg2 := e2termConn1.RecvSubsDelReq(t)
@@ -2692,6 +2707,7 @@ func TestRESTSubReqAndRouteNok(t *testing.T) {
        mainCtrl.wait_subs_clean(t, newSubsId, 10)
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqAndRouteUpdateNok(t *testing.T) {
@@ -2706,10 +2722,10 @@ func TestRESTSubReqAndRouteUpdateNok(t *testing.T) {
                Counter{cRestSubNotifToXapp, 1},
                Counter{cRestSubFailNotifToXapp, 1},
                Counter{cRouteCreateUpdateFail, 1},
-               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 2},
                Counter{cSubDelReqToE2, 1},
                Counter{cSubDelRespFromE2, 1},
-               Counter{cRestSubDelRespToXapp, 1},
+               Counter{cRestSubDelRespToXapp, 2},
        })
 
        var params *teststube2ap.RESTSubsReqParams = nil
@@ -2728,18 +2744,19 @@ func TestRESTSubReqAndRouteUpdateNok(t *testing.T) {
        xapp.Logger.Debug("Send REST subscriber request for second subscriber : %v", restSubId2)
        xappConn2.ExpectRESTNotificationNok(t, restSubId2, "allFail")
        waiter.WaitResult(t)
-       // e2SubsId2 := xappConn2.WaitRESTNotification(t, restSubId2) - TOD: missing delete
        xappConn2.WaitRESTNotification(t, restSubId2)
 
        queryXappSubscription(t, int64(e2SubsId), "RAN_NAME_1", []string{"localhost:13560"})
 
        deleteSubscription(t, xappConn1, e2termConn1, &restSubId)
+       xappConn2.SendRESTSubsDelReq(t, &restSubId2)
 
        mainCtrl.wait_subs_clean(t, newSubsId, 10)
        //Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubDelReqAndRouteDeleteNok(t *testing.T) {
@@ -2773,8 +2790,8 @@ func TestRESTSubDelReqAndRouteDeleteNok(t *testing.T) {
        waiter.WaitResult(t)
 
        waitSubsCleanup(t, e2SubsId, 10)
-
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubMergeDelAndRouteUpdateNok(t *testing.T) {
@@ -2817,6 +2834,7 @@ func TestRESTSubMergeDelAndRouteUpdateNok(t *testing.T) {
 
        waitSubsCleanup(t, e2SubsId2, 10)
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -2872,33 +2890,32 @@ func TestRESTSubReqRetransmission(t *testing.T) {
        // Subs Create
        const subReqCount int = 1
 
-       // In order to force both XAPP's to create their own subscriptions, force rtmgr to block a while so that 2nd create
-       // gets into execution before the rtmgrg responds for the first one.
-       waiter := rtmgrHttp.AllocNextSleep(10, true)
        params := xappConn1.GetRESTSubsReqReportParams(subReqCount)
-       restSubId1 := xappConn1.SendRESTSubsReq(t, params)
-       xappConn2.SendRESTSubsReq(t, params)
+       restSubId := xappConn1.SendRESTSubsReq(t, params)
 
-       waiter.WaitResult(t)
+       xappConn1.SendRESTSubsReq(t, params)
+       <-time.After(time.Second * 1)
 
-       xappConn1.WaitListedRestNotifications(t, []string{restSubId1})
+       xappConn1.WaitListedRestNotifications(t, []string{restSubId})
 
        // Depending one goroutine scheduling order, we cannot say for sure which xapp reaches e2term first. Thus
-       // the order is not significant he6re.
+       // the order is not significant here.
        crereq, cremsg := e2termConn1.RecvSubsReq(t)
        e2termConn1.SendSubsResp(t, crereq, cremsg)
 
-       e2SubsIdA := <-xappConn1.ListedRESTNotifications
-       xapp.Logger.Debug("TEST: 1.st XAPP notification received e2SubsId=%v", e2SubsIdA)
+       e2SubsId := <-xappConn1.ListedRESTNotifications
+
+       xapp.Logger.Debug("TEST: XAPP notification received e2SubsId=%v", e2SubsId)
 
        // Del1
-       xappConn1.SendRESTSubsDelReq(t, &restSubId1)
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
        delreq1, delmsg1 := e2termConn1.RecvSubsDelReq(t)
        e2termConn1.SendSubsDelResp(t, delreq1, delmsg1)
 
-       mainCtrl.wait_multi_subs_clean(t, []uint32{e2SubsIdA.E2SubsId}, 10)
+       mainCtrl.wait_multi_subs_clean(t, []uint32{e2SubsId.E2SubsId}, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -2965,26 +2982,27 @@ func TestRESTSubReqRetransmissionV2(t *testing.T) {
 
        queryXappSubscription(t, int64(e2SubsId), "RAN_NAME_1", []string{"localhost:13560"})
 
+       mainCtrl.WaitOngoingRequestMapEmpty()
+
        //1.st resend
        restSubId_resend := xappConn1.SendRESTSubsReq(t, params)
 
        assert.Equal(t, restSubId_resend, restSubId)
 
-       <-time.After(100 * time.Millisecond)
+       mainCtrl.WaitOngoingRequestMapEmpty()
 
        //2.nd resend
        restSubId_resend2 := xappConn1.SendRESTSubsReq(t, params)
 
        assert.Equal(t, restSubId_resend2, restSubId)
 
-       <-time.After(100 * time.Millisecond)
+       mainCtrl.WaitOngoingRequestMapEmpty()
 
        deleteSubscription(t, xappConn1, e2termConn1, &restSubId)
 
        waitSubsCleanup(t, e2SubsId, 10)
-
-       //Wait that subs is cleaned
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3050,7 +3068,7 @@ func TestRESTSubReqRetransmissionV3(t *testing.T) {
 
        queryXappSubscription(t, int64(e2SubsId), "RAN_NAME_1", []string{"localhost:13560"})
 
-       <-time.After(100 * time.Millisecond)
+       mainCtrl.WaitOngoingRequestMapEmpty()
 
        //1.st resend with subscription ID
        params.SetSubscriptionID(&restSubId)
@@ -3058,7 +3076,7 @@ func TestRESTSubReqRetransmissionV3(t *testing.T) {
 
        assert.Equal(t, restSubId_resend, restSubId)
 
-       <-time.After(100 * time.Millisecond)
+       mainCtrl.WaitOngoingRequestMapEmpty()
 
        //2.nd resend without subscription ID (faking app restart)
        params = xappConn1.GetRESTSubsReqReportParams(subReqCount)
@@ -3066,14 +3084,13 @@ func TestRESTSubReqRetransmissionV3(t *testing.T) {
 
        assert.Equal(t, restSubId_resend2, restSubId)
 
-       <-time.After(100 * time.Millisecond)
+       mainCtrl.WaitOngoingRequestMapEmpty()
 
        deleteSubscription(t, xappConn1, e2termConn1, &restSubId)
 
        waitSubsCleanup(t, e2SubsId, 10)
-
-       //Wait that subs is cleaned
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3153,7 +3170,7 @@ func TestRESTSubReqRetransmissionV4(t *testing.T) {
 
        restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
 
-       <-time.After(100 * time.Millisecond)
+       mainCtrl.WaitOngoingRequestMapEmpty()
 
        // Send modified  requst, this time with e2 subscriptions.
        params2 := xappConn1.GetRESTSubsReqReportParams(subReqCount + 1)
@@ -3174,7 +3191,7 @@ func TestRESTSubReqRetransmissionV4(t *testing.T) {
        e2SubsId2 := xappConn1.WaitRESTNotification(t, restSubId_resend)
        assert.NotEqual(t, e2SubsId2, 0)
 
-       <-time.After(100 * time.Millisecond)
+       mainCtrl.WaitOngoingRequestMapEmpty()
 
        xapp.Subscription.SetResponseCB(xappConn1.SubscriptionRespHandler)
        params = xappConn1.GetRESTSubsReqReportParams(subReqCount)
@@ -3187,15 +3204,16 @@ func TestRESTSubReqRetransmissionV4(t *testing.T) {
        e2SubsId1 = xappConn1.WaitAnyRESTNotification(t)
        assert.Equal(t, e2SubsId, e2SubsId1)
 
+       mainCtrl.WaitOngoingRequestMapEmpty()
+
        // Delete both e2 subscriptions
        xappConn1.SendRESTSubsDelReq(t, &restSubId)
        e2SubsIds := []uint32{e2SubsId, e2SubsId2}
        sendAndReceiveMultipleE2DelReqs(t, e2SubsIds, e2termConn1)
 
        waitSubsCleanup(t, e2SubsId, 10)
-
-       //Wait that subs is cleaned
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3275,9 +3293,9 @@ func TestRESTSubReqRetransmissionV5(t *testing.T) {
 
        restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
 
-       <-time.After(100 * time.Millisecond)
+       mainCtrl.WaitOngoingRequestMapEmpty()
 
-       // Send modified  requst, this time with e2 subscriptions.
+       // Send modified  request, this time with e2 subscriptions.
        params2 := xappConn1.GetRESTSubsReqReportParams(subReqCount + 1)
        params2.SetSubscriptionID(&restSubId)
 
@@ -3298,7 +3316,7 @@ func TestRESTSubReqRetransmissionV5(t *testing.T) {
        e2SubsId2 := xappConn1.WaitRESTNotification(t, restSubId_resend)
        assert.NotEqual(t, e2SubsId2, 0)
 
-       <-time.After(100 * time.Millisecond)
+       mainCtrl.WaitOngoingRequestMapEmpty()
 
        xapp.Subscription.SetResponseCB(xappConn1.SubscriptionRespHandler)
        params = xappConn1.GetRESTSubsReqReportParams(subReqCount)
@@ -3311,15 +3329,16 @@ func TestRESTSubReqRetransmissionV5(t *testing.T) {
        e2SubsId1 = xappConn1.WaitAnyRESTNotification(t)
        assert.Equal(t, e2SubsId, e2SubsId1)
 
+       mainCtrl.WaitOngoingRequestMapEmpty()
+
        // Delete both e2 subscriptions
        xappConn1.SendRESTSubsDelReq(t, &restSubId)
        e2SubsIds := []uint32{e2SubsId, e2SubsId2}
        sendAndReceiveMultipleE2DelReqs(t, e2SubsIds, e2termConn1)
 
        waitSubsCleanup(t, e2SubsId, 10)
-
-       //Wait that subs is cleaned
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3408,7 +3427,7 @@ func TestRESTSubReqRetransmissionV6(t *testing.T) {
 
        restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
 
-       <-time.After(100 * time.Millisecond)
+       mainCtrl.WaitOngoingRequestMapEmpty()
 
        // Send modified  requst, this time with e2 subscriptions.
        params2 := xappConn1.GetRESTSubsReqReportParams(subReqCount + 1)
@@ -3429,7 +3448,7 @@ func TestRESTSubReqRetransmissionV6(t *testing.T) {
        e2SubsId2 := xappConn1.WaitRESTNotification(t, restSubId_resend)
        assert.NotEqual(t, e2SubsId2, 0)
 
-       <-time.After(100 * time.Millisecond)
+       mainCtrl.WaitOngoingRequestMapEmpty()
 
        // Delete both e2 subscriptions
        xappConn1.SendRESTSubsDelReq(t, &restSubId)
@@ -3443,14 +3462,13 @@ func TestRESTSubReqRetransmissionV6(t *testing.T) {
        // fresh create.
        restSubId, e2SubsId = createSubscription(t, xappConn1, e2termConn1, params)
 
-       <-time.After(100 * time.Millisecond)
+       mainCtrl.WaitOngoingRequestMapEmpty()
 
        deleteSubscription(t, xappConn1, e2termConn1, &restSubId)
 
        waitSubsCleanup(t, e2SubsId, 10)
-
-       //Wait that subs is cleaned
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubDelReqRetransmission(t *testing.T) {
@@ -3486,8 +3504,8 @@ func TestRESTSubDelReqRetransmission(t *testing.T) {
        e2termConn1.SendSubsDelResp(t, delreq, delmsg)
 
        waitSubsCleanup(t, e2SubsId, 10)
-
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3559,7 +3577,7 @@ func TestRESTSubReqDelReq(t *testing.T) {
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
-
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubDelReqCollision(t *testing.T) {
@@ -3617,7 +3635,7 @@ func TestRESTSubReqAndSubDelOkTwoParallel(t *testing.T) {
        waitSubsCleanup(t, e2SubsIdB.E2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
-
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSameSubsDiffRan(t *testing.T) {
@@ -3654,6 +3672,7 @@ func TestRESTSameSubsDiffRan(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqRetryInSubmgr(t *testing.T) {
@@ -3698,7 +3717,7 @@ func TestRESTSubReqRetryInSubmgr(t *testing.T) {
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
-
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3753,7 +3772,10 @@ func TestRESTSubReqRetryNoRespSubDelRespInSubmgr(t *testing.T) {
                Counter{cRestSubFailNotifToXapp, 1},
                Counter{cSubDelReqToE2, 1},
                Counter{cSubDelRespFromE2, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
        })
+
        params := xappConn1.GetRESTSubsReqReportParams(subReqCount)
        restSubId := xappConn1.SendRESTSubsReq(t, params)
        xapp.Logger.Debug("Send REST subscriber request for subscriber : %v", restSubId)
@@ -3769,10 +3791,12 @@ func TestRESTSubReqRetryNoRespSubDelRespInSubmgr(t *testing.T) {
        e2termConn1.SendSubsDelResp(t, delreq, delmsg)
        xappConn1.WaitRESTNotification(t, restSubId)
 
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+
        // Wait that subs is cleaned
        waitSubsCleanup(t, delreq.RequestId.InstanceId, 10)
-
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestREST2eTermNotRespondingToSubReq(t *testing.T) {
@@ -3789,7 +3813,10 @@ func TestREST2eTermNotRespondingToSubReq(t *testing.T) {
                Counter{cRestSubFailNotifToXapp, 1},
                Counter{cSubDelReqToE2, 1},
                Counter{cSubDelReqTimerExpiry, 2},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
        })
+
        params := xappConn1.GetRESTSubsReqReportParams(subReqCount)
        restSubId := xappConn1.SendRESTSubsReq(t, params)
        xapp.Logger.Debug("Send REST subscriber request for subscriber : %v", restSubId)
@@ -3809,10 +3836,11 @@ func TestREST2eTermNotRespondingToSubReq(t *testing.T) {
 
        e2SubsId := xappConn1.WaitRESTNotification(t, restSubId)
 
-       waitSubsCleanup(t, e2SubsId, 10)
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
 
+       waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
-
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3867,6 +3895,8 @@ func TestRESTSubReqTwoRetriesNoRespAtAllInSubmgr(t *testing.T) {
                Counter{cSubDelReqToE2, 1},
                Counter{cSubDelReReqToE2, 1},
                Counter{cSubDelReqTimerExpiry, 2},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
        })
 
        params := xappConn1.GetRESTSubsReqReportParams(subReqCount)
@@ -3888,9 +3918,11 @@ func TestRESTSubReqTwoRetriesNoRespAtAllInSubmgr(t *testing.T) {
 
        e2SubsId := xappConn1.WaitRESTNotification(t, restSubId)
 
-       waitSubsCleanup(t, e2SubsId, 10)
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
 
+       waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3958,7 +3990,7 @@ func TestRESTSubReqSubFailRespInSubmgr(t *testing.T) {
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
-
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4022,6 +4054,7 @@ func TestRESTSubDelReqRetryInSubmgr(t *testing.T) {
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4084,6 +4117,7 @@ func TestRESTSubDelReqTwoRetriesNoRespInSubmgr(t *testing.T) {
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4140,6 +4174,7 @@ func TestRESTSubDelReqSubDelFailRespInSubmgr(t *testing.T) {
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4239,8 +4274,8 @@ func TestRESTSubReqAndSubDelOkSameAction(t *testing.T) {
 
        //Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId2, 10)
-
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4333,8 +4368,8 @@ func TestRESTSubReqAndSubDelOkSameActionParallel(t *testing.T) {
        e2termConn1.SendSubsDelResp(t, delreq2, delmsg2)
 
        waitSubsCleanup(t, e2SubsId2, 10)
-
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4399,6 +4434,7 @@ func TestRESTSubReqAndSubDelNoAnswerSameActionParallel(t *testing.T) {
                Counter{cSubReqTimerExpiry, 2},
                Counter{cSubReReqToE2, 1},
                Counter{cRestSubFailNotifToXapp, 2},
+               Counter{cUnmergedSubscriptions, 1},
                Counter{cRestSubDelReqFromXapp, 2},
                Counter{cSubDelReqToE2, 1},
                Counter{cSubDelRespFromE2, 1},
@@ -4441,8 +4477,8 @@ func TestRESTSubReqAndSubDelNoAnswerSameActionParallel(t *testing.T) {
 
        //Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsIdA.E2SubsId, 10)
-
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4500,6 +4536,7 @@ func TestRESTSubReqAndSubDelNokSameActionParallel(t *testing.T) {
                Counter{cSubReqToE2, 1},
                Counter{cSubFailFromE2, 1},
                Counter{cRestSubFailNotifToXapp, 2},
+               Counter{cUnmergedSubscriptions, 1},
                Counter{cRestSubDelReqFromXapp, 2},
                Counter{cRestSubDelRespToXapp, 2},
        })
@@ -4538,8 +4575,8 @@ func TestRESTSubReqAndSubDelNokSameActionParallel(t *testing.T) {
        //Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsIdA.E2SubsId, 10)
        waitSubsCleanup(t, e2SubsIdB.E2SubsId, 10)
-
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqPolicyAndSubDelOk(t *testing.T) {
@@ -4575,6 +4612,7 @@ func TestRESTSubReqPolicyAndSubDelOk(t *testing.T) {
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4669,6 +4707,7 @@ func TestRESTSubReqPolicyChangeAndSubDelOk(t *testing.T) {
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4750,6 +4789,7 @@ func TestRESTSubReqPolicyChangeNOk(t *testing.T) {
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4853,6 +4893,7 @@ func TestRESTSubReqAndSubDelOkTwoE2termParallel(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4952,6 +4993,7 @@ func TestRESTSubReqInsertAndSubDelOk(t *testing.T) {
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4965,6 +5007,8 @@ func TestRESTSubReqInsertAndSubDelOk(t *testing.T) {
 //     | RESTSubReq   |              |
 //     |------------->|              |
 //     |              |              |
+//     |  RESTSubResp |              |
+//     |<-------------|              |
 //     |              | SubReq       |
 //     |              |------------->|
 //     |              |              |
@@ -4980,6 +5024,15 @@ func TestRESTSubReqInsertAndSubDelOk(t *testing.T) {
 //     |              |   SubDelResp |
 //     |              |<-------------|
 //     |              |              |
+//     |    RESTNotif |              |
+//     |    unsuccess |              |
+//     |<-------------|              |
+//     |              |              |
+//     | RESTSubDelReq|              |
+//     |------------->|              |
+//     |              |              |
+//     |RESTSubDelResp|              |
+//     |<-------------|              |
 //
 //-----------------------------------------------------------------------------
 func TestRESTSubReqNokAndSubDelOkWithRestartInMiddle(t *testing.T) {
@@ -4992,14 +5045,12 @@ func TestRESTSubReqNokAndSubDelOkWithRestartInMiddle(t *testing.T) {
                Counter{cSubDelReqFromXapp, 1},
                Counter{cSubDelReqToE2, 1},
                Counter{cSubDelRespFromE2, 1},
-               Counter{cRestSubFailNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
        })
 
        const subReqCount int = 1
 
-       // Remove possible existing subscription
-       mainCtrl.removeExistingSubscriptions(t)
-
        params := xappConn1.GetRESTSubsReqReportParams(subReqCount)
 
        //Req
@@ -5014,16 +5065,19 @@ func TestRESTSubReqNokAndSubDelOkWithRestartInMiddle(t *testing.T) {
        mainCtrl.SimulateRestart(t)
        xapp.Logger.Debug("mainCtrl.SimulateRestart done")
 
-       //Del
+       // Deleletion of uncompleted subscription
        delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
        e2termConn1.SendSubsDelResp(t, delreq, delmsg)
 
+       //Del
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+
        xappConn1.TestMsgChanEmpty(t)
-       xappConn2.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -5079,12 +5133,9 @@ func TestRESTSubReqAndSubDelOkWithRestartInMiddle(t *testing.T) {
                Counter{cSubDelRespFromE2, 1},
                Counter{cRestSubDelRespToXapp, 1},
        })
-       // Remove possible existing subscription
-       mainCtrl.removeExistingSubscriptions(t)
-
-       var params *teststube2ap.RESTSubsReqParams = nil
 
        // Create subscription
+       var params *teststube2ap.RESTSubsReqParams = nil
        restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
        xapp.Logger.Debug("Send REST subscriber request for subscriber : %v", restSubId)
 
@@ -5094,6 +5145,10 @@ func TestRESTSubReqAndSubDelOkWithRestartInMiddle(t *testing.T) {
        mainCtrl.SimulateRestart(t)
        xapp.Logger.Debug("mainCtrl.SimulateRestart done")
 
+       // ReadE2Subscriptions() for testing is running in own go routine (go mainCtrl.c.ReadE2Subscriptions())
+       // That needs to be completed before successful subscription query is possible
+       <-time.After(time.Second * 1)
+
        // Check subscription
        queryXappSubscription(t, int64(e2SubsId), "RAN_NAME_1", []string{"localhost:13560"})
 
@@ -5104,6 +5159,7 @@ func TestRESTSubReqAndSubDelOkWithRestartInMiddle(t *testing.T) {
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -5160,7 +5216,6 @@ func TestRESTSubReqAndSubDelOkWithRestartInMiddle(t *testing.T) {
 //     |             |                 |              |
 //
 //-----------------------------------------------------------------------------
-
 func TestRESTSubReqAndSubDelOkSameActionWithRestartsInMiddle(t *testing.T) {
        CaseBegin("TestRESTSubReqAndSubDelOkSameActionWithRestartsInMiddle")
 
@@ -5178,12 +5233,8 @@ func TestRESTSubReqAndSubDelOkSameActionWithRestartsInMiddle(t *testing.T) {
                Counter{cRestSubDelRespToXapp, 2},
        })
 
-       // Remove possible existing subscription
-       mainCtrl.removeExistingSubscriptions(t)
-
-       var params *teststube2ap.RESTSubsReqParams = nil
-
        // Create subscription 1
+       var params *teststube2ap.RESTSubsReqParams = nil
        restSubId1, e2SubsId1 := createSubscription(t, xappConn1, e2termConn1, params)
        xapp.Logger.Debug("Send REST subscriber request for subscriber 1 : %v", restSubId1)
 
@@ -5200,15 +5251,24 @@ func TestRESTSubReqAndSubDelOkSameActionWithRestartsInMiddle(t *testing.T) {
        queryXappSubscription(t, int64(e2SubsId1), "RAN_NAME_1", []string{"localhost:13560", "localhost:13660"})
 
        mainCtrl.SimulateRestart(t)
-       xapp.Logger.Debug("mainCtrl.SimulateRestart done")
+       xapp.Logger.Debug("mainCtrl.SimulateRestart done 1")
+
+       // ReadE2Subscriptions() for testing is running in own go routine (go mainCtrl.c.ReadE2Subscriptions())
+       // That needs to be completed before successful subscription delete is possible
+       <-time.After(time.Second * 1)
 
        // Delete subscription 1, and wait until it has removed the first endpoint
-       subepcnt := mainCtrl.get_subs_entrypoint_cnt(t, e2SubsId1)
        xappConn1.SendRESTSubsDelReq(t, &restSubId1)
-       mainCtrl.wait_subs_entrypoint_cnt_change(t, e2SubsId1, subepcnt, 10)
+       mainCtrl.WaitRESTSubscriptionDelete(restSubId1)
+       // Above wait does not work correctly anymore as this delay makes this test case work
 
        mainCtrl.SimulateRestart(t)
-       xapp.Logger.Debug("mainCtrl.SimulateRestart done")
+       xapp.Logger.Debug("mainCtrl.SimulateRestart done 2")
+
+       // ReadE2Subscriptions() for testing is running in own go routine (go mainCtrl.c.ReadE2Subscriptions())
+       // That needs to be completed before successful subscription query is possible
+       <-time.After(time.Second * 1)
+
        queryXappSubscription(t, int64(e2SubsId1), "RAN_NAME_1", []string{"localhost:13660"})
 
        // Delete subscription 2
@@ -5218,6 +5278,7 @@ func TestRESTSubReqAndSubDelOkSameActionWithRestartsInMiddle(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -5254,14 +5315,14 @@ func TestRESTSubReqAndSubDelOkSameActionWithRestartsInMiddle(t *testing.T) {
 //     | RESTSubDelReq   |              |
 //     |---------------->|              |
 //     |                 |              |
+//     |   RESTSubDelResp|              |
+//     |<----------------|              |
 //     |                 | SubDelReq    |
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |   SubDelResp |
 //     |                 |<-------------|
 //     |                 |              |
-//     |   RESTSubDelResp|              |
-//     |<----------------|              |
 //
 //-----------------------------------------------------------------------------
 
@@ -5275,6 +5336,18 @@ func TestRESTReportSubReqAndSubDelOk(t *testing.T) {
 func RESTReportSubReqAndSubDelOk(t *testing.T, subReqCount int, testIndex int) {
        xapp.Logger.Debug("TEST: TestRESTReportSubReqAndSubDelOk with testIndex %v", testIndex)
 
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cRestSubReqFromXapp, 1},
+               Counter{cRestSubRespToXapp, 1},
+               Counter{cSubReqToE2, uint64(subReqCount)},
+               Counter{cSubRespFromE2, uint64(subReqCount)},
+               Counter{cRestSubNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
+               Counter{cSubDelReqToE2, uint64(subReqCount)},
+               Counter{cSubDelRespFromE2, uint64(subReqCount)},
+       })
+
        // Req
        params := xappConn1.GetRESTSubsReqReportParams(subReqCount)
        restSubId := xappConn1.SendRESTSubsReq(t, params)
@@ -5311,10 +5384,12 @@ func RESTReportSubReqAndSubDelOk(t *testing.T, subReqCount int, testIndex int) {
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
+       mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 /*
-func TestRESTPolicySubReqAndSubDelOk(t *testing.T) {
+func TestRESTPolicySubReqAndSubDelOk(t *testing.T) {  //Was in comments already. Next case is not run!
        CaseBegin("TestRESTPolicySubReqAndSubDelOk")
 
        subReqCount := 2
@@ -5329,6 +5404,18 @@ func TestRESTPolicySubReqAndSubDelOk(t *testing.T) {
 func RESTPolicySubReqAndSubDelOk(t *testing.T, subReqCount int, testIndex int) {
        xapp.Logger.Debug("TEST: TestRESTPolicySubReqAndSubDelOk with testIndex %v", testIndex)
 
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cRestSubReqFromXapp, 1},
+               Counter{cRestSubRespToXapp, 1},
+               Counter{cSubReqToE2, uint64(subReqCount)},
+               Counter{cSubRespFromE2, uint64(subReqCount)},
+               Counter{cRestSubNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
+               Counter{cSubDelReqToE2, uint64(subReqCount)},
+               Counter{cSubDelRespFromE2, uint64(subReqCount)},
+       })
+
        // Req
        params := xappConn1.GetRESTSubsReqPolicyParams(subReqCount)
        restSubId := xappConn1.SendRESTSubsReq(t, params)
@@ -5358,6 +5445,8 @@ func RESTPolicySubReqAndSubDelOk(t *testing.T, subReqCount int, testIndex int) {
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
+       mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 func TestRESTTwoPolicySubReqAndSubDelOk(t *testing.T) {
@@ -5392,6 +5481,7 @@ func TestRESTTwoPolicySubReqAndSubDelOk(t *testing.T) {
        mainCtrl.wait_registry_empty(t, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 func TestRESTPolicySubReqAndSubDelOkFullAmount(t *testing.T) {
 
@@ -5423,6 +5513,7 @@ func TestRESTPolicySubReqAndSubDelOkFullAmount(t *testing.T) {
        mainCtrl.wait_registry_empty(t, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTTwoReportSubReqAndSubDelOk(t *testing.T) {
@@ -5457,6 +5548,7 @@ func TestRESTTwoReportSubReqAndSubDelOk(t *testing.T) {
        mainCtrl.wait_registry_empty(t, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTTwoReportSubReqAndSubDelOkNoActParams(t *testing.T) {
@@ -5491,6 +5583,7 @@ func TestRESTTwoReportSubReqAndSubDelOkNoActParams(t *testing.T) {
        mainCtrl.wait_registry_empty(t, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTFullAmountReportSubReqAndSubDelOk(t *testing.T) {
@@ -5525,6 +5618,7 @@ func TestRESTFullAmountReportSubReqAndSubDelOk(t *testing.T) {
        mainCtrl.wait_registry_empty(t, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqReportSameActionDiffEventTriggerDefinitionLen(t *testing.T) {
@@ -5571,7 +5665,7 @@ func TestRESTSubReqReportSameActionDiffEventTriggerDefinitionLen(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqReportSameActionDiffActionListLen(t *testing.T) {
@@ -5623,7 +5717,7 @@ func TestRESTSubReqReportSameActionDiffActionListLen(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqReportSameActionDiffActionID(t *testing.T) {
@@ -5669,7 +5763,7 @@ func TestRESTSubReqReportSameActionDiffActionID(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqDiffActionType(t *testing.T) {
@@ -5720,7 +5814,7 @@ func TestRESTSubReqDiffActionType(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqPolicyAndSubDelOkSameAction(t *testing.T) {
@@ -5771,7 +5865,7 @@ func TestRESTSubReqPolicyAndSubDelOkSameAction(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqReportSameActionDiffActionDefinitionLen(t *testing.T) {
@@ -5818,7 +5912,7 @@ func TestRESTSubReqReportSameActionDiffActionDefinitionLen(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqReportSameActionDiffActionDefinitionContents(t *testing.T) {
@@ -5865,7 +5959,7 @@ func TestRESTSubReqReportSameActionDiffActionDefinitionContents(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqReportSameActionDiffSubsAction(t *testing.T) {
@@ -5910,7 +6004,7 @@ func TestRESTSubReqReportSameActionDiffSubsAction(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -5931,7 +6025,7 @@ func TestRESTSubReqReportSameActionDiffSubsAction(t *testing.T) {
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |      SubResp | ASN.1 decode fails
-//     |                 |<-------------|
+//     |                 |<-------------| Decode failed. More data needed. This will result timer expiry and resending
 //     |                 |              |
 //     |                 | SubReq       |
 //     |                 |------------->|
@@ -5941,11 +6035,27 @@ func TestRESTSubReqReportSameActionDiffSubsAction(t *testing.T) {
 //     | RESTNotif (fail)|              |
 //     |<----------------|              |
 //     |                 |              |
+//     |           [SUBS DELETE]        |
+//     |                 |              |
 //
 //-----------------------------------------------------------------------------
 
 func TestRESTUnpackSubscriptionResponseDecodeFail(t *testing.T) {
        xapp.Logger.Debug("TEST: TestRESTUnpackSubscriptionResponseDecodeFail")
+
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cRestSubReqFromXapp, 1},
+               Counter{cRestSubRespToXapp, 1},
+               Counter{cSubReqToE2, 1},
+               Counter{cSubReqTimerExpiry, 1},
+               Counter{cSubReReqToE2, 1},
+               Counter{cSubRespFromE2, 1},
+               Counter{cSubFailFromE2, 1},
+               Counter{cRestSubFailNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
+       })
+
        const subReqCount int = 1
 
        // Req
@@ -5969,12 +6079,16 @@ func TestRESTUnpackSubscriptionResponseDecodeFail(t *testing.T) {
        instanceId := xappConn1.WaitRESTNotification(t, restSubId)
        xapp.Logger.Debug("TEST: REST notification received e2SubsId=%v", instanceId)
 
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+
        // Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, crereq.RequestId.InstanceId, 10)
 
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
+       mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -5995,13 +6109,13 @@ func TestRESTUnpackSubscriptionResponseDecodeFail(t *testing.T) {
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |      SubResp | Unknown instanceId
-//     |                 |<-------------|
+//     |                 |<-------------| No valid subscription found with subIds [0]
 //     |                 |              |
 //     |                 | SubReq       |
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |      SubFail | Duplicated action
-//     |                 |<-------------|
+//     |                 |<-------------| No valid subscription found with subIds [0]
 //     | RESTNotif (fail)|              |
 //     |<----------------|              |
 //     |                 | SubDelReq    |
@@ -6009,11 +6123,30 @@ func TestRESTUnpackSubscriptionResponseDecodeFail(t *testing.T) {
 //     |                 |              |
 //     |                 |   SubDelResp |
 //     |                 |<-------------|
+//     |                 |              |
+//     |           [SUBS DELETE]        |
+//     |                 |              |
 //
 //-----------------------------------------------------------------------------
 
 func TestRESTUnpackSubscriptionResponseUnknownInstanceId(t *testing.T) {
        xapp.Logger.Debug("TEST: TestRESTUnpackSubscriptionResponseUnknownInstanceId")
+
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cRestSubReqFromXapp, 1},
+               Counter{cRestSubRespToXapp, 1},
+               Counter{cSubReqToE2, 1},
+               Counter{cSubReqTimerExpiry, 2},
+               Counter{cSubReReqToE2, 1},
+               Counter{cSubRespFromE2, 1},
+               Counter{cSubFailFromE2, 1},
+               Counter{cRestSubFailNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
+               Counter{cSubDelReqToE2, 1},
+               Counter{cSubDelRespFromE2, 1},
+       })
+
        const subReqCount int = 1
 
        // Req
@@ -6022,7 +6155,7 @@ func TestRESTUnpackSubscriptionResponseUnknownInstanceId(t *testing.T) {
 
        crereq, cremsg := e2termConn1.RecvSubsReq(t)
 
-       // Unknown instanceId in this response which will result resending original request
+       // Unknown instanceId in this response which will result resending original request
        orgInstanceId := crereq.RequestId.InstanceId
        crereq.RequestId.InstanceId = 0
        e2termConn1.SendSubsResp(t, crereq, cremsg)
@@ -6031,7 +6164,7 @@ func TestRESTUnpackSubscriptionResponseUnknownInstanceId(t *testing.T) {
 
        xappConn1.ExpectRESTNotificationNok(t, restSubId, "allFail")
 
-       // Subscription already created in E2 Node.
+       // Subscription already created in E2 Node. E2 Node responds with failure but there is also same unknown instanceId 0
        fparams := &teststube2ap.E2StubSubsFailParams{}
        fparams.Set(crereq)
        fparams.SetCauseVal(0, 1, 3) // CauseRIC / duplicate-action
@@ -6043,12 +6176,16 @@ func TestRESTUnpackSubscriptionResponseUnknownInstanceId(t *testing.T) {
        instanceId := xappConn1.WaitRESTNotification(t, restSubId)
        xapp.Logger.Debug("TEST: REST notification received e2SubsId=%v", instanceId)
 
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+
        // Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, orgInstanceId, 10)
 
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
+       mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6069,30 +6206,51 @@ func TestRESTUnpackSubscriptionResponseUnknownInstanceId(t *testing.T) {
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |      SubResp | No transaction for the response
-//     |                 |<-------------|
+//     |                 |<-------------| Ongoing transaction not found. This will result timer expiry and resending
 //     |                 |              |
 //     |                 | SubReq       |
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |      SubFail | Duplicated action
-//     |                 |<-------------|
+//     |                 |<-------------|Ongoing transaction not found. This will result timer expiry and sending delete
 //     | RESTNotif (fail)|              |
 //     |<----------------|              |
 //     |                 | SubDelReq    |
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |   SubDelResp |
-//     |                 |<-------------|
+//     |                 |<-------------| Ongoing transaction not found. This will result timer expiry and resending
 //     |                 |              |
 //     |                 | SubDelReq    |
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |   SubDelResp |
-//     |                 |<-------------|
+//     |                 |<-------------| Ongoing transaction not found.
+//     |                 |              |
+//     |           [SUBS DELETE]        |
+//     |                 |              |
 //
 //-----------------------------------------------------------------------------
 func TestRESTUnpackSubscriptionResponseNoTransaction(t *testing.T) {
        xapp.Logger.Debug("TEST: TestRESTUnpackSubscriptionResponseNoTransaction")
+
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cRestSubReqFromXapp, 1},
+               Counter{cRestSubRespToXapp, 1},
+               Counter{cSubReqToE2, 1},
+               Counter{cSubReqTimerExpiry, 2},
+               Counter{cSubReReqToE2, 1},
+               Counter{cSubRespFromE2, 1},
+               Counter{cSubFailFromE2, 1},
+               Counter{cRestSubFailNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
+               Counter{cSubDelReqToE2, 1},
+               Counter{cSubDelReqTimerExpiry, 2},
+               Counter{cSubDelReReqToE2, 1},
+               Counter{cSubDelRespFromE2, 2},
+       })
+
        const subReqCount int = 1
 
        // Req
@@ -6125,13 +6283,16 @@ func TestRESTUnpackSubscriptionResponseNoTransaction(t *testing.T) {
        instanceId := xappConn1.WaitRESTNotification(t, restSubId)
        xapp.Logger.Debug("TEST: REST notification received e2SubsId=%v", instanceId)
 
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+
        // Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, crereq.RequestId.InstanceId, 10)
 
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
-
+       mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6152,7 +6313,7 @@ func TestRESTUnpackSubscriptionResponseNoTransaction(t *testing.T) {
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |      SubFail | ASN.1 decode fails
-//     |                 |<-------------|
+//     |                 |<-------------| Decode failed. More data needed. This will result timer expiry and resending
 //     |                 |              |
 //     |                 | SubReq       |
 //     |                 |------------->|
@@ -6162,10 +6323,25 @@ func TestRESTUnpackSubscriptionResponseNoTransaction(t *testing.T) {
 //     | RESTNotif (fail)|              |
 //     |<----------------|              |
 //     |                 |              |
+//     |           [SUBS DELETE]        |
+//     |                 |              |
 //
 //-----------------------------------------------------------------------------
 func TestRESTUnpackSubscriptionFailureDecodeFail(t *testing.T) {
        xapp.Logger.Debug("TEST: TestRESTUnpackSubscriptionFailureDecodeFail")
+
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cRestSubReqFromXapp, 1},
+               Counter{cRestSubRespToXapp, 1},
+               Counter{cSubReqToE2, 1},
+               Counter{cSubReqTimerExpiry, 1},
+               Counter{cSubReReqToE2, 1},
+               Counter{cSubFailFromE2, 2},
+               Counter{cRestSubFailNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
+       })
+
        const subReqCount int = 1
 
        // Req
@@ -6190,12 +6366,16 @@ func TestRESTUnpackSubscriptionFailureDecodeFail(t *testing.T) {
        instanceId := xappConn1.WaitRESTNotification(t, restSubId)
        xapp.Logger.Debug("TEST: REST notification received e2SubsId=%v", instanceId)
 
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+
        // Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, crereq.RequestId.InstanceId, 10)
 
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
+       mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6216,13 +6396,13 @@ func TestRESTUnpackSubscriptionFailureDecodeFail(t *testing.T) {
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |      SubFail | Unknown instanceId
-//     |                 |<-------------|
+//     |                 |<-------------| No valid subscription found with subIds [0]. This will result timer expiry and resending
 //     |                 |              |
 //     |                 | SubReq       |
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |      SubFail | Duplicated action
-//     |                 |<-------------|
+//     |                 |<-------------|No valid subscription found with subIds [0]. This will result timer expiry and sending delete
 //     | RESTNotif (fail)|              |
 //     |<----------------|              |
 //     |                 | SubDelReq    |
@@ -6230,19 +6410,36 @@ func TestRESTUnpackSubscriptionFailureDecodeFail(t *testing.T) {
 //     |                 |              |
 //     |                 |   SubDelResp |
 //     |                 |<-------------|
+//     |                 |              |
+//     |           [SUBS DELETE]        |
+//     |                 |              |
 //
 //-----------------------------------------------------------------------------
 func TestRESTUnpackSubscriptionFailureUnknownInstanceId(t *testing.T) {
        xapp.Logger.Debug("TEST: TestRESTUnpackSubscriptionFailureUnknownInstanceId")
        const subReqCount int = 1
 
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cRestSubReqFromXapp, 1},
+               Counter{cRestSubRespToXapp, 1},
+               Counter{cSubReqToE2, 1},
+               Counter{cSubReqTimerExpiry, 2},
+               Counter{cSubReReqToE2, 1},
+               Counter{cSubFailFromE2, 2},
+               Counter{cRestSubFailNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
+               Counter{cSubDelReqToE2, 1},
+               Counter{cSubDelRespFromE2, 1},
+       })
+
        // Req
        params := xappConn1.GetRESTSubsReqReportParams(subReqCount)
        restSubId := xappConn1.SendRESTSubsReq(t, params)
 
        crereq, cremsg := e2termConn1.RecvSubsReq(t)
 
-       // Unknown instanceId in this response which will result resending original request
+       // Unknown instanceId in this response which will result resending original request
        fparams := &teststube2ap.E2StubSubsFailParams{}
        fparams.Set(crereq)
        fparams.Fail.RequestId.InstanceId = 0
@@ -6252,7 +6449,7 @@ func TestRESTUnpackSubscriptionFailureUnknownInstanceId(t *testing.T) {
 
        xappConn1.ExpectRESTNotificationNok(t, restSubId, "allFail")
 
-       // Subscription already created in E2 Node.
+       // Subscription already created in E2 Node. E2 Node responds with failure but there is also same unknown instanceId 0
        fparams.SetCauseVal(0, 1, 3) // CauseRIC / duplicate-action
        e2termConn1.SendSubsFail(t, fparams, cremsg)
 
@@ -6262,12 +6459,16 @@ func TestRESTUnpackSubscriptionFailureUnknownInstanceId(t *testing.T) {
        instanceId := xappConn1.WaitRESTNotification(t, restSubId)
        xapp.Logger.Debug("TEST: REST notification received e2SubsId=%v", instanceId)
 
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+
        // Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, crereq.RequestId.InstanceId, 10)
 
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
+       mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6288,26 +6489,51 @@ func TestRESTUnpackSubscriptionFailureUnknownInstanceId(t *testing.T) {
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |      SubFail | No transaction for the response
-//     |                 |<-------------|
+//     |                 |<-------------| Ongoing transaction not found. This will result timer expiry and resending
 //     |                 |              |
 //     |                 | SubReq       |
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |      SubFail | Duplicated action
-//     |                 |<-------------|
+//     |                 |<-------------| Ongoing transaction not found. This will result timer expiry and sending delete
 //     | RESTNotif (fail)|              |
 //     |<----------------|              |
 //     |                 | SubDelReq    |
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |   SubDelResp |
-//     |                 |<-------------|
+//     |                 |<-------------| Ongoing transaction not found. This will result timer expiry and resending
+//     |                 |              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelResp |
+//     |                 |<-------------| Ongoing transaction not found.
+//     |                 |              |
+//     |           [SUBS DELETE]        |
+//     |                 |              |
 //
 //-----------------------------------------------------------------------------
 func TestRESTUnpackSubscriptionFailureNoTransaction(t *testing.T) {
        xapp.Logger.Debug("TEST: TestRESTUnpackSubscriptionFailureNoTransaction")
        const subReqCount int = 1
 
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cRestSubReqFromXapp, 1},
+               Counter{cRestSubRespToXapp, 1},
+               Counter{cSubReqToE2, 1},
+               Counter{cSubReqTimerExpiry, 2},
+               Counter{cSubReReqToE2, 1},
+               Counter{cSubFailFromE2, 2},
+               Counter{cRestSubFailNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
+               Counter{cSubDelReqToE2, 1},
+               Counter{cSubDelReqTimerExpiry, 2},
+               Counter{cSubDelReReqToE2, 1},
+               Counter{cSubDelRespFromE2, 2},
+       })
+
        // Req
        params := xappConn1.GetRESTSubsReqReportParams(subReqCount)
        restSubId := xappConn1.SendRESTSubsReq(t, params)
@@ -6339,12 +6565,16 @@ func TestRESTUnpackSubscriptionFailureNoTransaction(t *testing.T) {
        instanceId := xappConn1.WaitRESTNotification(t, restSubId)
        xapp.Logger.Debug("TEST: REST notification received e2SubsId=%v", instanceId)
 
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+
        // Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, crereq.RequestId.InstanceId, 10)
 
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
+       mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6367,20 +6597,37 @@ func TestRESTUnpackSubscriptionFailureNoTransaction(t *testing.T) {
 //     |                 | SubDelReq    |
 //     |                 |------------->|
 //     |                 |              |
-//     |                 |   SubDelResp | ASN.1 decode fails
-//     |                 |<-------------|
+//     |                 |   SubDelResp | ASN.1 decode fails.
+//     |                 |<-------------| Decode failed. More data needed. This will result timer expiry and resending
 //     |                 |              |
 //     |                 | SubDelReq    |
 //     |                 |------------->|
 //     |                 |              |
-//     |                 |   SubDelFail | Subscription does exist any more
+//     |                 |   SubDelFail | Subscription does exist any more in E2 node
 //     |                 |<-------------|
 //     |                 |              |
+//     |           [SUBS DELETE]        |
+//     |                 |              |
 //
 //-----------------------------------------------------------------------------
 func TestRESTUnpackSubscriptionDeleteResponseDecodeFail(t *testing.T) {
        xapp.Logger.Debug("TEST: TestRESTUnpackSubscriptionDeleteResponseDecodeFail")
 
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cRestSubReqFromXapp, 1},
+               Counter{cRestSubRespToXapp, 1},
+               Counter{cSubReqToE2, 1},
+               Counter{cSubRespFromE2, 1},
+               Counter{cRestSubNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
+               Counter{cSubDelReqToE2, 1},
+               Counter{cSubDelReqTimerExpiry, 1},
+               Counter{cSubDelReReqToE2, 1},
+               Counter{cSubDelFailFromE2, 1},
+               Counter{cSubDelRespFromE2, 1},
+       })
+
        // Req
        var params *teststube2ap.RESTSubsReqParams = nil
        restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
@@ -6392,7 +6639,7 @@ func TestRESTUnpackSubscriptionDeleteResponseDecodeFail(t *testing.T) {
        delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
 
        // Decode of this response fails which will result resending original request
-       e2termConn1.SendInvalidE2Asn1Resp(t, delmsg, xapp.RIC_SUB_DEL_REQ)
+       e2termConn1.SendInvalidE2Asn1Resp(t, delmsg, xapp.RIC_SUB_DEL_RESP)
 
        // E2t: Receive 2nd SubsDelReq and send SubsDelResp
        delreq, delmsg = e2termConn1.RecvSubsDelReq(t)
@@ -6406,6 +6653,8 @@ func TestRESTUnpackSubscriptionDeleteResponseDecodeFail(t *testing.T) {
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
+       mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6429,18 +6678,35 @@ func TestRESTUnpackSubscriptionDeleteResponseDecodeFail(t *testing.T) {
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |   SubDelResp | Unknown instanceId
-//     |                 |<-------------|
+//     |                 |<-------------| No valid subscription found with subIds [0]. This will result timer expiry and resending
 //     |                 |              |
 //     |                 | SubDelReq    |
 //     |                 |------------->|
 //     |                 |              |
-//     |                 |   SubDelFail | Subscription does exist any more
+//     |                 |   SubDelFail | Subscription does exist any more in E2 node
 //     |                 |<-------------|
-//
+//     |                 |              |
+//     |           [SUBS DELETE]        |
+//     |                 |              |
 //-----------------------------------------------------------------------------
 func TestRESTUnpackSubscriptionDeleteResponseUnknownInstanceId(t *testing.T) {
        xapp.Logger.Debug("TEST: TestRESTUnpackSubscriptionDeleteResponseUnknownInstanceId")
 
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cRestSubReqFromXapp, 1},
+               Counter{cRestSubRespToXapp, 1},
+               Counter{cSubReqToE2, 1},
+               Counter{cSubRespFromE2, 1},
+               Counter{cRestSubNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
+               Counter{cSubDelReqToE2, 1},
+               Counter{cSubDelReqTimerExpiry, 1},
+               Counter{cSubDelReReqToE2, 1},
+               Counter{cSubDelRespFromE2, 1},
+               Counter{cSubDelFailFromE2, 1},
+       })
+
        // Req
        var params *teststube2ap.RESTSubsReqParams = nil
        restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
@@ -6467,6 +6733,8 @@ func TestRESTUnpackSubscriptionDeleteResponseUnknownInstanceId(t *testing.T) {
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
+       mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6490,18 +6758,35 @@ func TestRESTUnpackSubscriptionDeleteResponseUnknownInstanceId(t *testing.T) {
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |   SubDelResp | No transaction for the response
-//     |                 |<-------------|
+//     |                 |<-------------| Ongoing transaction not found. This will result timer expiry and resending
 //     |                 |              |
 //     |                 | SubDelReq    |
 //     |                 |------------->|
 //     |                 |              |
-//     |                 |   SubDelFail | Subscription does exist any more
-//     |                 |<-------------|
-//
+//     |                 |   SubDelFail | Subscription does exist any more in E2 node
+//     |                 |<-------------| Ongoing transaction not found. This will result timer expiry
+//     |                 |              |
+//     |           [SUBS DELETE]        |
+//     |                 |              |
 //-----------------------------------------------------------------------------
 func TestRESTUnpackSubscriptionDeleteResponseNoTransaction(t *testing.T) {
        xapp.Logger.Debug("TEST: TestRESTUnpackSubscriptionDeleteResponseNoTransaction")
 
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cRestSubReqFromXapp, 1},
+               Counter{cRestSubRespToXapp, 1},
+               Counter{cSubReqToE2, 1},
+               Counter{cSubRespFromE2, 1},
+               Counter{cRestSubNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
+               Counter{cSubDelReqToE2, 1},
+               Counter{cSubDelReqTimerExpiry, 2},
+               Counter{cSubDelReReqToE2, 1},
+               Counter{cSubDelRespFromE2, 1},
+               Counter{cSubDelFailFromE2, 1},
+       })
+
        // Req
        var params *teststube2ap.RESTSubsReqParams = nil
        restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
@@ -6529,6 +6814,8 @@ func TestRESTUnpackSubscriptionDeleteResponseNoTransaction(t *testing.T) {
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
+       mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6552,18 +6839,34 @@ func TestRESTUnpackSubscriptionDeleteResponseNoTransaction(t *testing.T) {
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |   SubDelFail | ASN.1 decode fails
-//     |                 |<-------------|
+//     |                 |<-------------| Decode failed. More data needed. This will result timer expiry and resending
 //     |                 |              |
 //     |                 | SubDelReq    |
 //     |                 |------------->|
 //     |                 |              |
-//     |                 |   SubDelFail | Subscription does exist any more
+//     |                 |   SubDelFail | Subscription does exist any more in E2 node
 //     |                 |<-------------|
-//
+//     |                 |              |
+//     |           [SUBS DELETE]        |
+//     |                 |              |
 //-----------------------------------------------------------------------------
 func TestRESTUnpackSubscriptionDeleteFailureDecodeFail(t *testing.T) {
        xapp.Logger.Debug("TEST: TestRESTUnpackSubscriptionDeleteFailureDecodeFail")
 
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cRestSubReqFromXapp, 1},
+               Counter{cRestSubRespToXapp, 1},
+               Counter{cSubReqToE2, 1},
+               Counter{cSubRespFromE2, 1},
+               Counter{cRestSubNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
+               Counter{cSubDelReqToE2, 1},
+               Counter{cSubDelReqTimerExpiry, 1},
+               Counter{cSubDelReReqToE2, 1},
+               Counter{cSubDelFailFromE2, 2},
+       })
+
        // Req
        var params *teststube2ap.RESTSubsReqParams = nil
        restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
@@ -6589,6 +6892,8 @@ func TestRESTUnpackSubscriptionDeleteFailureDecodeFail(t *testing.T) {
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
+       mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6612,18 +6917,34 @@ func TestRESTUnpackSubscriptionDeleteFailureDecodeFail(t *testing.T) {
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |   SubDelFail | Unknown instanceId
-//     |                 |<-------------|
+//     |                 |<-------------| No valid subscription found with subIds [0]. This will result timer expiry and resending
 //     |                 |              |
 //     |                 | SubDelReq    |
 //     |                 |------------->|
 //     |                 |              |
-//     |                 |   SubDelFail | Subscription does exist any more
-//     |                 |<-------------|
-//
+//     |                 |   SubDelFail | Subscription does exist any more in E2 node
+//     |                 |<-------------| No valid subscription found with subIds [0].
+//     |                 |              |
+//     |           [SUBS DELETE]        |
+//     |                 |              |
 //-----------------------------------------------------------------------------
 func TestRESTUnpackSubscriptionDeleteailureUnknownInstanceId(t *testing.T) {
        xapp.Logger.Debug("TEST: TestRESTUnpackSubscriptionDeleteailureUnknownInstanceId")
 
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cRestSubReqFromXapp, 1},
+               Counter{cRestSubRespToXapp, 1},
+               Counter{cSubReqToE2, 1},
+               Counter{cSubRespFromE2, 1},
+               Counter{cRestSubNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
+               Counter{cSubDelReqToE2, 1},
+               Counter{cSubDelReqTimerExpiry, 1},
+               Counter{cSubDelReReqToE2, 1},
+               Counter{cSubDelFailFromE2, 2},
+       })
+
        // Req
        var params *teststube2ap.RESTSubsReqParams = nil
        restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
@@ -6634,14 +6955,14 @@ func TestRESTUnpackSubscriptionDeleteailureUnknownInstanceId(t *testing.T) {
        // E2t: Receive 1st SubsDelReq
        delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
 
-       // Unknown instanceId in this response which will result resending original request
+       // Unknown instanceId in this response which will result resending original request
        delreq.RequestId.InstanceId = 0
        e2termConn1.SendSubsDelFail(t, delreq, delmsg)
 
        // E2t: Receive 2nd SubsDelReq
        delreq, delmsg = e2termConn1.RecvSubsDelReq(t)
 
-       // Subscription does not exist in in E2 Node.
+       // Subscription does not exist in in E2 Node. E2 Node responds with failure but there is also same unknown instanceId 0
        e2termConn1.SendSubsDelFail(t, delreq, delmsg)
 
        // Wait that subs is cleaned
@@ -6650,6 +6971,8 @@ func TestRESTUnpackSubscriptionDeleteailureUnknownInstanceId(t *testing.T) {
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
+       mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6673,18 +6996,34 @@ func TestRESTUnpackSubscriptionDeleteailureUnknownInstanceId(t *testing.T) {
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |   SubDelFail | No transaction for the response
-//     |                 |<-------------|
+//     |                 |<-------------| Ongoing transaction not found. This will result timer expiry and resending
 //     |                 |              |
 //     |                 | SubDelReq    |
 //     |                 |------------->|
 //     |                 |              |
-//     |                 |   SubDelFail | Subscription does exist any more
-//     |                 |<-------------|
-//
+//     |                 |   SubDelFail | Subscription does exist any more in E2 node
+//     |                 |<-------------| Ongoing transaction not found. This will result timer expiry
+//     |                 |              |
+//     |           [SUBS DELETE]        |
+//     |                 |              |
 //-----------------------------------------------------------------------------
 func TestRESTUnpackSubscriptionDeleteFailureNoTransaction(t *testing.T) {
        xapp.Logger.Debug("TEST: TestRESTUnpackSubscriptionDeleteFailureNoTransaction")
 
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cRestSubReqFromXapp, 1},
+               Counter{cRestSubRespToXapp, 1},
+               Counter{cSubReqToE2, 1},
+               Counter{cSubRespFromE2, 1},
+               Counter{cRestSubNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
+               Counter{cSubDelReqToE2, 1},
+               Counter{cSubDelReqTimerExpiry, 2},
+               Counter{cSubDelReReqToE2, 1},
+               Counter{cSubDelFailFromE2, 2},
+       })
+
        // Req
        var params *teststube2ap.RESTSubsReqParams = nil
        restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
@@ -6712,6 +7051,8 @@ func TestRESTUnpackSubscriptionDeleteFailureNoTransaction(t *testing.T) {
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
+       mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6750,6 +7091,8 @@ func TestRESTSubReqFailAsn1PackSubReqError(t *testing.T) {
                Counter{cRestSubReqFromXapp, 1},
                Counter{cRestSubRespToXapp, 1},
                Counter{cRestSubFailNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cRestSubDelRespToXapp, 1},
        })
 
        const subReqCount int = 1
@@ -6769,8 +7112,12 @@ func TestRESTSubReqFailAsn1PackSubReqError(t *testing.T) {
        xapp.Logger.Debug("TEST: REST notification received e2SubsId=%v", e2SubsId)
 
        e2ap_wrapper.AllowE2apToProcess(e2ap_wrapper.SUB_REQ, true)
+
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
+       mainCtrl.VerifyAllClean(t)
        mainCtrl.VerifyCounterValues(t)
 }
 
@@ -6829,7 +7176,7 @@ func TestRESTSubReqPolicyUpdateTimeoutAndSubDelOkSameAction(t *testing.T) {
        e2termConn1.SendSubsDelResp(t, delreq, delmsg)
 
        waitSubsCleanup(t, e2SubsId, 10)
-
+       mainCtrl.VerifyAllClean(t)
        mainCtrl.VerifyCounterValues(t)
 }
 
@@ -6888,16 +7235,12 @@ func TestPolicyUpdateRESTSubReqAndSubDelOkWithRestartInMiddle(t *testing.T) {
                Counter{cSubReqToE2, 2},
                Counter{cSubRespFromE2, 1},
                Counter{cRestSubNotifToXapp, 1},
-               Counter{cRestSubFailNotifToXapp, 1},
                Counter{cRestSubDelReqFromXapp, 1},
                Counter{cSubDelReqToE2, 1},
                Counter{cSubDelRespFromE2, 1},
                Counter{cRestSubDelRespToXapp, 1},
        })
 
-       // Remove possible existing subscription
-       mainCtrl.removeExistingSubscriptions(t)
-
        const e2Timeout int64 = 1
        const e2RetryCount int64 = 0
        const routingNeeded bool = false
@@ -6935,6 +7278,10 @@ func TestPolicyUpdateRESTSubReqAndSubDelOkWithRestartInMiddle(t *testing.T) {
        mainCtrl.SimulateRestart(t)
        xapp.Logger.Debug("mainCtrl.SimulateRestart done")
 
+       // ReadE2Subscriptions() for testing is running in own go routine (go mainCtrl.c.ReadE2Subscriptions())
+       // That needs to be completed before successful subscription query is possible
+       <-time.After(time.Second * 1)
+
        // Check subscription
        queryXappSubscription(t, int64(e2SubsId), "RAN_NAME_1", []string{"localhost:13560"})
 
@@ -6947,6 +7294,7 @@ func TestPolicyUpdateRESTSubReqAndSubDelOkWithRestartInMiddle(t *testing.T) {
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 ////////////////////////////////////////////////////////////////////////////////////
@@ -7040,9 +7388,9 @@ func deleteXapp2Subscription(t *testing.T, restSubId *string) {
 
 func queryXappSubscription(t *testing.T, e2SubsId int64, meid string, endpoint []string) {
        resp, _ := xapp.Subscription.QuerySubscriptions()
-       assert.Equal(t, resp[0].SubscriptionID, e2SubsId)
-       assert.Equal(t, resp[0].Meid, meid)
-       assert.Equal(t, resp[0].ClientEndpoint, endpoint)
+       assert.Equal(t, e2SubsId, resp[0].SubscriptionID)
+       assert.Equal(t, meid, resp[0].Meid)
+       assert.Equal(t, endpoint, resp[0].ClientEndpoint)
 }
 
 func waitSubsCleanup(t *testing.T, e2SubsId uint32, timeout int) {