1
1
package checks
2
2
3
3
import (
4
- "errors"
5
4
"regexp"
6
5
"runtime"
7
6
"strconv"
@@ -20,10 +19,7 @@ import (
20
19
"github.com/DataDog/gopsutil/process"
21
20
)
22
21
23
- func procCtrGenerator (pCount int , cCount int , containeredProcs int ) ([]* process.FilledProcess , []* containers.Container , error ) {
24
- if (pCount < cCount ) || (containeredProcs > pCount ) {
25
- return nil , nil , errors .New ("The process and container count specified is not valid" )
26
- }
22
+ func procCtrGenerator (pCount int , cCount int , containeredProcs int ) ([]* process.FilledProcess , []* containers.Container ) {
27
23
procs := make ([]* process.FilledProcess , 0 , pCount )
28
24
for i := 0 ; i < pCount ; i ++ {
29
25
procs = append (procs , makeProcess (int32 (i ), strconv .Itoa (i )))
@@ -45,7 +41,7 @@ func procCtrGenerator(pCount int, cCount int, containeredProcs int) ([]*process.
45
41
ctrIdx ++
46
42
}
47
43
48
- return procs , ctrs , nil
44
+ return procs , ctrs
49
45
}
50
46
51
47
func procsToHash (procs []* process.FilledProcess ) (procsByPid map [int32 ]* process.FilledProcess ) {
@@ -113,6 +109,14 @@ func TestRandomizeMessages(t *testing.T) {
113
109
maxSize : 30 ,
114
110
chunks : 4 ,
115
111
},
112
+ {
113
+ testName : "no-processes" ,
114
+ pCount : 0 ,
115
+ cCount : 30 ,
116
+ cProcs : 0 ,
117
+ maxSize : 10 ,
118
+ chunks : 1 ,
119
+ },
116
120
{
117
121
testName : "container-process-mixed-1" ,
118
122
pCount : 100 ,
@@ -148,9 +152,8 @@ func TestRandomizeMessages(t *testing.T) {
148
152
} {
149
153
150
154
t .Run (tc .testName , func (t * testing.T ) {
151
- procs , ctrs , err := procCtrGenerator (tc .pCount , tc .cCount , tc .cProcs )
155
+ procs , ctrs := procCtrGenerator (tc .pCount , tc .cCount , tc .cProcs )
152
156
procsByPid := procsToHash (procs )
153
- assert .NoError (t , err )
154
157
155
158
lastRun := time .Now ().Add (- 5 * time .Second )
156
159
syst1 , syst2 := cpu.TimesStat {}, cpu.TimesStat {}
@@ -264,9 +267,9 @@ func TestBasicProcessMessages(t *testing.T) {
264
267
maxSize : 2 ,
265
268
containers : []* containers.Container {c [1 ]},
266
269
blacklist : []string {"foo" },
267
- expectedChunks : 1 ,
270
+ expectedChunks : 2 ,
268
271
totalProcs : 2 ,
269
- totalContainers : 0 ,
272
+ totalContainers : 1 ,
270
273
},
271
274
} {
272
275
t .Run (tc .testName , func (t * testing.T ) {
0 commit comments