RICPLT-3014 Subs multiple rmr endpoints
[ric-plt/submgr.git] / pkg / control / messaging_test.go
index 1b50c8b..68118ea 100644 (file)
@@ -548,24 +548,24 @@ func (mc *testingMainControl) wait_subs_trans_clean(t *testing.T, e2SubsId int,
        return false
 }
 
-func (mc *testingMainControl) get_seqcnt(t *testing.T) uint16 {
+func (mc *testingMainControl) get_subid(t *testing.T) uint16 {
        mc.c.registry.mutex.Lock()
        defer mc.c.registry.mutex.Unlock()
-       return mc.c.registry.counter
+       return mc.c.registry.subIds[0]
 }
 
-func (mc *testingMainControl) wait_seqcnt_change(t *testing.T, orig uint16, secs int) (uint16, bool) {
+func (mc *testingMainControl) wait_subid_change(t *testing.T, origSubId uint16, secs int) (uint16, bool) {
        i := 1
        for ; i <= secs*2; i++ {
                mc.c.registry.mutex.Lock()
-               curr := mc.c.registry.counter
+               currSubId := mc.c.registry.subIds[0]
                mc.c.registry.mutex.Unlock()
-               if curr != orig {
-                       return curr, true
+               if currSubId != origSubId {
+                       return currSubId, true
                }
                time.Sleep(500 * time.Millisecond)
        }
-       testError(t, "(general) no seq change within %d secs", secs)
+       testError(t, "(general) no subId change within %d secs", secs)
        return 0, false
 }
 
@@ -586,6 +586,41 @@ 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)
+}
+
 //-----------------------------------------------------------------------------
 // TestSubReqAndSubDelOk
 //
@@ -623,15 +658,20 @@ 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)
@@ -1306,5 +1346,3 @@ func TestSubDelReqSubDelFailRespInSubmgr(t *testing.T) {
        // Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, e2SubsId, 10)
 }
-
-/* */