Removes external lib dependency

Since the test is failing on architectures/platform I can't reproduce
on.. I'm readapting the test in such a way to minimize the amount of
code that can be responsible for the error.

We're not looking for all system processes in order to find our
mount processes(ps -ef); we're looking directly at the mount
processes that have been spawned by our test instead.

To say that a process is no longer alive:
We try to wait for conclusion to get the processState.
If the wait results in an *ExitError, it means that either
the proc has failed to run, or it exited failing(see doc);
in both cases we're happy.. since we previously made a check
to know that those same processes were alive.
pull/15782/head
x7upLime 2023-02-13 00:20:09 +02:00
parent ead0b401ae
commit b5d5bbe38c
1 changed files with 21 additions and 17 deletions

View File

@ -33,7 +33,6 @@ import (
"testing"
"time"
psutil "github.com/shirou/gopsutil/v3/process"
"k8s.io/minikube/pkg/util/retry"
)
@ -343,22 +342,26 @@ func validateMountCmd(ctx context.Context, t *testing.T, profile string) { // no
t.Fatalf("mount was not ready in time: %v", err)
}
checkProcs := func() {
procs, err := psutil.Processes()
if err != nil {
t.Fatalf("failed gathering processes: %v", err)
}
for _, p := range procs {
cmdline, err := p.Cmdline()
if err != nil {
t.Fatalf("failed reading process cmdline: %v", err)
}
for _, mnt := range inNodeMounts {
if strings.Contains(cmdline, fmt.Sprintf("-p\x20%s\x20%s:%s", profile, tempDir, mnt)) {
t.Fatalf("Found active mount processes")
checkProcsAlive := func(end chan bool) {
for _, mntp := range mntProcs {
// Trying to wait for process end
// if the wait fail with ExitError we know that the process
// doesnt' exist anymore..
go func(end chan bool) {
err := mntp.cmd.Wait()
if _, ok := err.(*exec.ExitError); ok {
end <- true
}
}(end)
// Either we know that the mount process has ended
// or we fail after 1 second
// TODO: is there a better way? rather than waiting..
select {
case <-time.After(1 * time.Second):
t.Fatalf("1s TIMEOUT: Process %d is still running\n", mntp.cmd.Process.Pid)
case <-end:
continue
}
}
}
@ -369,6 +372,7 @@ func validateMountCmd(ctx context.Context, t *testing.T, profile string) { // no
t.Fatalf("failed while trying to kill mounts")
}
checkProcs()
end := make(chan bool, 1)
checkProcsAlive(end)
})
}