Fix for xApp transction release place
[ric-plt/submgr.git] / pkg / control / control.go
index 9410925..799a307 100755 (executable)
@@ -87,6 +87,7 @@ type Control struct {
        ResetTestFlag bool
        Counters      map[string]xapp.Counter
        LoggerLevel   int
+       UTTesting     bool
 }
 
 type RMRMeid struct {
@@ -483,6 +484,7 @@ func (c *Control) GetE2SubscriptionDirectives(p *models.SubscriptionParams) (*E2
 func (c *Control) processSubscriptionRequests(restSubscription *RESTSubscription, subReqList *e2ap.SubscriptionRequestList,
        clientEndpoint *models.SubscriptionParamsClientEndpoint, meid *string, restSubId *string, xAppRmrEndpoint string, md5sum string, e2SubscriptionDirectives *E2SubscriptionDirectives) {
 
+       c.SubscriptionProcessingStartDelay()
        xapp.Logger.Debug("Subscription Request count=%v ", len(subReqList.E2APSubscriptionRequests))
 
        var xAppEventInstanceID int64
@@ -509,6 +511,7 @@ func (c *Control) processSubscriptionRequests(restSubscription *RESTSubscription
                subRespMsg, errorInfo, err := c.handleSubscriptionRequest(trans, &subReqMsg, meid, *restSubId, e2SubscriptionDirectives)
 
                xapp.Logger.Debug("Handled SubscriptionRequest index=%v, %s", index, idstring(nil, trans))
+               trans.Release()
 
                if err != nil {
                        c.sendUnsuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, err, clientEndpoint, trans, errorInfo)
@@ -519,7 +522,19 @@ func (c *Control) processSubscriptionRequests(restSubscription *RESTSubscription
                                index, *restSubId, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans))
                        c.sendSuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, e2EventInstanceID, clientEndpoint, trans)
                }
-               trans.Release()
+       }
+}
+
+//-------------------------------------------------------------------
+//
+//------------------------------------------------------------------
+func (c *Control) SubscriptionProcessingStartDelay() {
+       if c.UTTesting == true {
+               // This is temporary fix for the UT problem that notification arrives before subscription response
+               // Correct fix would be to allow notification come before response and process it correctly
+               xapp.Logger.Debug("Setting 50 ms delay before starting processing Subscriptions")
+               <-time.After(time.Millisecond * 50)
+               xapp.Logger.Debug("Continuing after delay")
        }
 }