X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fut_ctrl_submgr_test.go;h=9ffda38fa6a50aa1423da324f0382d7b37d7b51d;hb=da34eecb23220659f8d519973c03d29444797998;hp=8f4e5ae39418b3635cc32e63752c407ebf61160b;hpb=a5c58bc513653ad86eaa1ac557c0c2960a1a0a6c;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/ut_ctrl_submgr_test.go b/pkg/control/ut_ctrl_submgr_test.go index 8f4e5ae..9ffda38 100644 --- a/pkg/control/ut_ctrl_submgr_test.go +++ b/pkg/control/ut_ctrl_submgr_test.go @@ -170,6 +170,35 @@ func (mc *testingSubmgrControl) wait_subs_clean(t *testing.T, e2SubsId uint32, s return false } +func (mc *testingSubmgrControl) wait_multi_subs_clean(t *testing.T, e2SubsIds []uint32, secs int) bool { + var subs *Subscription + var purgedSubscriptions int + i := 1 + k := 0 + for ; i <= secs*2; i++ { + purgedSubscriptions = 0 + for k = 0; k <= len(e2SubsIds); i++ { + subs = mc.c.registry.GetSubscription(e2SubsIds[k]) + if subs == nil { + mc.TestLog(t, "(submgr) subscriber purged for esSubsId %v", e2SubsIds[k]) + purgedSubscriptions += 1 + if purgedSubscriptions == len(e2SubsIds) { + return true + } else { + continue + } + } else { + mc.TestLog(t, "(submgr) subscriber %s no clean within %d secs: subs(N/A) - purged subscriptions %v", subs.String(), secs, purgedSubscriptions) + time.Sleep(500 * time.Millisecond) + } + } + } + + mc.TestError(t, "(submgr) no clean within %d secs: subs(N/A) - %v/%v subscriptions found still", secs, purgedSubscriptions, len(e2SubsIds)) + + return false +} + func (mc *testingSubmgrControl) wait_subs_trans_clean(t *testing.T, e2SubsId uint32, secs int) bool { var trans TransactionIf i := 1 @@ -332,3 +361,68 @@ func (mc *testingSubmgrControl) GetCurrentCounterValues(t *testing.T, chekedCoun } return retCounterMap } + +func (mc *testingSubmgrControl) sendGetRequest(t *testing.T, addr string, path string) { + + mc.TestLog(t, "GET http://"+addr+"%v", path) + req, err := http.NewRequest("GET", "http://"+addr+path, nil) + if err != nil { + mc.TestError(t, "Error reading request. %v", err) + return + } + req.Header.Set("Cache-Control", "no-cache") + client := &http.Client{Timeout: time.Second * 2} + resp, err := client.Do(req) + if err != nil { + mc.TestError(t, "Error reading response. %v", err) + return + } + defer resp.Body.Close() + + mc.TestLog(t, "Response status: %v", resp.Status) + mc.TestLog(t, "Response Headers: %v", resp.Header) + if !strings.Contains(resp.Status, "200 OK") { + mc.TestError(t, "Wrong response status") + return + } + + respBody, err := ioutil.ReadAll(resp.Body) + if err != nil { + mc.TestError(t, "Error reading body. %v", err) + return + } + mc.TestLog(t, "%s", respBody) + return +} + +func (mc *testingSubmgrControl) sendPostRequest(t *testing.T, addr string, path string) { + + mc.TestLog(t, "POST http://"+addr+"%v", path) + req, err := http.NewRequest("POST", "http://"+addr+path, nil) + if err != nil { + mc.TestError(t, "Error reading request. %v", err) + return + } + client := &http.Client{Timeout: time.Second * 2} + resp, err := client.Do(req) + if err != nil { + mc.TestError(t, "Error reading response. %v", err) + return + } + defer resp.Body.Close() + + mc.TestLog(t, "Response status: %v", resp.Status) + mc.TestLog(t, "Response Headers: %v", resp.Header) + if !strings.Contains(resp.Status, "200 OK") { + mc.TestError(t, "Wrong response status") + return + } + + respBody, err := ioutil.ReadAll(resp.Body) + if err != nil { + mc.TestError(t, "Error reading body. %v", err) + return + } + mc.TestLog(t, "%s", respBody) + return +}