Skip to content

Commit

Permalink
managerV2_test: Fix code smell around state check (#42389)
Browse files Browse the repository at this point in the history
```
!(state == proto.State_HEALTHY || state != proto.State_CONFIGURING || state == proto.State_STARTING
```

can only be true when
```
state == proto.State_CONFIGURING
```
which is probably not the intention around this test.

This PR changes the code to a `Contains()` call.
  • Loading branch information
orestisfl authored Jan 22, 2025
1 parent 5bd76b0 commit fe4882c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions x-pack/filebeat/tests/integration/managerV2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,11 @@ func TestInputReloadUnderElasticAgent(t *testing.T) {
nextState()
}
for _, unit := range observed.GetUnits() {
if state := unit.GetState(); !(state == proto.State_HEALTHY || state != proto.State_CONFIGURING || state == proto.State_STARTING) {
t.Fatalf("Unit '%s' is not healthy, state: %s", unit.GetId(), unit.GetState().String())
expected := []proto.State{proto.State_HEALTHY, proto.State_CONFIGURING, proto.State_STARTING}
if !waiting {
expected = append(expected, proto.State_STOPPING)
}
require.Containsf(t, expected, unit.GetState(), "Unit '%s' is not healthy, state: %s", unit.GetId(), unit.GetState().String())
}
return &proto.CheckinExpected{
Units: units[idx],
Expand All @@ -240,8 +242,8 @@ func TestInputReloadUnderElasticAgent(t *testing.T) {
// 0.5 second left, return the time left
// - otherwise return the time left minus 0.5 second.
waitDeadlineOr5Min := func() time.Duration {
deadline, deadileSet := t.Deadline()
if deadileSet {
deadline, deadlineSet := t.Deadline()
if deadlineSet {
left := time.Until(deadline)
final := left - 500*time.Millisecond
if final <= 0 {
Expand Down

0 comments on commit fe4882c

Please sign in to comment.