Improved tweak to get around with the fact that alarm package changes RMR_SEED_RT 35/3635/1
authorJuha Hyttinen <juha.hyttinen@nokia.com>
Fri, 8 May 2020 07:11:10 +0000 (10:11 +0300)
committerJuha Hyttinen <juha.hyttinen@nokia.com>
Fri, 8 May 2020 07:11:58 +0000 (10:11 +0300)
Change-Id: I884b67c43858f7be1dc1a74c5246e5a32a06f1c7
Signed-off-by: Juha Hyttinen <juha.hyttinen@nokia.com>
pkg/control/ut_test.go

index 773ad2b..c0c3b72 100644 (file)
@@ -26,6 +26,7 @@ import (
        "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks"
        "os"
        "testing"
+       "time"
 )
 
 //-----------------------------------------------------------------------------
@@ -154,11 +155,29 @@ func ut_test_init() {
        tent.Logger.Info("### submgr ctrl run ###")
        mainCtrl = createSubmgrControl(mainsrc, teststub.RmrRtgSvc{})
 
+       //
+       // Tweak to get around with fact that alarm package alternates RMR_SEED_RT environment variable
+       //
        //xapp-frame inits alarms when readycb is coming from xapps rmr
        //alarm will make new rmr instance and overrides RMR_SEED_RT and RMR_RTG_SVC
        //env variables. Re-create rt info.
-       rt.Disable()
-       rt.Enable()
+       for i := 0; i < int(10)*2; i++ {
+               if os.Getenv("RMR_SEED_RT") == rt.FileName() {
+                       tent.Logger.Info("Waiting that alarm alternates RMR_SEED_RT=%s", os.Getenv("RMR_SEED_RT"))
+                       time.Sleep(500 * time.Millisecond)
+               } else {
+                       tent.Logger.Info("Alarm has alternated RMR_SEED_RT=%s, so waiting 0.5 secs before restoring it", os.Getenv("RMR_SEED_RT"))
+                       time.Sleep(500 * time.Millisecond)
+                       rt.Disable()
+                       rt.Enable()
+                       break
+               }
+       }
+
+       if os.Getenv("RMR_SEED_RT") != rt.FileName() {
+               tent.Logger.Error("Unittest timing issue with alarm RMR_SEED_RT=%s", os.Getenv("RMR_SEED_RT"))
+               os.Exit(1)
+       }
 
        //---------------------------------
        //
@@ -196,6 +215,12 @@ func ut_test_init() {
        if teststub.RmrStubControlWaitAlive(10, 55555, mainCtrl.c) == false {
                os.Exit(1)
        }
+
+       if os.Getenv("RMR_SEED_RT") != rt.FileName() {
+               tent.Logger.Error("Unittest timing issue with alarm RMR_SEED_RT=%s", os.Getenv("RMR_SEED_RT"))
+               os.Exit(1)
+       }
+
 }
 
 //-----------------------------------------------------------------------------