Skip to content

Commit

Permalink
Fix process filter test (#126)
Browse files Browse the repository at this point in the history
## What does this PR do?

Fixes an issue that came to light with
#125

In certain instances, `FilterTest` will fail, if the process with the
most memory usage and most CPU usage are the same.
  • Loading branch information
fearful-symmetry authored Jan 5, 2024
1 parent 085e452 commit 44721e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ linters-settings:

nolintlint:
# Enable to ensure that nolint directives are all used. Default is true.
allow-unused: false
allow-unused: true
# Disable to ensure that nolint directives don't have a leading space. Default is true.
allow-leading-space: false
# Exclude following linters from requiring an explanation. Default is [].
Expand Down
11 changes: 7 additions & 4 deletions metric/system/process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestNetworkFilter(t *testing.T) {

_, exists := data.GetValue("network.ip.Forwarding")
require.NoError(t, exists, "filter did not preserve key")
ipMetrics, exists := data.GetValue("network.ip")
ipMetrics, _ := data.GetValue("network.ip")
require.Equal(t, 1, len(ipMetrics.(map[string]interface{})))
}

Expand All @@ -196,7 +196,10 @@ func TestFilter(t *testing.T) {

procData, _, err := testConfig.Get()
assert.NoError(t, err, "GetOne")
assert.Equal(t, 2, len(procData))
// the total count of processes can either be one or two,
// depending on if the highest-mem-usage process and
// highest-cpu-usage process are the same.
assert.GreaterOrEqual(t, len(procData), 1)

testZero := Stats{
Procs: []string{".*"},
Expand Down Expand Up @@ -581,7 +584,7 @@ func TestIncludeTopProcesses(t *testing.T) {
//go:generate docker run --rm -v ./testdata:/app --entrypoint g++ docker.elastic.co/beats-dev/golang-crossbuild:1.21.0-main -pthread -std=c++11 -o /app/threads /app/threads.cpp
//go:generate docker run --rm -v ./testdata:/app --entrypoint o64-clang++ docker.elastic.co/beats-dev/golang-crossbuild:1.21.0-darwin -pthread -std=c++11 -o /app/threads-darwin /app/threads.cpp
//go:generate docker run --rm -v ./testdata:/app --entrypoint x86_64-w64-mingw32-g++-posix docker.elastic.co/beats-dev/golang-crossbuild:1.21.0-main -pthread -std=c++11 -o /app/threads.exe /app/threads.cpp
func runThreads(t *testing.T) *exec.Cmd {
func runThreads(t *testing.T) *exec.Cmd { //nolint: deadcode,structcheck,unused // needed by other platforms
t.Helper()

supportedPlatforms := []string{"linux/amd64", "darwin/amd64", "windows/amd64"}
Expand Down Expand Up @@ -654,7 +657,7 @@ func initTestResolver() (Stats, error) {
return testConfig, err
}

func sliceContains(s []string, e string) bool {
func sliceContains(s []string, e string) bool { //nolint: deadcode,structcheck,unused // needed by other platforms
for _, v := range s {
if e == v {
return true
Expand Down

0 comments on commit 44721e5

Please sign in to comment.