Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows flaky test TestComponentBuildHashInDiagnostics #4219

Merged
merged 4 commits into from
Feb 8, 2024
Merged
Changes from 1 commit
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
30 changes: 19 additions & 11 deletions testing/integration/package_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package integration
import (
"bytes"
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -48,7 +49,7 @@ func TestPackageVersion(t *testing.T) {
// run the agent and check the daemon version as well
t.Run("check package version while the agent is running", testVersionWithRunningAgent(ctx, f))

// Destructive/mutating tests ahead! If you need to do a normal test on a healthy install of agent, put it before the tests below
// Destructive/mutating tests ahead! If you need to do a normal test on a healthy installation of agent, put it before the tests below

// change the version in the version file and verify that the agent returns the new value
t.Run("check package version after updating file", testVersionAfterUpdatingFile(ctx, f))
Expand All @@ -64,10 +65,6 @@ func TestComponentBuildHashInDiagnostics(t *testing.T) {
Local: false, // requires Agent installation
Sudo: true, // requires Agent installation
})
if runtime.GOOS == "windows" {
t.Skip("flaky on windows: https://github.com/elastic/elastic-agent/issues/4215")
}

ctx := context.Background()

f, err := define.NewFixture(t, define.Version())
Expand All @@ -93,20 +90,31 @@ func TestComponentBuildHashInDiagnostics(t *testing.T) {
"failed to install start agent [output: %s]", string(output))

stateBuff := bytes.Buffer{}
isHealth := func() bool {
allHealthy := func() bool {
stateBuff.Reset()

err := f.IsHealthy(ctx)
status, err := f.ExecStatus(ctx)
if err != nil {
stateBuff.WriteString(err.Error())
stateBuff.WriteString(fmt.Sprintf("failed to get agent status: %v",
err))
return false
}

return true
allHealthy := true
for _, c := range status.Components {
state := client.State(c.State)
if state != client.Healthy {
allHealthy = false
stateBuff.WriteString(fmt.Sprintf("%s not health, state: %s",
Copy link
Member

@pchila pchila Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: couldn't you just track the last status and dump that if the assertion fails? I understand that it would be bigger but it's a test and if it fails the more information we have, the better...

c.Name, state))
}
}

return allHealthy
}
require.Eventuallyf(t,
isHealth,
1*time.Minute, 10*time.Second,
allHealthy,
5*time.Minute, 10*time.Second,
"agent did not became health. Last status: %v", &stateBuff)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"agent did not became health. Last status: %v", &stateBuff)
"agent never became healthy. Last status: %v", &stateBuff)


filebeat := "filebeat"
Expand Down
Loading