Merge "Fix for E2 Connection status counters"
[ric-plt/submgr.git] / pkg / control / ut_messaging_test.go
index 6ce7b51..2c8bd33 100644 (file)
@@ -46,6 +46,10 @@ func TestSuiteSetup(t *testing.T) {
 }
 func TestRanStatusChangeViaSDLNotification(t *testing.T) {
 
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cE2StateChangedToUp, 3},
+       })
+
        // Current UT test cases use these ran names
        xappRnibMock.CreateGnb("RAN_NAME_1", entities.ConnectionStatus_DISCONNECTED)
        xappRnibMock.CreateGnb("RAN_NAME_11", entities.ConnectionStatus_DISCONNECTED)
@@ -57,6 +61,8 @@ func TestRanStatusChangeViaSDLNotification(t *testing.T) {
        mainCtrl.SetE2State(t, "RAN_NAME_1_CONNECTED")
        mainCtrl.SetE2State(t, "RAN_NAME_2_CONNECTED")
        mainCtrl.SetE2State(t, "RAN_NAME_11_CONNECTED")
+
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -83,6 +89,8 @@ func TestRESTSubReqAfterE2ConnBreak(t *testing.T) {
        mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
                Counter{cRestSubReqFromXapp, 1},
                Counter{cRestReqRejDueE2Down, 1},
+               Counter{cE2StateChangedToDown, 1},
+               Counter{cE2StateChangedToUp, 1},
        })
 
        // E2 disconnect after E2term has received response
@@ -95,9 +103,9 @@ func TestRESTSubReqAfterE2ConnBreak(t *testing.T) {
        // Restore E2 connection for following test cases
        mainCtrl.SetE2State(t, "RAN_NAME_1_CONNECTED")
 
-       mainCtrl.VerifyCounterValues(t)
        mainCtrl.VerifyAllClean(t)
-       //os.Exit(1)
+       mainCtrl.VerifyCounterValues(t)
+       //os.Exit(0)
 }
 
 //-----------------------------------------------------------------------------
@@ -135,6 +143,8 @@ func TestRESTSubReqE2ConnBreak(t *testing.T) {
                Counter{cSubReqToE2, 1},
                Counter{cSubRespFromE2, 1},
                Counter{cRestSubFailNotifToXapp, 1},
+               Counter{cE2StateChangedToDown, 1},
+               Counter{cE2StateChangedToUp, 1},
        })
 
        // Req
@@ -212,6 +222,8 @@ func TestRESTSubscriptionDeleteAfterE2ConnectionBreak(t *testing.T) {
                Counter{cRestSubNotifToXapp, 1},
                Counter{cRestSubDelReqFromXapp, 1},
                Counter{cRestSubDelRespToXapp, 1},
+               Counter{cE2StateChangedToDown, 1},
+               Counter{cE2StateChangedToUp, 1},
        })
 
        // Req
@@ -289,6 +301,7 @@ func TestRESTOtherE2ConnectionChanges(t *testing.T) {
                Counter{cSubDelReqToE2, 1},
                Counter{cSubDelRespFromE2, 1},
                Counter{cRestSubDelRespToXapp, 1},
+               Counter{cE2StateChangedToUp, 1},
        })
 
        // Req
@@ -300,7 +313,7 @@ func TestRESTOtherE2ConnectionChanges(t *testing.T) {
        e2termConn1.SendSubsResp(t, crereq, cremsg)
        e2SubsId := xappConn1.WaitRESTNotification(t, restSubId)
 
-       // Submgr should not react any other connection state changes than CONNECTED and DISCONNECTED
+       // Submgr should not react to any other connection state changes than CONNECTED and DISCONNECTED
        mainCtrl.SetE2State(t, "RAN_NAME_1_CONNECTED_SETUP_FAILED")
        mainCtrl.SetE2State(t, "RAN_NAME_1_CONNECTING")
        mainCtrl.SetE2State(t, "RAN_NAME_1_SHUTTING_DOWN")
@@ -675,7 +688,6 @@ func TestSubDelReqAndRouteDeleteNok(t *testing.T) {
        xappConn2.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
-
        mainCtrl.VerifyCounterValues(t)
 }
 
@@ -2375,9 +2387,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)
@@ -2459,6 +2468,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))
@@ -2553,7 +2566,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"})
@@ -2561,6 +2574,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))
@@ -2576,6 +2593,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)
@@ -2974,19 +2995,21 @@ 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)
 
