Fixed function id handling and improved ut fail handling
[ric-plt/submgr.git] / pkg / control / messaging_test.go
index 68118ea..4465d6c 100644 (file)
@@ -115,6 +115,7 @@ func (xappConn *testingXappControl) handle_xapp_subs_resp(t *testing.T, trans *x
        //---------------------------------
        select {
        case msg := <-xappConn.rmrConChan:
+               xappConn.DecMsgCnt()
                if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
                        testError(t, "(%s) Received RIC_SUB_RESP wrong mtype expected %s got %s, error", xappConn.desc, "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
                        return -1
@@ -158,6 +159,7 @@ func (xappConn *testingXappControl) handle_xapp_subs_fail(t *testing.T, trans *x
        //-------------------------------
        select {
        case msg := <-xappConn.rmrConChan:
+               xappConn.DecMsgCnt()
                if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] {
                        testError(t, "(%s) Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", xappConn.desc, "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype])
                        return -1
@@ -246,6 +248,7 @@ func (xappConn *testingXappControl) handle_xapp_subs_del_resp(t *testing.T, tran
        //---------------------------------
        select {
        case msg := <-xappConn.rmrConChan:
+               xappConn.DecMsgCnt()
                if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
                        testError(t, "(%s) Received RIC_SUB_DEL_RESP wrong mtype expected %s got %s, error", xappConn.desc, "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype])
                        return
@@ -283,6 +286,7 @@ func (e2termConn *testingE2termControl) handle_e2term_subs_req(t *testing.T) (*e
        //---------------------------------
        select {
        case msg := <-e2termConn.rmrConChan:
+               e2termConn.DecMsgCnt()
                if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
                        testError(t, "(%s) Received wrong mtype expected %s got %s, error", e2termConn.desc, "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype])
                } else {
@@ -342,10 +346,11 @@ func (e2termConn *testingE2termControl) handle_e2term_subs_resp(t *testing.T, re
 
        params := &RMRParams{&xapp.RMRParams{}}
        params.Mtype = xapp.RIC_SUB_RESP
-       params.SubId = msg.SubId
+       //params.SubId = msg.SubId
+       params.SubId = -1
        params.Payload = packedMsg.Buf
        params.Meid = msg.Meid
-       params.Xid = msg.Xid
+       //params.Xid = msg.Xid
        params.Mbuf = nil
 
        snderr := e2termConn.RmrSend(params)
@@ -357,7 +362,39 @@ func (e2termConn *testingE2termControl) handle_e2term_subs_resp(t *testing.T, re
 //-----------------------------------------------------------------------------
 //
 //-----------------------------------------------------------------------------
-func (e2termConn *testingE2termControl) handle_e2term_subs_fail(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *RMRParams) {
+type test_subs_fail_params struct {
+       req  *e2ap.E2APSubscriptionRequest
+       fail *e2ap.E2APSubscriptionFailure
+}
+
+func (p *test_subs_fail_params) Set(req *e2ap.E2APSubscriptionRequest) {
+       p.req = req
+
+       p.fail = &e2ap.E2APSubscriptionFailure{}
+       p.fail.RequestId.Id = p.req.RequestId.Id
+       p.fail.RequestId.Seq = p.req.RequestId.Seq
+       p.fail.FunctionId = p.req.FunctionId
+       p.fail.ActionNotAdmittedList.Items = make([]e2ap.ActionNotAdmittedItem, len(p.req.ActionSetups))
+       for index := int(0); index < len(p.fail.ActionNotAdmittedList.Items); index++ {
+               p.fail.ActionNotAdmittedList.Items[index].ActionId = p.req.ActionSetups[index].ActionId
+               p.SetCauseVal(index, 5, 1)
+       }
+}
+
+func (p *test_subs_fail_params) SetCauseVal(ind int, content uint8, causeval uint8) {
+
+       if ind < 0 {
+               for index := int(0); index < len(p.fail.ActionNotAdmittedList.Items); index++ {
+                       p.fail.ActionNotAdmittedList.Items[index].Cause.Content = content
+                       p.fail.ActionNotAdmittedList.Items[index].Cause.CauseVal = causeval
+               }
+               return
+       }
+       p.fail.ActionNotAdmittedList.Items[ind].Cause.Content = content
+       p.fail.ActionNotAdmittedList.Items[ind].Cause.CauseVal = causeval
+}
+
+func (e2termConn *testingE2termControl) handle_e2term_subs_fail(t *testing.T, fparams *test_subs_fail_params, msg *RMRParams) {
        xapp.Logger.Info("(%s) handle_e2term_subs_fail", e2termConn.desc)
        e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
 
@@ -366,19 +403,7 @@ func (e2termConn *testingE2termControl) handle_e2term_subs_fail(t *testing.T, re
        //---------------------------------
        xapp.Logger.Info("(%s) Send Subs Fail", e2termConn.desc)
 
-       resp := &e2ap.E2APSubscriptionFailure{}
-       resp.RequestId.Id = req.RequestId.Id
-       resp.RequestId.Seq = req.RequestId.Seq
-       resp.FunctionId = req.FunctionId
-
-       resp.ActionNotAdmittedList.Items = make([]e2ap.ActionNotAdmittedItem, len(resp.ActionNotAdmittedList.Items))
-       for index := int(0); index < len(resp.ActionNotAdmittedList.Items); index++ {
-               resp.ActionNotAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
-               resp.ActionNotAdmittedList.Items[index].Cause.Content = 3  // CauseMisc
-               resp.ActionNotAdmittedList.Items[index].Cause.CauseVal = 4 // unspecified
-       }
-
-       e2SubsFail.Set(resp)
+       e2SubsFail.Set(fparams.fail)
        xapp.Logger.Debug("%s", e2SubsFail.String())
        packerr, packedMsg := e2SubsFail.Pack(nil)
        if packerr != nil {
@@ -411,6 +436,7 @@ func (e2termConn *testingE2termControl) handle_e2term_subs_del_req(t *testing.T)
        //---------------------------------
        select {
        case msg := <-e2termConn.rmrConChan:
+               e2termConn.DecMsgCnt()
                if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
                        testError(t, "(%s) Received wrong mtype expected %s got %s, error", e2termConn.desc, "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype])
                } else {
@@ -520,31 +546,42 @@ func (e2termConn *testingE2termControl) handle_e2term_subs_del_fail(t *testing.T
 //
 //-----------------------------------------------------------------------------
 func (mc *testingMainControl) wait_subs_clean(t *testing.T, e2SubsId int, secs int) bool {
+       var subs *Subscription
        i := 1
        for ; i <= secs*2; i++ {
-               if mc.c.registry.GetSubscription(uint16(e2SubsId)) == nil {
+               subs = mc.c.registry.GetSubscription(uint16(e2SubsId))
+               if subs == nil {
                        return true
                }
                time.Sleep(500 * time.Millisecond)
        }
-       testError(t, "(general) no clean within %d secs", secs)
+       if subs != nil {
+               testError(t, "(general) no clean within %d secs: %s", secs, subs.String())
+       } else {
+               testError(t, "(general) no clean within %d secs: subs(N/A)", secs)
+       }
        return false
 }
 
 func (mc *testingMainControl) wait_subs_trans_clean(t *testing.T, e2SubsId int, secs int) bool {
+       var trans *Transaction
        i := 1
        for ; i <= secs*2; i++ {
                subs := mc.c.registry.GetSubscription(uint16(e2SubsId))
                if subs == nil {
                        return true
                }
-               trans := subs.GetTransaction()
+               trans = subs.GetTransaction()
                if trans == nil {
                        return true
                }
                time.Sleep(500 * time.Millisecond)
        }
-       testError(t, "(general) no clean within %d secs", secs)
+       if trans != nil {
+               testError(t, "(general) no clean within %d secs: %s", secs, trans.String())
+       } else {
+               testError(t, "(general) no clean within %d secs: trans(N/A)", secs)
+       }
        return false
 }
 
@@ -619,6 +656,10 @@ func TestSubReqAndRouteNok(t *testing.T) {
 
        //Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, int(newSubsId), 10)
+
+       xappConn1.TestMsgCnt(t)
+       xappConn2.TestMsgCnt(t)
+       e2termConn.TestMsgCnt(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -675,6 +716,10 @@ func TestSubReqAndSubDelOk(t *testing.T) {
 
        //Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgCnt(t)
+       xappConn2.TestMsgCnt(t)
+       e2termConn.TestMsgCnt(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -727,6 +772,10 @@ func TestSubReqRetransmission(t *testing.T) {
 
        //Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgCnt(t)
+       xappConn2.TestMsgCnt(t)
+       e2termConn.TestMsgCnt(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -780,6 +829,10 @@ func TestSubDelReqRetransmission(t *testing.T) {
 
        //Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgCnt(t)
+       xappConn2.TestMsgCnt(t)
+       e2termConn.TestMsgCnt(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -834,6 +887,10 @@ func TestSubDelReqCollision(t *testing.T) {
 
        //Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgCnt(t)
+       xappConn2.TestMsgCnt(t)
+       e2termConn.TestMsgCnt(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -908,6 +965,10 @@ func TestSubReqAndSubDelOkTwoParallel(t *testing.T) {
        xappConn2.handle_xapp_subs_del_resp(t, deltrans2)
        //Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, e2SubsId2, 10)
+
+       xappConn1.TestMsgCnt(t)
+       xappConn2.TestMsgCnt(t)
+       e2termConn.TestMsgCnt(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -985,6 +1046,10 @@ func TestSameSubsDiffRan(t *testing.T) {
        xappConn1.handle_xapp_subs_del_resp(t, deltrans2)
        //Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, e2SubsId2, 10)
+
+       xappConn1.TestMsgCnt(t)
+       xappConn2.TestMsgCnt(t)
+       e2termConn.TestMsgCnt(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -1040,6 +1105,10 @@ func TestSubReqRetryInSubmgr(t *testing.T) {
 
        // Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgCnt(t)
+       xappConn2.TestMsgCnt(t)
+       e2termConn.TestMsgCnt(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -1093,6 +1162,10 @@ func TestSubReqRetryNoRespSubDelRespInSubmgr(t *testing.T) {
 
        // Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, int(delreq.RequestId.Seq), 10)
+
+       xappConn1.TestMsgCnt(t)
+       xappConn2.TestMsgCnt(t)
+       e2termConn.TestMsgCnt(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -1144,7 +1217,11 @@ func TestSubReqTwoRetriesNoRespAtAllInSubmgr(t *testing.T) {
        delreq, _ := e2termConn.handle_e2term_subs_del_req(t)
 
        // Wait that subs is cleaned
-       mainCtrl.wait_subs_clean(t, int(delreq.RequestId.Seq), 10)
+       mainCtrl.wait_subs_clean(t, int(delreq.RequestId.Seq), 15)
+
+       xappConn1.TestMsgCnt(t)
+       xappConn2.TestMsgCnt(t)
+       e2termConn.TestMsgCnt(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -1179,13 +1256,19 @@ func TestSubReqSubFailRespInSubmgr(t *testing.T) {
 
        // E2t: Receive SubsReq and send SubsFail
        crereq, cremsg := e2termConn.handle_e2term_subs_req(t)
-       e2termConn.handle_e2term_subs_fail(t, crereq, cremsg)
+       fparams := &test_subs_fail_params{}
+       fparams.Set(crereq)
+       e2termConn.handle_e2term_subs_fail(t, fparams, cremsg)
 
        // Xapp: Receive SubsFail
        e2SubsId := xappConn1.handle_xapp_subs_fail(t, cretrans)
 
        // Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgCnt(t)
+       xappConn2.TestMsgCnt(t)
+       e2termConn.TestMsgCnt(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -1242,6 +1325,10 @@ func TestSubDelReqRetryInSubmgr(t *testing.T) {
 
        // Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgCnt(t)
+       xappConn2.TestMsgCnt(t)
+       e2termConn.TestMsgCnt(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -1295,6 +1382,10 @@ func TestSubDelReqTwoRetriesNoRespInSubmgr(t *testing.T) {
 
        // Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgCnt(t)
+       xappConn2.TestMsgCnt(t)
+       e2termConn.TestMsgCnt(t)
 }
 
 //-----------------------------------------------------------------------------
@@ -1345,4 +1436,8 @@ func TestSubDelReqSubDelFailRespInSubmgr(t *testing.T) {
 
        // Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgCnt(t)
+       xappConn2.TestMsgCnt(t)
+       e2termConn.TestMsgCnt(t)
 }