X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Fxapp_test.go;h=9696e6eec4b75e3b928665bbaefe872edfaa7e85;hb=1307b2d8d34f48bf44267efc2d1e607823c8d06d;hp=ca858eb32ed3658137699b4d59851c93393874cc;hpb=5120ec103eead26427b977f4b2456c2ce57b36ac;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/xapp_test.go b/pkg/xapp/xapp_test.go index ca858eb..9696e6e 100755 --- a/pkg/xapp/xapp_test.go +++ b/pkg/xapp/xapp_test.go @@ -21,6 +21,7 @@ package xapp import ( "github.com/gorilla/mux" + "github.com/spf13/viper" "net/http" "net/http/httptest" "os" @@ -29,12 +30,12 @@ import ( "time" ) -var _ = func() bool { - testing.Init() - return true -}() +//var _ = func() bool { +// testing.Init() +// return true +//}() -type Consumer struct {} +type Consumer struct{} func (m Consumer) Consume(params *RMRParams) (err error) { Sdl.Store("myKey", params.Payload) @@ -43,7 +44,7 @@ func (m Consumer) Consume(params *RMRParams) (err error) { // Test cases func TestMain(m *testing.M) { - go Run(Consumer{}) + go RunWithParams(Consumer{}, viper.GetBool("db.waitForSdl")) time.Sleep(time.Duration(5) * time.Second) code := m.Run() os.Exit(code) @@ -101,6 +102,7 @@ func TestInjectQueryFailures(t *testing.T) { } func TestMessagesReceivedSuccessfully(t *testing.T) { + time.Sleep(time.Duration(5) * time.Second) for i := 0; i < 100; i++ { params := &RMRParams{} params.Mtype = 10004 @@ -114,13 +116,14 @@ func TestMessagesReceivedSuccessfully(t *testing.T) { // Allow time to process the messages time.Sleep(time.Duration(2) * time.Second) + waitForSdl := viper.GetBool("db.waitForSdl") stats := getMetrics(t) if !strings.Contains(stats, "ricxapp_RMR_Transmitted 100") { - t.Errorf("Error: ricxapp_RMR_Transmitted value incorrect") + t.Errorf("Error: ricxapp_RMR_Transmitted value incorrect: %v", stats) } if !strings.Contains(stats, "ricxapp_RMR_Received 100") { - t.Errorf("Error: ricxapp_RMR_Received value incorrect") + t.Errorf("Error: ricxapp_RMR_Received value incorrect: %v", stats) } if !strings.Contains(stats, "ricxapp_RMR_TransmitError 0") { @@ -131,16 +134,107 @@ func TestMessagesReceivedSuccessfully(t *testing.T) { t.Errorf("Error: ricxapp_RMR_ReceiveError value incorrect") } - if !strings.Contains(stats, "ricxapp_SDL_Stored 100") { + if waitForSdl && !strings.Contains(stats, "ricxapp_SDL_Stored 100") { t.Errorf("Error: ricxapp_SDL_Stored value incorrect") } - if !strings.Contains(stats, "ricxapp_SDL_StoreError 0") { + if waitForSdl && !strings.Contains(stats, "ricxapp_SDL_StoreError 0") { t.Errorf("Error: ricxapp_SDL_StoreError value incorrect") } } +func TestMessagesReceivedSuccessfullyUsingWh(t *testing.T) { + time.Sleep(time.Duration(5) * time.Second) + whid := Rmr.Openwh("localhost:4560") + time.Sleep(time.Duration(1) * time.Second) + for i := 0; i < 100; i++ { + params := &RMRParams{} + params.Mtype = 10004 + params.SubId = -1 + params.Payload = []byte{1, 2, 3, 4, 5, 6} + params.Meid = &RMRMeid{PlmnID: "1234", EnbID: "7788", RanName: "RanName-1234"} + params.Xid = "TestXID" + params.Whid = int(whid) + Rmr.SendMsg(params) + } + + // Allow time to process the messages + time.Sleep(time.Duration(2) * time.Second) + + waitForSdl := viper.GetBool("db.waitForSdl") + stats := getMetrics(t) + if !strings.Contains(stats, "ricxapp_RMR_Transmitted 200") { + t.Errorf("Error: ricxapp_RMR_Transmitted value incorrect: %v", stats) + } + + if !strings.Contains(stats, "ricxapp_RMR_Received 200") { + t.Errorf("Error: ricxapp_RMR_Received value incorrect: %v", stats) + } + + if !strings.Contains(stats, "ricxapp_RMR_TransmitError 0") { + t.Errorf("Error: ricxapp_RMR_TransmitError value incorrect") + } + + if !strings.Contains(stats, "ricxapp_RMR_ReceiveError 0") { + t.Errorf("Error: ricxapp_RMR_ReceiveError value incorrect") + } + + if waitForSdl && !strings.Contains(stats, "ricxapp_SDL_Stored 200") { + t.Errorf("Error: ricxapp_SDL_Stored value incorrect") + } + + if waitForSdl && !strings.Contains(stats, "ricxapp_SDL_StoreError 0") { + t.Errorf("Error: ricxapp_SDL_StoreError value incorrect") + } + Rmr.Closewh(int(whid)) +} + +func TestMessagesReceivedSuccessfullyUsingWhCall(t *testing.T) { + time.Sleep(time.Duration(5) * time.Second) + whid := Rmr.Openwh("localhost:4560") + params := &RMRParams{} + params.Payload = []byte("newrt|start\nnewrt|end\n") + params.Whid = int(whid) + params.Callid = 4 + params.Timeout = 1000 + Rmr.SendCallMsg(params) + + // Allow time to process the messages + time.Sleep(time.Duration(2) * time.Second) + + waitForSdl := viper.GetBool("db.waitForSdl") + stats := getMetrics(t) + if !strings.Contains(stats, "ricxapp_RMR_Transmitted 200") { + t.Errorf("Error: ricxapp_RMR_Transmitted value incorrect: %v", stats) + } + + if !strings.Contains(stats, "ricxapp_RMR_Received 201") { + t.Errorf("Error: ricxapp_RMR_Received value incorrect: %v", stats) + } + + if !strings.Contains(stats, "ricxapp_RMR_TransmitError 1") { + t.Errorf("Error: ricxapp_RMR_TransmitError value incorrect") + } + + if !strings.Contains(stats, "ricxapp_RMR_ReceiveError 0") { + t.Errorf("Error: ricxapp_RMR_ReceiveError value incorrect") + } + + if waitForSdl && !strings.Contains(stats, "ricxapp_SDL_Stored 201") { + t.Errorf("Error: ricxapp_SDL_Stored value incorrect") + } + + if waitForSdl && !strings.Contains(stats, "ricxapp_SDL_StoreError 0") { + t.Errorf("Error: ricxapp_SDL_StoreError value incorrect") + } + Rmr.Closewh(int(whid)) +} + func TestSubscribeChannels(t *testing.T) { + if !viper.GetBool("db.waitForSdl") { + return + } + var NotificationCb = func(ch string, events ...string) { if ch != "channel1" { t.Errorf("Error: Callback function called with incorrect params") @@ -170,14 +264,36 @@ func TestGetRicMessageSuccess(t *testing.T) { } func TestGetRicMessageFails(t *testing.T) { - id, ok := Rmr.GetRicMessageId("INVALID") + ok := Rmr.IsRetryError(&RMRParams{status: 0}) + if ok { + t.Errorf("Error: IsRetryError returned wrong value") + } + + ok = Rmr.IsRetryError(&RMRParams{status: 10}) + if !ok { + t.Errorf("Error: IsRetryError returned wrong value") + } + + ok = Rmr.IsNoEndPointError(&RMRParams{status: 5}) if ok { - t.Errorf("Error: GetRicMessageId returned invalid value id=%d", id) + t.Errorf("Error: IsNoEndPointError returned wrong value") } - name := Rmr.GetRicMessageName(123456) - if name != "" { - t.Errorf("Error: GetRicMessageName returned invalid value: name=%s", name) + ok = Rmr.IsNoEndPointError(&RMRParams{status: 2}) + if !ok { + t.Errorf("Error: IsNoEndPointError returned wrong value") + } +} + +func TestIsErrorFunctions(t *testing.T) { + id, ok := Rmr.GetRicMessageId("RIC_SUB_REQ") + if !ok || id != 12010 { + t.Errorf("Error: GetRicMessageId failed: id=%d", id) + } + + name := Rmr.GetRicMessageName(12010) + if name != "RIC_SUB_REQ" { + t.Errorf("Error: GetRicMessageName failed: name=%s", name) } }