Skip to content

Commit

Permalink
Check new state implementation
Browse files Browse the repository at this point in the history
We want to use check-new option to check options after transition, thus
 the next state after initial

Signed-off-by: Petr Fedchenkov <[email protected]>
  • Loading branch information
giggsoff committed Oct 21, 2023
1 parent 523cad4 commit 1b681f8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
17 changes: 16 additions & 1 deletion tests/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))

Check failure on line 121 in tests/app/app_test.go

View workflow job for this annotation

GitHub Actions / yetus

golangcilint: use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
return nil
}
}
out += utils.AddTimestamp(fmt.Sprintf(
"app %s state %s\n",
appName, state))
Expand All @@ -133,6 +146,8 @@ func checkApp(edgeNode *device.Ctx, state string, appNames []string) projects.Pr
func TestAppStatus(t *testing.T) {

Check failure on line 146 in tests/app/app_test.go

View workflow job for this annotation

GitHub Actions / yetus

golangcilint: calculated cyclomatic complexity for function TestAppStatus is 12, max is 10 (cyclop)
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])
Expand Down
17 changes: 16 additions & 1 deletion tests/network/nw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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])
Expand Down
17 changes: 16 additions & 1 deletion tests/volume/vol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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])
Expand Down

0 comments on commit 1b681f8

Please sign in to comment.