Unverified Commit 2bb05b6d authored by Kevin Di Lallo's avatar Kevin Di Lallo Committed by GitHub
Browse files

Merge pull request #292 from pastorsx/sp_dev_system-alpha-test

MEC011 system test and sandbox frontend alpha test fixes
parents ff15039d 10e537e8
Loading
Loading
Loading
Loading
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2019  InterDigital Communications, Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package main

import (
	"os"
	"strings"
	"testing"

	log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger"
)

// Build:
//  $ go test -covermode=count -coverpkg=./... -c -o <name-of-your-app>
// Run:
//  $ ./<name-of-your-app> -test.coverprofile=cover.out __DEVEL--code-cov  <your-app-args>

// TestMain is a hack that allows us to figure out what the coverage is during
// integration tests. I would not recommend that you use a binary built using
// this hack outside of a test suite.
func TestMain(t *testing.T) {
	var (
		args []string
		run  bool
	)

	log.Info(os.Args)
	for _, arg := range os.Args {
		switch {
		case arg == "__DEVEL--code-cov":
			run = true
		case strings.HasPrefix(arg, "-test"):
		case strings.HasPrefix(arg, "__DEVEL"):
		default:
			args = append(args, arg)
		}
	}
	os.Args = args
	log.Info(os.Args)

	if run {
		main()
	}
}
+3 −0
Original line number Diff line number Diff line
@@ -182,6 +182,9 @@ func Stop() {
		mqLocal.UnregisterHandler(handlerId)
	}

	_ = sm.Stop()
	_ = as.Stop()

	// Remove APIs
	if apiMgr != nil {
		err := apiMgr.RemoveApis()
+10 −5
Original line number Diff line number Diff line
@@ -129,6 +129,11 @@ func Run() (err error) {

// Stop - Stop APP support
func Stop() (err error) {
	// Flush all app-enablement instance data
	if baseKey != "" {
		key := baseKey + "*"
		_ = rc.DBFlush(key)
	}
	return nil
}

@@ -494,7 +499,7 @@ func applicationsSubscriptionsGET(w http.ResponseWriter, r *http.Request) {

	//loop through appTerm map
	for _, appTermSubscription := range appTerminationNotificationSubscriptionMap {
		if appTermSubscription != nil {
		if appTermSubscription != nil && appTermSubscription.AppInstanceId == appInstanceId {
			var subscription MecAppSuptApiSubscriptionLinkListSubscription
			subscription.Href = appTermSubscription.Links.Self.Href
			//in v2.1.1 it should be SubscriptionType, but spec is expecting "rel" as per v1.1.1
@@ -584,7 +589,6 @@ func processAppTerminate(appInstanceId string, mep string) {

	// Filter subscriptions
	gracefulTermination := false

	for subId, sub := range appTerminationNotificationSubscriptionMap {
		// Filter subscriptions
		if sub == nil || sub.AppInstanceId != appInstanceId {
@@ -611,7 +615,11 @@ func processAppTerminate(appInstanceId string, mep string) {
		// Start graceful timeout prior to sending the app termination notification, or the answer could be received before the timer is started
		gracefulTimeoutTicker := time.NewTicker(time.Duration(DEFAULT_GRACEFUL_TIMEOUT) * time.Second)
		appTerminationGracefulTimeoutMap[appInstanceId] = gracefulTimeoutTicker
		callbackReference := sub.CallbackReference
		go func() {
			sendAppTermNotification(callbackReference, notif)
			log.Info("App Termination Notification" + "(" + subIdStr + ") for " + appInstanceId)

			for range gracefulTimeoutTicker.C {
				log.Info("Graceful timeout expiry for ", appInstanceId, "---", appTerminationGracefulTimeoutMap[appInstanceId])
				gracefulTimeoutTicker.Stop()
@@ -621,9 +629,6 @@ func processAppTerminate(appInstanceId string, mep string) {
				deleteAppInstance(appInstanceId)
			}
		}()
		sendAppTermNotification(sub.CallbackReference, notif)
		log.Info("App Termination Notification" + "(" + subIdStr + ") for " + appInstanceId)

	}

	// Delete App instance immediately if no graceful termination subscription
+1 −2
Original line number Diff line number Diff line
@@ -28,6 +28,5 @@ import (
)

func TransportsGET(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusOK)
	transportsGET(w, r)
}
+37 −3
Original line number Diff line number Diff line
@@ -147,6 +147,11 @@ func Run() (err error) {

// Stop - Stop Service Mgmt
func Stop() (err error) {
	// Flush all app-enablement instance data
	if baseKey != "" {
		key := baseKey + "*"
		_ = rc.DBFlush(key)
	}
	return nil
}

@@ -308,7 +313,6 @@ func appServicesByIdDELETE(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	appInstanceId := vars["appInstanceId"]
	serviceId := vars["serviceId"]

	mutex.Lock()
	defer mutex.Unlock()

@@ -633,7 +637,7 @@ func applicationsSubscriptionDELETE(w http.ResponseWriter, r *http.Request) {

	// Validate subscription exists
	key := baseKey + ":app:" + appInstanceId + ":" + msmgmtKey + ":sub:" + subIdParamStr
	if rc.EntryExists(key) {
	if !rc.EntryExists(key) {
		w.WriteHeader(http.StatusNotFound)
		return
	}
@@ -1138,7 +1142,7 @@ func checkSerAvailNotification(sInfo *ServiceInfo, mep string, changeType Servic
		idStr := strconv.Itoa(id)

		var notif ServiceAvailabilityNotification
		notif.NotificationType = SER_AVAILABILITY_NOTIFICATION_SUBSCRIPTION_TYPE
		notif.NotificationType = SER_AVAILABILITY_NOTIFICATION_TYPE
		links := new(Subscription)
		linkType := new(LinkType)
		linkType.Href = sub.Links.Self.Href
@@ -1263,3 +1267,33 @@ func getSubIdFromKey(key string) string {
	}
	return ""
}

func transportsGET(w http.ResponseWriter, r *http.Request) {
	log.Info("transportsGET")
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

	//transportInfo
	var transportInfo TransportInfo
	transportInfo.Id = "transport"
	transportInfo.Name = "REST"
	transportType := REST_HTTP
	transportInfo.Type_ = &transportType
	transportInfo.Protocol = "HTTP"
	transportInfo.Version = "2.0"
	var endpoint OneOfTransportInfoEndpoint
	endpointPath := hostUrl.String() + basePath
	endpoint.Uris = append(endpoint.Uris, endpointPath)
	transportInfo.Endpoint = &endpoint

	var transportInfoResp []TransportInfo
	transportInfoResp = append(transportInfoResp, transportInfo)
	// Prepare & send response
	jsonResponse, err := json.Marshal(transportInfoResp)
	if err != nil {
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.WriteHeader(http.StatusOK)
	fmt.Fprintf(w, string(jsonResponse))
}
Loading