Skip to content

Commit

Permalink
added function to check scheduledstop time comparison
Browse files Browse the repository at this point in the history
Signed-off-by: Tharun <rajendrantharun@live.com>
  • Loading branch information
tharun208 committed Dec 8, 2020
1 parent 40cf0da commit c6e6f2d
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions test/integration/scheduled_stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestScheduledStopWindows(t *testing.T) {
// schedule a stop for 5m from now
stopMinikube(ctx, t, profile, []string{"--schedule", "5m"})
// make sure timeToStop is present in status
ensureMinikubeStatus(ctx, t, profile, "TimeToStop", "3m")
ensureMinikubeScheduledTime(ctx, t, profile, 5*time.Minute)
// make sure the systemd service is running
rr, err := Run(t, exec.CommandContext(ctx, Target(), []string{"ssh", "-p", profile, "--", "sudo", "systemctl", "show", constants.ScheduledStopSystemdService, "--no-page"}...))
if err != nil {
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestScheduledStopUnix(t *testing.T) {
// schedule a stop for 5 min from now and make sure PID is created
stopMinikube(ctx, t, profile, []string{"--schedule", "5m"})
// make sure timeToStop is present in status
ensureMinikubeStatus(ctx, t, profile, "TimeToStop", "3m")
ensureMinikubeScheduledTime(ctx, t, profile, 5*time.Minute)
pid := checkPID(t, profile)
if !processRunning(t, pid) {
t.Fatalf("process %v is not running", pid)
Expand All @@ -112,6 +112,8 @@ func TestScheduledStopUnix(t *testing.T) {
if processRunning(t, pid) {
t.Fatalf("process %v running but should have been killed on reschedule of stop", pid)
}

// make sure minikube status is "Stopped"
ensureMinikubeStatus(ctx, t, profile, "Host", state.Stopped.String())
// make sure minikube timtostop is "Nonexistent"
ensureMinikubeStatus(ctx, t, profile, "TimeToStop", "Nonexistent")
Expand Down Expand Up @@ -164,12 +166,11 @@ func processRunning(t *testing.T, pid string) bool {
return err == nil
}
func ensureMinikubeStatus(ctx context.Context, t *testing.T, profile, key string, wantStatus string) {
// wait allotted time to make sure minikube status is "Stopped"
checkStatus := func() error {
ctx, cancel := context.WithDeadline(ctx, time.Now().Add(10*time.Second))
defer cancel()
got := Status(ctx, t, Target(), profile, key, profile)
if !strings.Contains(got, wantStatus) {
if got != wantStatus {
return fmt.Errorf("expected post-stop %q status to be -%q- but got *%q*", key, wantStatus, got)
}
return nil
Expand All @@ -178,3 +179,19 @@ func ensureMinikubeStatus(ctx context.Context, t *testing.T, profile, key string
t.Fatalf("error %v", err)
}
}

func ensureMinikubeScheduledTime(ctx context.Context, t *testing.T, profile string, givenTime time.Duration) {
checkTime := func() error {
ctx, cancel := context.WithDeadline(ctx, time.Now().Add(10*time.Second))
defer cancel()
got := Status(ctx, t, Target(), profile, "TimeToStop", profile)
gotTime, _ := time.ParseDuration(got)
if gotTime < givenTime {
return nil
}
return fmt.Errorf("expected scheduled stop TimeToStop to be less than *%q* but got *%q*", givenTime, got)
}
if err := retry.Expo(checkTime, time.Second, time.Minute); err != nil {
t.Fatalf("error %v", err)
}
}

0 comments on commit c6e6f2d

Please sign in to comment.