Commit 3b5a1c8b authored by Simon Pastor's avatar Simon Pastor
Browse files

fix ut testing for wai and rni

parent 475651db
Loading
Loading
Loading
Loading
+23 −18
Original line number Diff line number Diff line
@@ -342,7 +342,7 @@ func checkForExpiredSubscriptions() {
					notif.ExpiryDeadline = &expiryTimeStamp

					sendExpiryNotification(link.Self, context.TODO(), subsIdStr, notif)
					_ = delSubscription(baseKey+cellChangeSubscriptionType, subsIdStr)
					_ = delSubscription(baseKey+cellChangeSubscriptionType, subsIdStr, true)
				}
			}
		}
@@ -1076,28 +1076,33 @@ func registerRr(rabRelSubscription *RabRelSubscription, subsIdStr string) {
	log.Info("New registration: ", subsId, " type: ", rabRelSubscriptionType)
}

func deregisterCc(subsIdStr string) {
func deregisterCc(subsIdStr string, mutexTaken bool) {
	subsId, _ := strconv.Atoi(subsIdStr)
	if !mutexTaken {
		mutex.Lock()
		defer mutex.Unlock()

	}
	ccSubscriptionMap[subsId] = nil
	log.Info("Deregistration: ", subsId, " type: ", cellChangeSubscriptionType)
}

func deregisterRe(subsIdStr string) {
func deregisterRe(subsIdStr string, mutexTaken bool) {
	subsId, _ := strconv.Atoi(subsIdStr)
	if !mutexTaken {
		mutex.Lock()
		defer mutex.Unlock()
	}

	reSubscriptionMap[subsId] = nil
	log.Info("Deregistration: ", subsId, " type: ", rabEstSubscriptionType)
}

func deregisterRr(subsIdStr string) {
func deregisterRr(subsIdStr string, mutexTaken bool) {
	subsId, _ := strconv.Atoi(subsIdStr)
	if !mutexTaken {
		mutex.Lock()
		defer mutex.Unlock()
	}

	rrSubscriptionMap[subsId] = nil
	log.Info("Deregistration: ", subsId, " type: ", rabRelSubscriptionType)
@@ -1197,12 +1202,12 @@ func cellChangeSubscriptionsPUT(w http.ResponseWriter, r *http.Request) {
	}
}

func delSubscription(keyPrefix string, subsId string) error {
func delSubscription(keyPrefix string, subsId string, mutexTaken bool) error {

	err := rc.JSONDelEntry(keyPrefix+":"+subsId, ".")
	deregisterCc(subsId)
	deregisterRe(subsId)
	deregisterRr(subsId)
	deregisterCc(subsId, mutexTaken)
	deregisterRe(subsId, mutexTaken)
	deregisterRr(subsId, mutexTaken)
	return err
}

@@ -1210,7 +1215,7 @@ func cellChangeSubscriptionsDELETE(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	vars := mux.Vars(r)

	err := delSubscription(baseKey+cellChangeSubscriptionType, vars["subscriptionId"])
	err := delSubscription(baseKey+cellChangeSubscriptionType, vars["subscriptionId"], false)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
@@ -1346,7 +1351,7 @@ func rabEstSubscriptionsDELETE(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	vars := mux.Vars(r)

	err := delSubscription(baseKey+rabEstSubscriptionType, vars["subscriptionId"])
	err := delSubscription(baseKey+rabEstSubscriptionType, vars["subscriptionId"], false)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
@@ -1482,7 +1487,7 @@ func rabRelSubscriptionsDELETE(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	vars := mux.Vars(r)

	err := delSubscription(baseKey+rabRelSubscriptionType, vars["subscriptionId"])
	err := delSubscription(baseKey+rabRelSubscriptionType, vars["subscriptionId"], false)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
+2 −2
Original line number Diff line number Diff line
@@ -2182,8 +2182,8 @@ func TestSbi(t *testing.T) {

	var expectedAppEcgiStr [2]string
	var expectedAppEcgi [2]Ecgi
	expectedAppEcgi[INITIAL] = Ecgi{&Plmn{"123", "456"}, "1234567"}
	expectedAppEcgi[UPDATED] = Ecgi{&Plmn{"123", "456"}, "1234567"}
	expectedAppEcgi[INITIAL] = Ecgi{&Plmn{"123", "456"}, ""}
	expectedAppEcgi[UPDATED] = Ecgi{&Plmn{"123", "456"}, ""}

	j, err := json.Marshal(expectedUeData[INITIAL])
	if err != nil {
+1 −1
Original line number Diff line number Diff line
@@ -217,7 +217,7 @@ func processActiveScenarioUpdate() {
		var ueMacIdList []string

		for _, pl := range poa.PhysicalLocations {
			ueMacIdList = append(ueMacIdList, pl.Name)
			ueMacIdList = append(ueMacIdList, pl.MacId)
		}
		sbi.updateAccessPointInfoCB(name, poa.PoaWifiConfig.MacId, longitude, latitude, ueMacIdList)
	}
+29 −5
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import (
	"reflect"
	"strconv"
	"strings"
	"sync"
	"time"

	sbi "github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-wais/sbi"
@@ -66,6 +67,7 @@ var hostUrl *url.URL
var sandboxName string
var basePath string
var baseKey string
var mutex sync.Mutex

var expiryTicker *time.Ticker

@@ -268,6 +270,8 @@ func createClient(notifyPath string) (*clientNotif.APIClient, error) {
func checkForExpiredSubscriptions() {

	nowTime := int(time.Now().Unix())
	mutex.Lock()
	defer mutex.Unlock()
	for expiryTime, subsIndexList := range subscriptionExpiryMap {
		if expiryTime <= nowTime {
			subscriptionExpiryMap[expiryTime] = nil
@@ -293,7 +297,7 @@ func checkForExpiredSubscriptions() {
					notif.ExpiryDeadline = &expiryTimeStamp

					sendExpiryNotification(link.Self, context.TODO(), subsIdStr, notif)
					_ = delSubscription(baseKey+"subscription", subsIdStr)
					_ = delSubscription(baseKey+"subscription", subsIdStr, true)
				}
			}
		}
@@ -315,6 +319,9 @@ func repopulateSubscriptionMap(key string, jsonInfo string, userData interface{}
	subsIdStr := selfUrl[len(selfUrl)-1]
	subsId, _ := strconv.Atoi(subsIdStr)

	mutex.Lock()
	defer mutex.Unlock()

	//only assocSta subscription for now
	assocStaSubscriptionMap[subsId] = &subscription
	if subscription.ExpiryDeadline != nil {
@@ -333,6 +340,8 @@ func repopulateSubscriptionMap(key string, jsonInfo string, userData interface{}

func checkAssocStaNotificationRegisteredSubscriptions(staMacIds []string, apMacId string) {

	mutex.Lock()
	defer mutex.Unlock()
	//check all that applies
	for subsId, sub := range assocStaSubscriptionMap {
		match := false
@@ -456,6 +465,8 @@ func subscriptionsGET(w http.ResponseWriter, r *http.Request) {

func isSubscriptionIdRegistered(subsIdStr string) bool {
	subsId, _ := strconv.Atoi(subsIdStr)
	mutex.Lock()
	defer mutex.Unlock()
	if assocStaSubscriptionMap[subsId] != nil {
		return true
	} else {
@@ -465,6 +476,9 @@ func isSubscriptionIdRegistered(subsIdStr string) bool {

func register(subscription *Subscription, subsIdStr string) {
	subsId, _ := strconv.Atoi(subsIdStr)
	mutex.Lock()
	defer mutex.Unlock()

	assocStaSubscriptionMap[subsId] = subscription
	if subscription.ExpiryDeadline != nil {
		//get current list of subscription meant to expire at this time
@@ -476,8 +490,12 @@ func register(subscription *Subscription, subsIdStr string) {
	log.Info("New registration: ", subsId, " type: ", subscription.SubscriptionType)
}

func deregister(subsIdStr string) {
func deregister(subsIdStr string, mutexTaken bool) {
	subsId, _ := strconv.Atoi(subsIdStr)
	if !mutexTaken {
		mutex.Lock()
		defer mutex.Unlock()
	}
	assocStaSubscriptionMap[subsId] = nil
	log.Info("Deregistration: ", subsId, " type: ", assocStaSubscriptionType)
}
@@ -571,10 +589,10 @@ func subscriptionsPUT(w http.ResponseWriter, r *http.Request) {
	}
}

func delSubscription(keyPrefix string, subsId string) error {
func delSubscription(keyPrefix string, subsId string, mutexTaken bool) error {

	err := rc.JSONDelEntry(keyPrefix+":"+subsId, ".")
	deregister(subsId)
	deregister(subsId, mutexTaken)
	return err
}

@@ -582,7 +600,7 @@ func subscriptionsDELETE(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	vars := mux.Vars(r)

	err := delSubscription(baseKey+"subscription:", vars["subscriptionId"])
	err := delSubscription(baseKey+"subscription:", vars["subscriptionId"], false)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
@@ -724,6 +742,9 @@ func createSubscriptionLinkList(subType string) *SubscriptionLinkList {

	//loop through all different types of subscription

	mutex.Lock()
	defer mutex.Unlock()

	if subType == "" || subType == assocStaSubscriptionType {
		//loop through assocSta map
		for _, assocStaSubscription := range assocStaSubscriptionMap {
@@ -764,6 +785,9 @@ func cleanUp() {
	rc.DBFlush(baseKey)
	nextSubscriptionIdAvailable = 1

	mutex.Lock()
	defer mutex.Unlock()

	assocStaSubscriptionMap = map[int]*Subscription{}

	subscriptionExpiryMap = map[int][]int{}
+9 −3
Original line number Diff line number Diff line
@@ -332,6 +332,7 @@ const testScenario string = `
                              "id": "c52208b3-93bb-4255-9b34-52432acc4398",
                              "name": "10.100.0.1",
                              "type": "UE",
                              "macId": "101000100000",
                              "geoData": {
                                 "location": {
                                    "type": "Point",
@@ -2575,6 +2576,7 @@ const testScenario string = `
                              "id": "0ca4bfcc-7346-4f57-9c85-bb92642ec37e",
                              "name": "10.1.0.2",
                              "type": "UE",
                              "macId": "101020000000",
                              "geoData": {
                                 "location": {
                                    "type": "Point",
@@ -2912,6 +2914,7 @@ const testScenario string = `
                              "id": "ec32caa6-ddc6-4f5e-a815-654782b31abb",
                              "name": "10.100.0.2",
                              "type": "UE",
                              "macId": "101000200000",
                              "geoData": {
                                 "location": {
                                    "type": "Point",
@@ -3843,6 +3846,7 @@ const testScenario string = `
                              "id": "1d2683f4-086e-47d6-abbb-07fa481a25fb",
                              "name": "10.10.0.1",
                              "type": "UE",
                              "macId": "101001000000",
                              "geoData": {
                                 "location": {
                                    "type": "Point",
@@ -4724,6 +4728,7 @@ const testScenario string = `
                              "id": "c3bc8d8d-170b-45bb-93a9-8ce658571321",
                              "name": "10.1.0.1",
                              "type": "UE",
                              "macId": "101010000000",
                              "geoData": {
                                 "location": {
                                    "type": "Point",
@@ -5181,6 +5186,7 @@ const testScenario string = `
                              "id": "824cf1bf-f91d-44c2-906d-e939fa3339cd",
                              "name": "10.10.0.2",
                              "type": "UE",
                              "macId": "101002000000",
                              "geoData": {
                                 "location": {
                                    "type": "Point",
@@ -6334,7 +6340,7 @@ func TestSubscriptionAssocStaNotification(t *testing.T) {
	expectedApId := ApIdentity{"0050C272800A", "", ""}
	expectedSubscriptionType := assocStaSubscriptionType
	expectedApIdMacIdStr := "{\"macId\":\"0050C272800A\"}"
	expectedStaIdMacIdStr := "[{\"macId\":\"10.10.0.2\"}]"
	expectedStaIdMacIdStr := "[{\"macId\":\"101002000000\"}]"

	/******************************
	 * request vars section
@@ -6434,7 +6440,7 @@ func TestSbi(t *testing.T) {

	//different tests
	ueName := "10.10.0.2"
	ueMacId := "10.10.0.2" //currently name
	ueMacId := "101002000000" //currently name
	apName1 := "4g-macro-cell-10"
	apMacId1 := ""
	apName2 := "w10"
@@ -6595,7 +6601,7 @@ func TestStaInfoGet(t *testing.T) {
	 * expected response section
	 ******************************/
	nbExpectedStaInfo := 1
	expectedStaIdMacId := "10.10.0.2"
	expectedStaIdMacId := "101002000000"

	/******************************
	 * request vars section