[process] Fix Test_Children test regression because of some other running test

pull/796/head
Lomanic 6 years ago
parent 1fcea92f73
commit e7090ba9fc

@ -2,10 +2,12 @@ package process
import (
"fmt"
"io/ioutil"
"net"
"os"
"os/exec"
"os/user"
"path/filepath"
"reflect"
"runtime"
"strconv"
@ -13,8 +15,6 @@ import (
"sync"
"testing"
"time"
"path/filepath"
"io/ioutil"
"github.com/shirou/gopsutil/internal/common"
"github.com/stretchr/testify/assert"
@ -303,7 +303,7 @@ func Test_Process_Long_Name(t *testing.T) {
t.Fatalf("unable to create temp file %v", err)
}
tmpfilecontent := []byte("package main\nimport(\n\"time\"\n)\nfunc main(){\ntime.Sleep(time.Second)\n}")
tmpfilecontent := []byte("package main\nimport(\n\"time\"\n)\nfunc main(){\nfor range time.Tick(time.Second) {}\n}")
if _, err := tmpfile.Write(tmpfilecontent); err != nil {
tmpfile.Close()
t.Fatalf("unable to write temp file %v", err)
@ -312,7 +312,7 @@ func Test_Process_Long_Name(t *testing.T) {
t.Fatalf("unable to close temp file %v", err)
}
err = exec.Command("go", "build", "-o", tmpfile.Name() + ".exe", tmpfile.Name()).Run()
err = exec.Command("go", "build", "-o", tmpfile.Name()+".exe", tmpfile.Name()).Run()
if err != nil {
t.Fatalf("unable to build temp file %v", err)
}
@ -324,7 +324,7 @@ func Test_Process_Long_Name(t *testing.T) {
p, err := NewProcess(int32(cmd.Process.Pid))
skipIfNotImplementedErr(t, err)
assert.Nil(t, err)
n, err := p.Name()
skipIfNotImplementedErr(t, err)
if err != nil {
@ -334,7 +334,7 @@ func Test_Process_Long_Name(t *testing.T) {
if basename != n {
t.Fatalf("%s != %s", basename, n)
}
cmd.Wait()
cmd.Process.Kill()
}
func Test_Process_Exe(t *testing.T) {
p := testGetProcess()
@ -503,7 +503,14 @@ func Test_Children(t *testing.T) {
if len(c) == 0 {
t.Fatalf("children is empty")
}
if c[0].Pid != int32(cmd.Process.Pid) {
found := false
for _, child := range c {
if child.Pid == int32(cmd.Process.Pid) {
found = true
break
}
}
if !found {
t.Errorf("could not find child %d", cmd.Process.Pid)
}
}

Loading…
Cancel
Save