@@ -3058,7 +3081,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)
@@ -3066,7 +3089,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)
@@ -3074,7 +3097,7 @@ func TestRESTSubReqRetransmissionV3(t *testing.T) {
 
        assert.Equal(t, restSubId_resend2, restSubId)
 
-       <-time.After(100 * time.Millisecond)
+       mainCtrl.WaitOngoingRequestMapEmpty()
 
        deleteSubscription(t, xappConn1, e2termConn1, &restSubId)
 
@@ -3160,7 +3183,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)
@@ -3181,7 +3204,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)
@@ -3194,6 +3217,8 @@ 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}
@@ -3281,9 +3306,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)
 
@@ -3304,7 +3329,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)
@@ -3317,6 +3342,8 @@ 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}
@@ -3413,7 +3440,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)
@@ -3434,7 +3461,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)
@@ -3448,7 +3475,7 @@ 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)
 
@@ -4358,7 +4385,6 @@ func TestRESTSubReqAndSubDelOkSameActionParallel(t *testing.T) {
        mainCtrl.VerifyAllClean(t)
 }
 
-/*
 //-----------------------------------------------------------------------------
 // TestRESTSubReqAndSubDelNoAnswerSameActionParallel
 //
@@ -4421,6 +4447,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},
@@ -4522,6 +4549,7 @@ func TestRESTSubReqAndSubDelNokSameActionParallel(t *testing.T) {
                Counter{cSubReqToE2, 1},
                Counter{cSubFailFromE2, 1},
                Counter{cRestSubFailNotifToXapp, 2},
+               Counter{cUnmergedSubscriptions, 1},
                Counter{cRestSubDelReqFromXapp, 2},
                Counter{cRestSubDelRespToXapp, 2},
        })
@@ -4563,7 +4591,7 @@ func TestRESTSubReqAndSubDelNokSameActionParallel(t *testing.T) {
        mainCtrl.VerifyCounterValues(t)
        mainCtrl.VerifyAllClean(t)
 }
-*/
+
 func TestRESTSubReqPolicyAndSubDelOk(t *testing.T) {
        CaseBegin("TestRESTSubReqPolicyAndSubDelOk")
 
@@ -5030,16 +5058,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
@@ -5122,12 +5146,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)
 
@@ -5137,6 +5158,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"})
 
