Fix for E2 Connection status counters
[ric-plt/submgr.git] / pkg / control / ut_messaging_test.go
index 99ceafc..79eccd2 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.VerifyAllClean(t)
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
-       //os.Exit(1)
+       //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
@@ -176,7 +186,7 @@ func TestRESTSubReqE2ConnBreak(t *testing.T) {
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -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
@@ -253,7 +265,7 @@ func TestRESTSubscriptionDeleteAfterE2ConnectionBreak(t *testing.T) {
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -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")
@@ -317,7 +330,7 @@ func TestRESTOtherE2ConnectionChanges(t *testing.T) {
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -367,7 +380,7 @@ func TestRESTSubReqAndDeleteOkWithE2apUtWrapper(t *testing.T) {
        deleteSubscription(t, xappConn1, e2termConn1, &restSubId)
 
        waitSubsCleanup(t, e2SubsId, 10)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -414,7 +427,7 @@ func TestRESTSubReqAndE1apDeleteReqPackingError(t *testing.T) {
        defer e2ap_wrapper.AllowE2apToProcess(e2ap_wrapper.SUB_DEL_REQ, true)
 
        waitSubsCleanup(t, e2SubsId, 10)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -477,7 +490,7 @@ func TestRESTSubReqAndE1apDeleteRespUnpackingError(t *testing.T) {
        defer e2ap_wrapper.AllowE2apToProcess(e2ap_wrapper.SUB_DEL_RESP, true)
 
        waitSubsCleanup(t, e2SubsId, 10)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -2375,9 +2388,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 +2469,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 +2567,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 +2575,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 +2594,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)
@@ -2699,7 +2721,7 @@ func TestRESTSubReqAndRouteNok(t *testing.T) {
        mainCtrl.wait_subs_clean(t, newSubsId, 10)
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqAndRouteUpdateNok(t *testing.T) {
@@ -2714,10 +2736,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
@@ -2736,19 +2758,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)    //This test case is not working correctly
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubDelReqAndRouteDeleteNok(t *testing.T) {
@@ -2782,9 +2804,8 @@ func TestRESTSubDelReqAndRouteDeleteNok(t *testing.T) {
        waiter.WaitResult(t)
 
        waitSubsCleanup(t, e2SubsId, 10)
-
        mainCtrl.VerifyCounterValues(t)
-       ////mainCtrl.VerifyAllClean(t)  This test case is not working correctly
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubMergeDelAndRouteUpdateNok(t *testing.T) {
@@ -2827,7 +2848,7 @@ func TestRESTSubMergeDelAndRouteUpdateNok(t *testing.T) {
 
        waitSubsCleanup(t, e2SubsId2, 10)
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -2883,34 +2904,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)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -2977,27 +2996,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)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3063,7 +3082,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)
@@ -3071,7 +3090,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)
@@ -3079,15 +3098,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)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3167,7 +3184,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)
@@ -3188,7 +3205,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)
@@ -3201,16 +3218,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)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3290,7 +3307,7 @@ 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.
        params2 := xappConn1.GetRESTSubsReqReportParams(subReqCount + 1)
@@ -3313,7 +3330,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)
@@ -3326,16 +3343,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)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3424,7 +3441,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)
@@ -3445,7 +3462,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)
@@ -3459,15 +3476,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)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubDelReqRetransmission(t *testing.T) {
@@ -3503,9 +3518,8 @@ func TestRESTSubDelReqRetransmission(t *testing.T) {
        e2termConn1.SendSubsDelResp(t, delreq, delmsg)
 
        waitSubsCleanup(t, e2SubsId, 10)
-
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3577,7 +3591,7 @@ func TestRESTSubReqDelReq(t *testing.T) {
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubDelReqCollision(t *testing.T) {
@@ -3635,7 +3649,7 @@ func TestRESTSubReqAndSubDelOkTwoParallel(t *testing.T) {
        waitSubsCleanup(t, e2SubsIdB.E2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSameSubsDiffRan(t *testing.T) {
@@ -3672,7 +3686,7 @@ func TestRESTSameSubsDiffRan(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqRetryInSubmgr(t *testing.T) {
@@ -3717,7 +3731,7 @@ func TestRESTSubReqRetryInSubmgr(t *testing.T) {
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3772,7 +3786,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)
@@ -3788,11 +3805,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)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestREST2eTermNotRespondingToSubReq(t *testing.T) {
@@ -3809,7 +3827,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)
@@ -3829,10 +3850,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)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3887,6 +3909,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)
@@ -3908,10 +3932,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)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -3979,7 +4004,7 @@ func TestRESTSubReqSubFailRespInSubmgr(t *testing.T) {
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4043,7 +4068,7 @@ func TestRESTSubDelReqRetryInSubmgr(t *testing.T) {
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4106,7 +4131,7 @@ func TestRESTSubDelReqTwoRetriesNoRespInSubmgr(t *testing.T) {
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4163,7 +4188,7 @@ func TestRESTSubDelReqSubDelFailRespInSubmgr(t *testing.T) {
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4263,9 +4288,8 @@ func TestRESTSubReqAndSubDelOkSameAction(t *testing.T) {
 
        //Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId2, 10)
-
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4358,9 +4382,8 @@ func TestRESTSubReqAndSubDelOkSameActionParallel(t *testing.T) {
        e2termConn1.SendSubsDelResp(t, delreq2, delmsg2)
 
        waitSubsCleanup(t, e2SubsId2, 10)
-
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4425,6 +4448,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},
@@ -4467,9 +4491,8 @@ func TestRESTSubReqAndSubDelNoAnswerSameActionParallel(t *testing.T) {
 
        //Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsIdA.E2SubsId, 10)
-
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4527,6 +4550,7 @@ func TestRESTSubReqAndSubDelNokSameActionParallel(t *testing.T) {
                Counter{cSubReqToE2, 1},
                Counter{cSubFailFromE2, 1},
                Counter{cRestSubFailNotifToXapp, 2},
+               Counter{cUnmergedSubscriptions, 1},
                Counter{cRestSubDelReqFromXapp, 2},
                Counter{cRestSubDelRespToXapp, 2},
        })
@@ -4565,9 +4589,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)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqPolicyAndSubDelOk(t *testing.T) {
@@ -4603,7 +4626,7 @@ func TestRESTSubReqPolicyAndSubDelOk(t *testing.T) {
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4698,7 +4721,7 @@ func TestRESTSubReqPolicyChangeAndSubDelOk(t *testing.T) {
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4780,7 +4803,7 @@ func TestRESTSubReqPolicyChangeNOk(t *testing.T) {
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4884,7 +4907,7 @@ func TestRESTSubReqAndSubDelOkTwoE2termParallel(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4984,7 +5007,7 @@ func TestRESTSubReqInsertAndSubDelOk(t *testing.T) {
        // Wait that subs is cleaned
        waitSubsCleanup(t, e2SubsId, 10)
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -4998,6 +5021,8 @@ func TestRESTSubReqInsertAndSubDelOk(t *testing.T) {
 //     | RESTSubReq   |              |
 //     |------------->|              |
 //     |              |              |
+//     |  RESTSubResp |              |
+//     |<-------------|              |
 //     |              | SubReq       |
 //     |              |------------->|
 //     |              |              |
@@ -5013,6 +5038,15 @@ func TestRESTSubReqInsertAndSubDelOk(t *testing.T) {
 //     |              |   SubDelResp |
 //     |              |<-------------|
 //     |              |              |
+//     |    RESTNotif |              |
+//     |    unsuccess |              |
+//     |<-------------|              |
+//     |              |              |
+//     | RESTSubDelReq|              |
+//     |------------->|              |
+//     |              |              |
+//     |RESTSubDelResp|              |
+//     |<-------------|              |
 //
 //-----------------------------------------------------------------------------
 func TestRESTSubReqNokAndSubDelOkWithRestartInMiddle(t *testing.T) {
@@ -5025,14 +5059,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
@@ -5047,17 +5079,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)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -5113,12 +5147,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)
 
@@ -5128,6 +5159,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"})
 
@@ -5138,7 +5173,7 @@ func TestRESTSubReqAndSubDelOkWithRestartInMiddle(t *testing.T) {
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -5195,7 +5230,6 @@ func TestRESTSubReqAndSubDelOkWithRestartInMiddle(t *testing.T) {
 //     |             |                 |              |
 //
 //-----------------------------------------------------------------------------
-
 func TestRESTSubReqAndSubDelOkSameActionWithRestartsInMiddle(t *testing.T) {
        CaseBegin("TestRESTSubReqAndSubDelOkSameActionWithRestartsInMiddle")
 
@@ -5213,12 +5247,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)
 
@@ -5235,15 +5265,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
@@ -5253,7 +5292,7 @@ func TestRESTSubReqAndSubDelOkSameActionWithRestartsInMiddle(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -5347,11 +5386,11 @@ 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.VerifyAllClean(t)
 }
 
 /*
-func TestRESTPolicySubReqAndSubDelOk(t *testing.T) {
+func TestRESTPolicySubReqAndSubDelOk(t *testing.T) {  was in comments already
        CaseBegin("TestRESTPolicySubReqAndSubDelOk")
 
        subReqCount := 2
@@ -5395,7 +5434,7 @@ 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.VerifyAllClean(t)
 }
 
 func TestRESTTwoPolicySubReqAndSubDelOk(t *testing.T) {
@@ -5430,7 +5469,7 @@ func TestRESTTwoPolicySubReqAndSubDelOk(t *testing.T) {
        mainCtrl.wait_registry_empty(t, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 func TestRESTPolicySubReqAndSubDelOkFullAmount(t *testing.T) {
 
@@ -5462,7 +5501,7 @@ func TestRESTPolicySubReqAndSubDelOkFullAmount(t *testing.T) {
        mainCtrl.wait_registry_empty(t, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTTwoReportSubReqAndSubDelOk(t *testing.T) {
@@ -5497,7 +5536,7 @@ func TestRESTTwoReportSubReqAndSubDelOk(t *testing.T) {
        mainCtrl.wait_registry_empty(t, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTTwoReportSubReqAndSubDelOkNoActParams(t *testing.T) {
@@ -5532,7 +5571,7 @@ func TestRESTTwoReportSubReqAndSubDelOkNoActParams(t *testing.T) {
        mainCtrl.wait_registry_empty(t, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTFullAmountReportSubReqAndSubDelOk(t *testing.T) {
@@ -5567,7 +5606,7 @@ func TestRESTFullAmountReportSubReqAndSubDelOk(t *testing.T) {
        mainCtrl.wait_registry_empty(t, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqReportSameActionDiffEventTriggerDefinitionLen(t *testing.T) {
@@ -5614,7 +5653,7 @@ func TestRESTSubReqReportSameActionDiffEventTriggerDefinitionLen(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqReportSameActionDiffActionListLen(t *testing.T) {
@@ -5666,7 +5705,7 @@ func TestRESTSubReqReportSameActionDiffActionListLen(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqReportSameActionDiffActionID(t *testing.T) {
@@ -5712,7 +5751,7 @@ func TestRESTSubReqReportSameActionDiffActionID(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqDiffActionType(t *testing.T) {
@@ -5763,7 +5802,7 @@ func TestRESTSubReqDiffActionType(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqPolicyAndSubDelOkSameAction(t *testing.T) {
@@ -5814,7 +5853,7 @@ func TestRESTSubReqPolicyAndSubDelOkSameAction(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqReportSameActionDiffActionDefinitionLen(t *testing.T) {
@@ -5861,7 +5900,7 @@ func TestRESTSubReqReportSameActionDiffActionDefinitionLen(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqReportSameActionDiffActionDefinitionContents(t *testing.T) {
@@ -5908,7 +5947,7 @@ func TestRESTSubReqReportSameActionDiffActionDefinitionContents(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqReportSameActionDiffSubsAction(t *testing.T) {
@@ -5953,7 +5992,7 @@ func TestRESTSubReqReportSameActionDiffSubsAction(t *testing.T) {
        waitSubsCleanup(t, e2SubsId2, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6012,13 +6051,15 @@ 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.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6087,13 +6128,15 @@ 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.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6170,13 +6213,15 @@ 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.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6235,13 +6280,15 @@ 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.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6308,13 +6355,15 @@ 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.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6386,13 +6435,15 @@ 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.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6454,7 +6505,7 @@ func TestRESTUnpackSubscriptionDeleteResponseDecodeFail(t *testing.T) {
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6516,7 +6567,7 @@ func TestRESTUnpackSubscriptionDeleteResponseUnknownInstanceId(t *testing.T) {
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6579,7 +6630,7 @@ func TestRESTUnpackSubscriptionDeleteResponseNoTransaction(t *testing.T) {
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6640,7 +6691,7 @@ func TestRESTUnpackSubscriptionDeleteFailureDecodeFail(t *testing.T) {
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6702,7 +6753,7 @@ func TestRESTUnpackSubscriptionDeleteailureUnknownInstanceId(t *testing.T) {
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6765,7 +6816,7 @@ func TestRESTUnpackSubscriptionDeleteFailureNoTransaction(t *testing.T) {
        xappConn1.TestMsgChanEmpty(t)
        e2termConn1.TestMsgChanEmpty(t)
        mainCtrl.wait_registry_empty(t, 10)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6804,6 +6855,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
@@ -6823,10 +6876,13 @@ 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.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 func TestRESTSubReqPolicyUpdateTimeoutAndSubDelOkSameAction(t *testing.T) {
@@ -6886,7 +6942,7 @@ func TestRESTSubReqPolicyUpdateTimeoutAndSubDelOkSameAction(t *testing.T) {
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -6944,16 +7000,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
@@ -6991,6 +7043,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"})
 
@@ -7003,7 +7059,7 @@ func TestPolicyUpdateRESTSubReqAndSubDelOkWithRestartInMiddle(t *testing.T) {
        waitSubsCleanup(t, e2SubsId, 10)
 
        mainCtrl.VerifyCounterValues(t)
-       //mainCtrl.VerifyAllClean(t)
+       mainCtrl.VerifyAllClean(t)
 }
 
 ////////////////////////////////////////////////////////////////////////////////////
@@ -7097,9 +7153,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) {