@@ -24,19 +24,58 @@ import (
24
24
"io/ioutil"
25
25
"os"
26
26
"os/exec"
27
+ "runtime"
27
28
"strconv"
29
+ "strings"
28
30
"syscall"
29
31
"testing"
30
32
"time"
31
33
32
34
"github.com/docker/machine/libmachine/state"
35
+ "k8s.io/minikube/pkg/minikube/constants"
33
36
"k8s.io/minikube/pkg/minikube/localpath"
34
37
"k8s.io/minikube/pkg/util/retry"
35
38
)
36
39
37
- func TestScheduledStop (t * testing.T ) {
40
+ func TestScheduledStopWindows (t * testing.T ) {
41
+ if runtime .GOOS != "windows" {
42
+ t .Skip ("test only runs on windows" )
43
+ }
38
44
if NoneDriver () {
39
- t .Skip ("--schedule does not apply to none driver " )
45
+ t .Skip ("--schedule does not work with the none driver" )
46
+ }
47
+ profile := UniqueProfileName ("scheduled-stop" )
48
+ ctx , cancel := context .WithTimeout (context .Background (), Minutes (5 ))
49
+ defer CleanupWithLogs (t , profile , cancel )
50
+ startMinikube (ctx , t , profile )
51
+
52
+ // schedule a stop for 5m from now
53
+ scheduledStopMinikube (ctx , t , profile , "5m" )
54
+
55
+ // make sure the systemd service is running
56
+ rr , err := Run (t , exec .CommandContext (ctx , Target (), []string {"ssh" , "-p" , profile , "--" , "sudo" , "systemctl" , "show" , constants .ScheduledStopSystemdService , "--no-page" }... ))
57
+ if err != nil {
58
+ t .Fatalf ("getting minikube-scheduled-stop status: %v\n %s" , err , rr .Output ())
59
+ }
60
+ if ! strings .Contains (rr .Output (), "ActiveState=active" ) {
61
+ t .Fatalf ("minikube-scheduled-stop is not running: %v" , rr .Output ())
62
+ }
63
+
64
+ // reschedule stop for 5 seconds from now
65
+ scheduledStopMinikube (ctx , t , profile , "5s" )
66
+
67
+ // sleep for 5 seconds
68
+ time .Sleep (5 * time .Second )
69
+ // make sure minikube status is "Stopped"
70
+ ensureMinikubeStatusStopped (ctx , t , profile )
71
+ }
72
+
73
+ func TestScheduledStopUnix (t * testing.T ) {
74
+ if runtime .GOOS == "windows" {
75
+ t .Skip ("test only runs on unix" )
76
+ }
77
+ if NoneDriver () {
78
+ t .Skip ("--schedule does not work with the none driver" )
40
79
}
41
80
profile := UniqueProfileName ("scheduled-stop" )
42
81
ctx , cancel := context .WithTimeout (context .Background (), Minutes (5 ))
@@ -56,19 +95,8 @@ func TestScheduledStop(t *testing.T) {
56
95
t .Fatalf ("process %v running but should have been killed on reschedule of stop" , pid )
57
96
}
58
97
checkPID (t , profile )
59
- // wait allotted time to make sure minikube status is "Stopped"
60
- checkStatus := func () error {
61
- ctx , cancel := context .WithDeadline (ctx , time .Now ().Add (10 * time .Second ))
62
- defer cancel ()
63
- got := Status (ctx , t , Target (), profile , "Host" , profile )
64
- if got != state .Stopped .String () {
65
- return fmt .Errorf ("expected post-stop host status to be -%q- but got *%q*" , state .Stopped , got )
66
- }
67
- return nil
68
- }
69
- if err := retry .Expo (checkStatus , time .Second , time .Minute ); err != nil {
70
- t .Fatalf ("error %v" , err )
71
- }
98
+ // make sure minikube status is "Stopped"
99
+ ensureMinikubeStatusStopped (ctx , t , profile )
72
100
}
73
101
74
102
func startMinikube (ctx context.Context , t * testing.T , profile string ) {
@@ -116,3 +144,19 @@ func processRunning(t *testing.T, pid string) bool {
116
144
t .Log ("signal error was: " , err )
117
145
return err == nil
118
146
}
147
+
148
+ func ensureMinikubeStatusStopped (ctx context.Context , t * testing.T , profile string ) {
149
+ // wait allotted time to make sure minikube status is "Stopped"
150
+ checkStatus := func () error {
151
+ ctx , cancel := context .WithDeadline (ctx , time .Now ().Add (10 * time .Second ))
152
+ defer cancel ()
153
+ got := Status (ctx , t , Target (), profile , "Host" , profile )
154
+ if got != state .Stopped .String () {
155
+ return fmt .Errorf ("expected post-stop host status to be -%q- but got *%q*" , state .Stopped , got )
156
+ }
157
+ return nil
158
+ }
159
+ if err := retry .Expo (checkStatus , time .Second , time .Minute ); err != nil {
160
+ t .Fatalf ("error %v" , err )
161
+ }
162
+ }
0 commit comments