@@ -5204,7 +5229,6 @@ func TestRESTSubReqAndSubDelOkWithRestartInMiddle(t *testing.T) {
 //     |             |                 |              |
 //
 //-----------------------------------------------------------------------------
-
 func TestRESTSubReqAndSubDelOkSameActionWithRestartsInMiddle(t *testing.T) {
        CaseBegin("TestRESTSubReqAndSubDelOkSameActionWithRestartsInMiddle")
 
@@ -5222,12 +5246,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)
 
@@ -5244,15 +5264,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
@@ -5299,14 +5328,14 @@ func TestRESTSubReqAndSubDelOkSameActionWithRestartsInMiddle(t *testing.T) {
 //     | RESTSubDelReq   |              |
 //     |---------------->|              |
 //     |                 |              |
+//     |   RESTSubDelResp|              |
+//     |<----------------|              |
 //     |                 | SubDelReq    |
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |   SubDelResp |
 //     |                 |<-------------|
 //     |                 |              |
-//     |   RESTSubDelResp|              |
-//     |<----------------|              |
 //
 //-----------------------------------------------------------------------------
 
@@ -5320,6 +5349,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)
@@ -5357,10 +5398,11 @@ func RESTReportSubReqAndSubDelOk(t *testing.T, subReqCount int, testIndex int) {
        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
@@ -5375,6 +5417,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)
@@ -5405,6 +5459,7 @@ func RESTPolicySubReqAndSubDelOk(t *testing.T, subReqCount int, testIndex int) {
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
        mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 func TestRESTTwoPolicySubReqAndSubDelOk(t *testing.T) {
@@ -5983,7 +6038,7 @@ func TestRESTSubReqReportSameActionDiffSubsAction(t *testing.T) {
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |      SubResp | ASN.1 decode fails
-//     |                 |<-------------|
+//     |                 |<-------------| Decode failed. More data needed. This will result timer expiry and resending
 //     |                 |              |
 //     |                 | SubReq       |
 //     |                 |------------->|
@@ -5993,11 +6048,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
@@ -6030,6 +6101,7 @@ func TestRESTUnpackSubscriptionResponseDecodeFail(t *testing.T) {
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
        mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6050,13 +6122,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    |
@@ -6064,11 +6136,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
@@ -6077,7 +6168,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)
@@ -6086,7 +6177,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
@@ -6107,6 +6198,7 @@ func TestRESTUnpackSubscriptionResponseUnknownInstanceId(t *testing.T) {
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
        mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6127,30 +6219,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
@@ -6192,6 +6305,7 @@ func TestRESTUnpackSubscriptionResponseNoTransaction(t *testing.T) {
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
        mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6212,7 +6326,7 @@ func TestRESTUnpackSubscriptionResponseNoTransaction(t *testing.T) {
 //     |                 |------------->|
 //     |                 |              |
 //     |                 |      SubFail | ASN.1 decode fails
-//     |                 |<-------------|
+//     |                 |<-------------| Decode failed. More data needed. This will result timer expiry and resending
 //     |                 |              |
 //     |                 | SubReq       |
 //     |                 |------------->|
@@ -6222,10 +6336,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
@@ -6259,6 +6388,7 @@ func TestRESTUnpackSubscriptionFailureDecodeFail(t *testing.T) {
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
        mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6279,13 +6409,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    |
@@ -6293,19 +6423,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
@@ -6315,7 +6462,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)
 
@@ -6334,6 +6481,7 @@ func TestRESTUnpackSubscriptionFailureUnknownInstanceId(t *testing.T) {
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
        mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6354,26 +6502,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)
@@ -6414,6 +6587,7 @@ func TestRESTUnpackSubscriptionFailureNoTransaction(t *testing.T) {
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
        mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6436,20 +6610,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)
@@ -6461,7 +6652,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)
@@ -6476,6 +6667,7 @@ func TestRESTUnpackSubscriptionDeleteResponseDecodeFail(t *testing.T) {
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
        mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6499,18 +6691,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)
@@ -6538,6 +6747,7 @@ func TestRESTUnpackSubscriptionDeleteResponseUnknownInstanceId(t *testing.T) {
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
        mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6561,18 +6771,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)
@@ -6601,6 +6828,7 @@ func TestRESTUnpackSubscriptionDeleteResponseNoTransaction(t *testing.T) {
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
        mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6624,18 +6852,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)
@@ -6662,6 +6906,7 @@ func TestRESTUnpackSubscriptionDeleteFailureDecodeFail(t *testing.T) {
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
        mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6685,18 +6930,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)
@@ -6707,14 +6968,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
@@ -6724,6 +6985,7 @@ func TestRESTUnpackSubscriptionDeleteailureUnknownInstanceId(t *testing.T) {
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
        mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6747,18 +7009,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)
@@ -6787,6 +7065,7 @@ func TestRESTUnpackSubscriptionDeleteFailureNoTransaction(t *testing.T) {
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
        mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6851,8 +7130,8 @@ func TestRESTSubReqFailAsn1PackSubReqError(t *testing.T) {
 
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
-       mainCtrl.VerifyCounterValues(t)
        mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 func TestRESTSubReqPolicyUpdateTimeoutAndSubDelOkSameAction(t *testing.T) {
@@ -6910,9 +7189,8 @@ func TestRESTSubReqPolicyUpdateTimeoutAndSubDelOkSameAction(t *testing.T) {
        e2termConn1.SendSubsDelResp(t, delreq, delmsg)
 
        waitSubsCleanup(t, e2SubsId, 10)
-
-       mainCtrl.VerifyCounterValues(t)
        mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyCounterValues(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6970,16 +7248,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
@@ -7017,6 +7291,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"})
 
@@ -7123,9 +7401,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) {