forked from ycrash/yc-360-script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproc_test.go
More file actions
51 lines (46 loc) · 971 Bytes
/
proc_test.go
File metadata and controls
51 lines (46 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package shell
import (
"testing"
)
func TestCheckProcessExists(t *testing.T) {
e := IsProcessExists(65535)
if e {
t.Fatal("process 65535 should not exists")
}
noGC, err := CommandStartInBackground(Command{"java", "-cp", "./capture/testdata/", "MyClass"})
if err != nil {
t.Fatal(err)
}
defer noGC.KillAndWait()
e = IsProcessExists(noGC.GetPid())
if !e {
t.Fatal("process should be exists")
}
}
func TestGetTopProcess(t *testing.T) {
noGC, err := CommandStartInBackground(Command{"java", "-cp", "./capture/testdata/", "MyClass"})
if err != nil {
t.Fatal(err)
}
defer noGC.KillAndWait()
t.Run("cpu", func(t *testing.T) {
id, err := GetTopCpu()
if err != nil {
t.Fatal(err)
}
t.Log(id)
if id < 1 {
t.Fatal("can not get pid of java process")
}
})
t.Run("mem", func(t *testing.T) {
id, err := GetTopMem()
if err != nil {
t.Fatal(err)
}
t.Log(id)
if id < 1 {
t.Fatal("can not get pid of java process")
}
})
}