diff --git a/scenario/connfunchandler.go b/scenario/connfunchandler.go index 8d26e876..309ef75b 100644 --- a/scenario/connfunchandler.go +++ b/scenario/connfunchandler.go @@ -47,7 +47,7 @@ func defaultGuidWsConnectTest(connectionSettings *connection.ConnectionSettings, return errors.Wrapf(err, "failed to get connect function") } - connectWs := OpenAppSettings{}.GetConnectWsAction("", connectFunc) + connectWs := GetConnectWsAction("", connectFunc) if err := connectWs.Execute(sessionState, connectionSettings); err != nil { return errors.Wrap(err, "failed to connect to engine over web socket") } diff --git a/scenario/openapp.go b/scenario/openapp.go index 9bdd1706..d1bf79a0 100644 --- a/scenario/openapp.go +++ b/scenario/openapp.go @@ -82,7 +82,7 @@ func (openApp OpenAppSettings) Execute(sessionState *session.State, actionState wsLabel = fmt.Sprintf("%s - WS", label) } - connectWs := openApp.GetConnectWsAction(wsLabel, connectFunc) + connectWs := GetConnectWsAction(wsLabel, connectFunc) //Connect websocket and logs as separate action actionState.NoResults = true // temporary set to not report while doing sub action. @@ -101,97 +101,12 @@ func (openApp OpenAppSettings) Execute(sessionState *session.State, actionState uplink := sessionState.Connection.Sense() - openApp.doOpen(sessionState, actionState, uplink, appEntry.ID) + DoOpenApp(sessionState, actionState, uplink, appEntry.ID) if actionState.Failed { return } - if uplink.CurrentApp == nil { - actionState.AddErrors(errors.New("No current app")) - return - } - if uplink.CurrentApp.Doc == nil { - actionState.AddErrors(errors.New("No current enigma doc")) - return - } - - doc := uplink.CurrentApp.Doc - - var authUser string - // Ask for user synchronously to make sure it's on all subsequent log entries - getAuthUser := func(ctx context.Context) error { - var err error - authUser, err = uplink.Global.GetAuthenticatedUser(ctx) - return err - } - if err := sessionState.SendRequest(actionState, getAuthUser); err != nil { - actionState.AddErrors(err) - return - } - sessionState.LogEntry.LogInfo("AuthenticatedUser", authUser) - - // send another AuthenticatedUser for api compliance - sessionState.QueueRequest(func(ctx context.Context) error { - _, err := uplink.Global.GetAuthenticatedUser(ctx) - return err - }, actionState, true, "") - - sessionState.QueueRequest(func(ctx context.Context) error { - layout, applyOutErr := doc.GetAppLayout(ctx) - if applyOutErr != nil { - return applyOutErr - } - uplink.CurrentApp.Layout = layout - return nil - }, actionState, true, fmt.Sprintf("Failed getting app layout for app GUID<%s>", appEntry.ID)) - - sessionState.QueueRequest(func(ctx context.Context) error { - _, err := uplink.CurrentApp.GetVariableList(sessionState, actionState) - return errors.WithStack(err) - }, actionState, true, "") - - sessionState.QueueRequest(func(ctx context.Context) error { - _, err := uplink.CurrentApp.GetStoryList(sessionState, actionState) - return errors.WithStack(err) - }, actionState, true, "") - - sessionState.QueueRequest(func(ctx context.Context) error { - _, err := uplink.CurrentApp.GetAppsPropsList(sessionState, actionState) - return errors.WithStack(err) - }, actionState, true, "") - - sessionState.QueueRequest(func(ctx context.Context) error { - _, err := uplink.Global.AllowCreateApp(ctx) - return errors.WithStack(err) - }, actionState, true, "") - - sessionState.QueueRequest(func(ctx context.Context) error { - _, err := uplink.CurrentApp.Doc.GetScriptEx(ctx) // ignore err, as when not ownning app an Access denied will be returned. - if err != nil { - sessionState.LogEntry.LogDebugf("GetScriptEx request returned error: %v", err) - } - return nil - }, actionState, true, "") - - for i := 0; i < 2; i++ { - sessionState.QueueRequestRaw(uplink.CurrentApp.Doc.GetAppPropertiesRaw, actionState, true, "failed to get AppProperties") - } - sessionState.QueueRequest(func(ctx context.Context) error { - _, err := uplink.Global.GetBaseBNFHash(ctx, "S") - return err - }, actionState, true, "") - - // Send GetConfiguration request 5 times - for i := 0; i < 5; i++ { - sessionState.QueueRequest(func(ctx context.Context) error { - return errors.WithStack(uplink.Global.RPC(ctx, "GetConfiguration", nil)) - }, actionState, false, "GetConfiguration request failed") - } - - sessionState.GetSheetList(actionState, uplink) - if actionState.Failed { - return - } + DoPostOpenAppRequests(sessionState, actionState, uplink, appEntry.ID) // setup re-connect function sessionState.SetReconnectFunc(connectFunc) @@ -216,7 +131,7 @@ func openDoc(ctx context.Context, uplink *enigmahandlers.SenseUplink, appGUID st return uplink.SetCurrentApp(appGUID, doc) } -func (openApp OpenAppSettings) GetConnectWsAction(wsLabel string, connectFunc func(bool) (string, error)) Action { +func GetConnectWsAction(wsLabel string, connectFunc func(bool) (string, error)) Action { connectWs := Action{ ActionCore{ Type: ActionConnectWs, @@ -274,7 +189,8 @@ func (openApp OpenAppSettings) AffectsAppObjectsAction(structure appstructure.Ap return []*appstructure.AppStructurePopulatedObjects{&newObjs}, nil, true } -func (openApp OpenAppSettings) doOpen(sessionState *session.State, actionState *action.State, uplink *enigmahandlers.SenseUplink, appGUID string) { +// DoOpenApp is intended to be used from inside a open app action after websocket is connected +func DoOpenApp(sessionState *session.State, actionState *action.State, uplink *enigmahandlers.SenseUplink, appGUID string) { if err := sessionState.SendRequest(actionState, func(ctx context.Context) error { return openDoc(ctx, uplink, appGUID) }); err != nil { @@ -291,3 +207,92 @@ func (openApp OpenAppSettings) doOpen(sessionState *session.State, actionState * return } } + +func DoPostOpenAppRequests(sessionState *session.State, actionState *action.State, uplink *enigmahandlers.SenseUplink, appID string) { + if uplink.CurrentApp == nil { + actionState.AddErrors(errors.New("No current app")) + return + } + if uplink.CurrentApp.Doc == nil { + actionState.AddErrors(errors.New("No current enigma doc")) + return + } + + doc := uplink.CurrentApp.Doc + + var authUser string + // Ask for user synchronously to make sure it's on all subsequent log entries + getAuthUser := func(ctx context.Context) error { + var err error + authUser, err = uplink.Global.GetAuthenticatedUser(ctx) + return err + } + if err := sessionState.SendRequest(actionState, getAuthUser); err != nil { + actionState.AddErrors(err) + return + } + sessionState.LogEntry.LogInfo("AuthenticatedUser", authUser) + + // send another AuthenticatedUser for api compliance + sessionState.QueueRequest(func(ctx context.Context) error { + _, err := uplink.Global.GetAuthenticatedUser(ctx) + return err + }, actionState, true, "") + + sessionState.QueueRequest(func(ctx context.Context) error { + layout, applyOutErr := doc.GetAppLayout(ctx) + if applyOutErr != nil { + return applyOutErr + } + uplink.CurrentApp.Layout = layout + return nil + }, actionState, true, fmt.Sprintf("Failed getting app layout for app GUID<%s>", appID)) + + sessionState.QueueRequest(func(ctx context.Context) error { + _, err := uplink.CurrentApp.GetVariableList(sessionState, actionState) + return errors.WithStack(err) + }, actionState, true, "") + + sessionState.QueueRequest(func(ctx context.Context) error { + _, err := uplink.CurrentApp.GetStoryList(sessionState, actionState) + return errors.WithStack(err) + }, actionState, true, "") + + sessionState.QueueRequest(func(ctx context.Context) error { + _, err := uplink.CurrentApp.GetAppsPropsList(sessionState, actionState) + return errors.WithStack(err) + }, actionState, true, "") + + sessionState.QueueRequest(func(ctx context.Context) error { + _, err := uplink.Global.AllowCreateApp(ctx) + return errors.WithStack(err) + }, actionState, true, "") + + sessionState.QueueRequest(func(ctx context.Context) error { + _, err := uplink.CurrentApp.Doc.GetScriptEx(ctx) // ignore err, as when not ownning app an Access denied will be returned. + if err != nil { + sessionState.LogEntry.LogDebugf("GetScriptEx request returned error: %v", err) + } + return nil + }, actionState, true, "") + + for i := 0; i < 2; i++ { + sessionState.QueueRequestRaw(uplink.CurrentApp.Doc.GetAppPropertiesRaw, actionState, true, "failed to get AppProperties") + } + sessionState.QueueRequest(func(ctx context.Context) error { + _, err := uplink.Global.GetBaseBNFHash(ctx, "S") + return err + }, actionState, true, "") + + // Send GetConfiguration request 5 times + for i := 0; i < 5; i++ { + sessionState.QueueRequest(func(ctx context.Context) error { + return errors.WithStack(uplink.Global.RPC(ctx, "GetConfiguration", nil)) + }, actionState, false, "GetConfiguration request failed") + } + + sessionState.GetSheetList(actionState, uplink) + if actionState.Failed { + return + } +}