improves IsActive testing
This commit is contained in:
parent
e941c90f0d
commit
27c2ad77c8
@ -267,4 +267,27 @@ func TestGetPID(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
t.Run(fmt.Sprintf("prove pid changes"), func(t *testing.T) {
|
||||
if userString != "root" && userString != "system" {
|
||||
t.Skip("skipping superuser test while running as user")
|
||||
}
|
||||
unit := "nginx"
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
Restart(ctx, unit, Options{UserMode: true})
|
||||
pid, err := GetPID(ctx, unit, Options{UserMode: false})
|
||||
if err != nil {
|
||||
t.Errorf("issue getting MainPID for nginx as %s: %v", userString, err)
|
||||
}
|
||||
syscall.Kill(pid, syscall.SIGKILL)
|
||||
secondPid, err := GetPID(ctx, unit, Options{UserMode: false})
|
||||
if err != nil {
|
||||
t.Errorf("issue getting second MainPID for nginx as %s: %v", userString, err)
|
||||
}
|
||||
if pid == secondPid {
|
||||
t.Errorf("Expected pid != secondPid, but both were: %d", pid)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
@ -152,9 +152,9 @@ func TestIsActive(t *testing.T) {
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
err := Start(ctx, unit, Options{UserMode: false})
|
||||
err := Restart(ctx, unit, Options{UserMode: false})
|
||||
if err != nil {
|
||||
t.Errorf("Unable to restart %s", unit)
|
||||
t.Errorf("Unable to restart %s: %v", unit, err)
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
isActive, err := IsActive(ctx, unit, Options{UserMode: false})
|
||||
|
Loading…
x
Reference in New Issue
Block a user