improves IsActive testing

This commit is contained in:
Tai Groot 2021-05-16 22:32:24 -07:00
parent e941c90f0d
commit 27c2ad77c8
Signed by: taigrr
GPG Key ID: D00C269A87614812
2 changed files with 25 additions and 2 deletions

View File

@ -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)
}
})
} }

View File

@ -152,9 +152,9 @@ func TestIsActive(t *testing.T) {
} }
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()
err := Start(ctx, unit, Options{UserMode: false}) err := Restart(ctx, unit, Options{UserMode: false})
if err != nil { if err != nil {
t.Errorf("Unable to restart %s", unit) t.Errorf("Unable to restart %s: %v", unit, err)
} }
time.Sleep(time.Second) time.Sleep(time.Second)
isActive, err := IsActive(ctx, unit, Options{UserMode: false}) isActive, err := IsActive(ctx, unit, Options{UserMode: false})