Skip to content

Commit

Permalink
Merge pull request #361 from itmo-eve/more-info-in-app-test
Browse files Browse the repository at this point in the history
Improving #351
  • Loading branch information
mydatascience authored Nov 12, 2020
2 parents 78d4c28 + 900ee1b commit 2d15d7a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/edenPod.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func getPortMapping(appConfig *config.AppInstanceConfig, qemuPorts map[string]st
//podPsCmd is a command to list deployed apps
var podPsCmd = &cobra.Command{
Use: "ps",
Short: "List podsList",
Short: "List pods",
PreRunE: func(cmd *cobra.Command, args []string) error {
assignCobraToViper(cmd)
_, err := utils.LoadConfigFile(configFile)
Expand Down
47 changes: 38 additions & 9 deletions tests/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
var (
timewait = flag.Duration("timewait", time.Minute, "Timewait for items waiting")
tc *projects.TestContext
found map[string]string
states map[string][]string
)

// TestMain is used to provide setup and teardown for the rest of the
Expand All @@ -41,6 +41,24 @@ func TestMain(m *testing.M) {
os.Exit(res)
}

// checkNewLastState returns true if provided state not equals with last
func checkNewLastState(appName, state string) bool {
appStates, ok := states[appName]
if ok {
lastState := appStates[len(appStates)-1]
if lastState != state {
return true
}
}
return false
}

func checkAndAppendState(appName, state string) {
if checkNewLastState(appName, state) {
states[appName] = append(states[appName], state)
}
}

//checkApp wait for info of ZInfoApp type with state
func checkApp(state string, appNames []string) projects.ProcInfoFunc {
return func(msg *info.ZInfoMsg) error {
Expand All @@ -50,7 +68,7 @@ func checkApp(state string, appNames []string) projects.ProcInfoFunc {
foundAny := false
for _, app := range msg.GetDinfo().AppInstances {
if _, inSlice := utils.FindEleInSlice(appNames, app.Name); inSlice {
found[app.Name] = "EXISTS"
checkAndAppendState(app.Name, "EXISTS")
foundAny = true
}
}
Expand All @@ -68,12 +86,17 @@ func checkApp(state string, appNames []string) projects.ProcInfoFunc {
if msg.Ztype == info.ZInfoTypes_ZiApp {
app := msg.GetAinfo()
if _, inSlice := utils.FindEleInSlice(appNames, app.AppName); inSlice {
found[app.AppName] = app.State.String()
if len(app.AppErr) > 0 {
//if AppErr, show them
checkAndAppendState(app.AppName, fmt.Sprintf("%s: %s", app.State.String(), app.AppErr))
} else {
checkAndAppendState(app.AppName, app.State.String())
}
}
}
if len(found) == len(appNames) {
if len(states) == len(appNames) {
for _, appName := range appNames {
if astate, inFoundSlice := found[appName]; inFoundSlice && astate == state {
if !checkNewLastState(appName, state) {
out += fmt.Sprintf(
"app %s state %s\n",
appName, state)
Expand Down Expand Up @@ -104,17 +127,23 @@ func TestAppStatus(t *testing.T) {
args[1:], state, secs)

apps := args[1:]
found = make(map[string]string)
states = make(map[string][]string)
for _, el := range apps {
found[el] = "no info from controller"
states[el] = []string{"no info from controller"}
}

tc.AddProcInfo(edgeNode, checkApp(state, apps))

callback := func() {
t.Errorf("ASSERTION FAILED: expected apps %s in %s state", apps, state)
for k, v := range found {
t.Errorf("\tactual app %s: %s", k, v)
for k, v := range states {
t.Errorf("\tactual %s: %s", k, v[len(v)-1])
if checkNewLastState(k, state) {
t.Errorf("\thistory of states for %s:", k)
for _, st := range v {
t.Errorf("\t\t%s", st)
}
}
}
}

Expand Down

0 comments on commit 2d15d7a

Please sign in to comment.