Unit test improvement 47/7347/1
authorAnssi Mannila <anssi.mannila@nokia.com>
Tue, 14 Dec 2021 08:28:20 +0000 (10:28 +0200)
committerAnssi Mannila <anssi.mannila@nokia.com>
Tue, 14 Dec 2021 08:31:15 +0000 (10:31 +0200)
 - Fixed dealy replaced with waiting function in one UT case
 - This should fix random crashes seen in that UT case

Change-Id: Ia2d342cb14560349b3ba45eb8ea13e233b6bd0a4
Signed-off-by: Anssi Mannila <anssi.mannila@nokia.com>
pkg/control/ut_ctrl_submgr_test.go
pkg/control/ut_messaging_test.go

index 4e2c471..dadf42f 100644 (file)
@@ -297,8 +297,8 @@ func (mc *testingSubmgrControl) VerifyAllClean(t *testing.T) {
                                break
                        }
                }
+               xapp.Logger.Debug("VerifyAllClean. Adding 100ms more delay to complete")
                <-time.After(time.Millisecond * 100)
-               xapp.Logger.Debug("VerifyAllClean delay plus 100ms")
        }
 
        assert.Equal(t, 0, len(mainCtrl.c.registry.register))
@@ -317,7 +317,17 @@ func (mc *testingSubmgrControl) WaitOngoingRequestMapEmpty() {
        for i := 0; i < 100; i++ {
                if len(mainCtrl.c.restDuplicateCtrl.ongoingRequestMap) != 0 {
                        <-time.After(time.Millisecond * 100)
-                       xapp.Logger.Debug("WaitOngoingRequestMapEmpty delay plus 100ms")
+                       xapp.Logger.Debug("WaitOngoingRequestMapEmpty. Adding 100ms more delay to complete")
+               }
+       }
+}
+
+func (mc *testingSubmgrControl) WaitRESTSubscriptionDelete(restSubsId string) {
+       for i := 0; i < 100; i++ {
+               restSubscription, _ := mainCtrl.c.registry.GetRESTSubscription(restSubsId, false)
+               if restSubscription != nil {
+                       xapp.Logger.Debug("WaitRESTSubscriptionDelete. Adding 100ms more delay to complete")
+                       <-time.After(time.Millisecond * 100)
                }
        }
 }
index 10e10b7..2a3ad96 100644 (file)
@@ -5259,12 +5259,9 @@ func TestRESTSubReqAndSubDelOkSameActionWithRestartsInMiddle(t *testing.T) {
        <-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
-       //<-time.After(time.Second * 1)
 
        mainCtrl.SimulateRestart(t)
        xapp.Logger.Debug("mainCtrl.SimulateRestart done 2")