diff --git a/tests/app/app_test.go b/tests/app/app_test.go index c0289fc24..5b35a6575 100644 --- a/tests/app/app_test.go +++ b/tests/app/app_test.go @@ -26,9 +26,11 @@ type appState struct { // This test wait for the app's state with a timewait. var ( timewait = flag.Duration("timewait", 10*time.Minute, "Timewait for items waiting") - _ = flag.Bool("check-new", false, "Check only new info messages") + checkNew = flag.Bool("check-new", false, "Check for the new state after state transition") tc *projects.TestContext states map[string][]appState + + lastRebootTime time.Time ) // TestMain is used to provide setup and teardown for the rest of the @@ -109,6 +111,17 @@ func checkState(eveState *eve.State, state string, appNames []string) error { if len(states) == len(appNames) { for _, appName := range appNames { if !checkNewLastState(appName, state) { + currentLastRebootTime := eveState.NodeState().LastRebootTime + // if we rebooted we may miss state transition + if *checkNew && !currentLastRebootTime.After(lastRebootTime) { + // first one is no info from controller + // the second is initial state + // we want to wait for the third or later, thus new state + if len(states[appName]) <= 2 { + fmt.Println(utils.AddTimestamp(fmt.Sprintf("\tappName %s wait for new state", appName))) + return nil + } + } out += utils.AddTimestamp(fmt.Sprintf( "app %s state %s\n", appName, state)) @@ -133,6 +146,8 @@ func checkApp(edgeNode *device.Ctx, state string, appNames []string) projects.Pr func TestAppStatus(t *testing.T) { edgeNode := tc.GetEdgeNode(tc.WithTest(t)) + lastRebootTime = tc.GetState(edgeNode).GetEVEState().NodeState().LastRebootTime + args := flag.Args() if len(args) == 0 { t.Fatalf("Usage: %s [options] state app_name...\n", os.Args[0]) diff --git a/tests/network/nw_test.go b/tests/network/nw_test.go index 92dcb6876..fc199b00a 100644 --- a/tests/network/nw_test.go +++ b/tests/network/nw_test.go @@ -22,9 +22,11 @@ type nwState struct { // This test wait for the network's state with a timewait. var ( timewait = flag.Duration("timewait", time.Minute, "Timewait for items waiting") - _ = flag.Bool("check-new", false, "Check only new info messages") + checkNew = flag.Bool("check-new", false, "Check for the new state after state transition") tc *projects.TestContext states map[string][]nwState + + lastRebootTime time.Time ) // TestMain is used to provide setup and teardown for the rest of the @@ -96,6 +98,17 @@ func checkState(eveState *eve.State, state string, netNames []string) error { if len(states) == len(netNames) { for _, netName := range netNames { if !checkNewLastState(netName, state) { + currentLastRebootTime := eveState.NodeState().LastRebootTime + // if we rebooted we may miss state transition + if *checkNew && !currentLastRebootTime.After(lastRebootTime) { + // first one is no info from controller + // the second is initial state + // we want to wait for the third or later, thus new state + if len(states[netName]) <= 2 { + fmt.Println(utils.AddTimestamp(fmt.Sprintf("\tnetName %s wait for new state", netName))) + return nil + } + } out += fmt.Sprintf( "network %s state %s\n", netName, state) @@ -120,6 +133,8 @@ func checkNet(edgeNode *device.Ctx, state string, volNames []string) projects.Pr func TestNetworkStatus(t *testing.T) { edgeNode := tc.GetEdgeNode(tc.WithTest(t)) + lastRebootTime = tc.GetState(edgeNode).GetEVEState().NodeState().LastRebootTime + args := flag.Args() if len(args) == 0 { t.Fatalf("Usage: %s [options] state vol_name...\n", os.Args[0]) diff --git a/tests/volume/vol_test.go b/tests/volume/vol_test.go index 4a80525ce..8086d24a4 100644 --- a/tests/volume/vol_test.go +++ b/tests/volume/vol_test.go @@ -22,9 +22,11 @@ type volState struct { // This test wait for the volume's state with a timewait. var ( timewait = flag.Duration("timewait", time.Minute, "Timewait for items waiting") - _ = flag.Bool("check-new", false, "Check only new info messages") + checkNew = flag.Bool("check-new", false, "Check for the new state after state transition") tc *projects.TestContext states map[string][]volState + + lastRebootTime time.Time ) // TestMain is used to provide setup and teardown for the rest of the @@ -100,6 +102,17 @@ func checkState(eveState *eve.State, state string, volNames []string) error { if len(states) == len(volNames) { for _, volName := range volNames { if !checkNewLastState(volName, state) { + currentLastRebootTime := eveState.NodeState().LastRebootTime + // if we rebooted we may miss state transition + if *checkNew && !currentLastRebootTime.After(lastRebootTime) { + // first one is no info from controller + // the second is initial state + // we want to wait for the third or later, thus new state + if len(states[volName]) <= 2 { + fmt.Println(utils.AddTimestamp(fmt.Sprintf("\tvolName %s wait for new state", volName))) + return nil + } + } out += fmt.Sprintf( "volume %s state %s\n", volName, state) @@ -124,6 +137,8 @@ func checkVol(edgeNode *device.Ctx, state string, volNames []string) projects.Pr func TestVolStatus(t *testing.T) { edgeNode := tc.GetEdgeNode(tc.WithTest(t)) + lastRebootTime = tc.GetState(edgeNode).GetEVEState().NodeState().LastRebootTime + args := flag.Args() if len(args) == 0 { t.Fatalf("Usage: %s [options] state vol_name...\n", os.Args[0])