X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fmessaging_test.go;h=4465d6cd9d7d382e78f5cc4c983df6158494a7d5;hb=af91f971681842c22dc0fad165c0cbf7ebaa0e4d;hp=ed314231ae609f6687d020ad42356b5a52f03620;hpb=7e9c5e52615fef7cbc23de28505e1a7292cdf14f;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/messaging_test.go b/pkg/control/messaging_test.go index ed31423..4465d6c 100644 --- a/pkg/control/messaging_test.go +++ b/pkg/control/messaging_test.go @@ -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 } @@ -586,6 +623,45 @@ func (mc *testingMainControl) wait_msgcounter_change(t *testing.T, orig uint64, return 0, false } +//----------------------------------------------------------------------------- +// TestSubReqAndRouteNok +// +// stub stub +// +-------+ +---------+ +---------+ +// | xapp | | submgr | | rtmgr | +// +-------+ +---------+ +---------+ +// | | | +// | SubReq | | +// |------------->| | +// | | | +// | | RouteCreate | +// | |------------->| +// | | | +// | | RouteCreate | +// | | status:400 | +// | |<-------------| +// | | | +// | [SUBS INT DELETE] | +// | | | +// +//----------------------------------------------------------------------------- + +func TestSubReqAndRouteNok(t *testing.T) { + xapp.Logger.Info("TestSubReqAndRouteNok") + + waiter := rtmgrHttp.AllocNextEvent(false) + newSubsId := mainCtrl.get_subid(t) + xappConn1.handle_xapp_subs_req(t, nil) + waiter.WaitResult(t) + + //Wait that subs is cleaned + mainCtrl.wait_subs_clean(t, int(newSubsId), 10) + + xappConn1.TestMsgCnt(t) + xappConn2.TestMsgCnt(t) + e2termConn.TestMsgCnt(t) +} + //----------------------------------------------------------------------------- // TestSubReqAndSubDelOk // @@ -623,18 +699,27 @@ func (mc *testingMainControl) wait_msgcounter_change(t *testing.T, orig uint64, func TestSubReqAndSubDelOk(t *testing.T) { xapp.Logger.Info("TestSubReqAndSubDelOk") + waiter := rtmgrHttp.AllocNextEvent(true) cretrans := xappConn1.handle_xapp_subs_req(t, nil) + waiter.WaitResult(t) + crereq, cremsg := e2termConn.handle_e2term_subs_req(t) e2termConn.handle_e2term_subs_resp(t, crereq, cremsg) e2SubsId := xappConn1.handle_xapp_subs_resp(t, cretrans) - deltrans := xappConn1.handle_xapp_subs_del_req(t, nil, e2SubsId) delreq, delmsg := e2termConn.handle_e2term_subs_del_req(t) + + waiter = rtmgrHttp.AllocNextEvent(true) e2termConn.handle_e2term_subs_del_resp(t, delreq, delmsg) xappConn1.handle_xapp_subs_del_resp(t, deltrans) + waiter.WaitResult(t) //Wait that subs is cleaned mainCtrl.wait_subs_clean(t, e2SubsId, 10) + + xappConn1.TestMsgCnt(t) + xappConn2.TestMsgCnt(t) + e2termConn.TestMsgCnt(t) } //----------------------------------------------------------------------------- @@ -687,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) } //----------------------------------------------------------------------------- @@ -740,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) } //----------------------------------------------------------------------------- @@ -794,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) } //----------------------------------------------------------------------------- @@ -868,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) } //----------------------------------------------------------------------------- @@ -945,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) } //----------------------------------------------------------------------------- @@ -1000,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) } //----------------------------------------------------------------------------- @@ -1053,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) } //----------------------------------------------------------------------------- @@ -1104,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) } //----------------------------------------------------------------------------- @@ -1139,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) } //----------------------------------------------------------------------------- @@ -1202,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) } //----------------------------------------------------------------------------- @@ -1255,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) } //----------------------------------------------------------------------------- @@ -1305,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) }