Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-shin0 committed Jul 24, 2024
1 parent 66d9a2b commit 8655a76
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions autopprof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,88 @@ func TestAutoPprof_watchGoroutineCount_reportAll(t *testing.T) {
)
},
},
{
name: "reportAll: true, disableCPUProf: true",
fields: fields{
watchInterval: 1 * time.Second,
goroutineThreshold: 100,
reportAll: true,
disableCPUProf: true,
disableMemProf: false,
stopC: make(chan struct{}),
},
mockFunc: func(mockCgroupsQueryer *queryer.MockCgroupsQueryer, mockRuntimeQueryer *queryer.MockRuntimeQueryer, mockProfiler *Mockprofiler, mockReporter *report.MockReporter) {
gomock.InOrder(
mockRuntimeQueryer.EXPECT().
GoroutineCount().
AnyTimes().
Return(200),

mockProfiler.EXPECT().
profileGoroutine().
AnyTimes().
Return([]byte("goroutine_prof"), nil),

mockReporter.EXPECT().
ReportGoroutineProfile(gomock.Any(), gomock.Any(), report.GoroutineInfo{
ThresholdCount: 100,
Count: 200,
}).
AnyTimes().
Return(nil),

mockCgroupsQueryer.EXPECT().
MemUsage().
AnyTimes().
Return(0.2, nil),

mockProfiler.EXPECT().
profileHeap().
AnyTimes().
Return([]byte("mem_prof"), nil),

mockReporter.EXPECT().
ReportHeapProfile(gomock.Any(), gomock.Any(), report.MemInfo{
ThresholdPercentage: 0.5 * 100,
UsagePercentage: 0.2 * 100,
}).
AnyTimes().
Return(nil),
)
},
},
{
name: "reportAll: false",
fields: fields{
watchInterval: 1 * time.Second,
goroutineThreshold: 100,
reportAll: false,
disableCPUProf: false,
disableMemProf: false,
stopC: make(chan struct{}),
},
mockFunc: func(mockCgroupsQueryer *queryer.MockCgroupsQueryer, mockRuntimeQueryer *queryer.MockRuntimeQueryer, mockProfiler *Mockprofiler, mockReporter *report.MockReporter) {
gomock.InOrder(
mockRuntimeQueryer.EXPECT().
GoroutineCount().
AnyTimes().
Return(200),

mockProfiler.EXPECT().
profileGoroutine().
AnyTimes().
Return([]byte("goroutine_prof"), nil),

mockReporter.EXPECT().
ReportGoroutineProfile(gomock.Any(), gomock.Any(), report.GoroutineInfo{
ThresholdCount: 100,
Count: 200,
}).
AnyTimes().
Return(nil),
)
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit 8655a76

Please sign in to comment.