Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix template always being overwritten. {pull}11671[11671]
- Fix matching of string arrays in contains condition. {pull}11691[11691]
- Fix initialization of the TCP input logger. {pull}11605[11605]
- Fix flaky service_integration_windows_test test by introducing a confidence factor and enriching the error message with more service details. {issue}8880[8880] and {issue}7977[7977]
Comment thread
narph marked this conversation as resolved.
Outdated

*Auditbeat*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ package service
import (
"testing"

"github.com/elastic/beats/libbeat/common"

"github.com/StackExchange/wmi"
"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -68,6 +70,8 @@ func TestReadService(t *testing.T) {
t.Fatal(err)
}

var stateChangedServices []common.MapStr

// Compare our module's data against WMI.
for _, s := range services {
// Look if the service is in the WMI data.
Expand All @@ -78,14 +82,17 @@ func TestReadService(t *testing.T) {
assert.Equal(t, w.ProcessId, s["pid"],
"PID of service %v does not match", w.DisplayName)
}
assert.Equal(t, w.State, s["state"],
"State of service %v does not match", w.DisplayName)

// For some services DisplayName and Name are the same. It seems to be a bug from the wmi query.
if w.DisplayName != w.Name {
assert.Equal(t, w.DisplayName, s["display_name"],
"Display name of service %v does not match", w.Name)
}
// Some services have changed state before the second retrieval.
if w.State != s["state"] {
changed := s
changed["initial_state"] = w.State
stateChangedServices = append(stateChangedServices, changed)
}
found = true
break
}
Expand All @@ -96,4 +103,14 @@ func TestReadService(t *testing.T) {
t.Errorf("Service %s can not be found by wmi query", s["name"])
}
}
// If more than 90% of the services have the same state then we have enough confidence the state check works while being resilient to race conditions,
// else it will require further investigation on which services are failing
if stateChangedServices != nil {
failing := float64(len(stateChangedServices)) / float64(len(services)) * 100
if failing > 90 {
// print entire information on the services failing
t.Errorf("%.2f%% of the services have a different state than initial one \n : %s", failing, stateChangedServices)
}
}

}