Skip to content

Commit d8f5134

Browse files
authored
fix windows flaky test TestComponentBuildHashInDiagnostics (#4219)
Makes the test integration test TestComponentBuildHashInDiagnostics to wait all components to be healthy after agent installation before proceeding with the test.
1 parent 5ce913e commit d8f5134

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

testing/integration/package_version_test.go

+26-11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ package integration
99
import (
1010
"bytes"
1111
"context"
12+
"encoding/json"
13+
"fmt"
1214
"os"
1315
"os/exec"
1416
"path/filepath"
@@ -48,7 +50,7 @@ func TestPackageVersion(t *testing.T) {
4850
// run the agent and check the daemon version as well
4951
t.Run("check package version while the agent is running", testVersionWithRunningAgent(ctx, f))
5052

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

5355
// change the version in the version file and verify that the agent returns the new value
5456
t.Run("check package version after updating file", testVersionAfterUpdatingFile(ctx, f))
@@ -64,10 +66,6 @@ func TestComponentBuildHashInDiagnostics(t *testing.T) {
6466
Local: false, // requires Agent installation
6567
Sudo: true, // requires Agent installation
6668
})
67-
if runtime.GOOS == "windows" {
68-
t.Skip("flaky on windows: https://github.com/elastic/elastic-agent/issues/4215")
69-
}
70-
7169
ctx := context.Background()
7270

7371
f, err := define.NewFixture(t, define.Version())
@@ -93,21 +91,38 @@ func TestComponentBuildHashInDiagnostics(t *testing.T) {
9391
"failed to install start agent [output: %s]", string(output))
9492

9593
stateBuff := bytes.Buffer{}
96-
isHealth := func() bool {
94+
allHealthy := func() bool {
9795
stateBuff.Reset()
9896

99-
err := f.IsHealthy(ctx)
97+
status, err := f.ExecStatus(ctx)
10098
if err != nil {
101-
stateBuff.WriteString(err.Error())
99+
stateBuff.WriteString(fmt.Sprintf("failed to get agent status: %v",
100+
err))
102101
return false
103102
}
104103

104+
for _, c := range status.Components {
105+
state := client.State(c.State)
106+
if state != client.Healthy {
107+
bs, err := json.MarshalIndent(status, "", " ")
108+
if err != nil {
109+
stateBuff.WriteString(fmt.Sprintf("%s not health, could not marshal status outptu: %v",
110+
c.Name, err))
111+
return false
112+
}
113+
114+
stateBuff.WriteString(fmt.Sprintf("%s not health, agent status output: %s",
115+
c.Name, bs))
116+
return false
117+
}
118+
}
119+
105120
return true
106121
}
107122
require.Eventuallyf(t,
108-
isHealth,
109-
1*time.Minute, 10*time.Second,
110-
"agent did not became health. Last status: %v", &stateBuff)
123+
allHealthy,
124+
5*time.Minute, 10*time.Second,
125+
"agent never became healthy. Last status: %v", &stateBuff)
111126

112127
filebeat := "filebeat"
113128
if runtime.GOOS == "windows" {

0 commit comments

Comments
 (0)