-
Notifications
You must be signed in to change notification settings - Fork 154
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
[Flaky Test] TestComponentBuildHashInDiagnostics improve agent state check #5420
[Flaky Test] TestComponentBuildHashInDiagnostics improve agent state check #5420
Conversation
This pull request does not have a backport label. Could you fix it @AndersonQ? 🙏
NOTE: |
@@ -130,13 +148,13 @@ func TestComponentBuildHashInDiagnostics(t *testing.T) { | |||
allHealthy, | |||
5*time.Minute, 10*time.Second, | |||
"agent never became healthy. Last status: %v", &stateBuff) | |||
t.Cleanup(func() { | |||
defer func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we switching from Cleanup
to defer
here? As far as I'm aware these should be interchangeable if we aren't using subtests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one of them attempts to move a file from a tempDir to a persistent one and it failed. So I'm guessing it might be because the temp directory was cleaned up before my function run. So I'm attempting to avoid it by using just defer
|
||
if len(status.Components) == 0 { | ||
stateBuff.WriteString(fmt.Sprintf( | ||
"healty but without components: agent status: %s-%s", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"healty but without components: agent status: %s-%s", | |
"healthy but without components: agent status: %s-%s", |
for _, c := range status.Components { | ||
bs, err := json.MarshalIndent(status, "", " ") | ||
if err != nil { | ||
stateBuff.WriteString(fmt.Sprintf("%s not health, could not marshal status outptu: %v", | ||
stateBuff.WriteString(fmt.Sprintf( | ||
"%s not health, could not marshal status outptu: %v", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"%s not health, could not marshal status outptu: %v", | |
"%s not healthy, could not marshal status output: %v", |
return false | ||
} | ||
|
||
if len(status.Components) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment above this to explain why this check is required being it really fixed the flaky issue in the test.
|
…cs improve agent state check (#5435) * [Flaky Test] TestComponentBuildHashInDiagnostics improve agent state check (#5420) ensure the agent status has components, all components are healthy and the version info is up-to-date (cherry picked from commit 116e73f) * manually backport de3dec4 --------- Co-authored-by: Anderson Queiroz <anderson.queiroz@elastic.co>
What does this PR do?
Improves the agent status check on TestComponentBuildHashInDiagnostics to ensure the agent is healthy and has components.
Why is it important?
The test is flaky because the test did not account for the absence of components
Checklist
[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration files[ ] I have added tests that prove my fix is effective or that my feature works[ ] I have added an entry in./changelog/fragments
using the changelog tool[ ] I have added an integration test or an E2E testDisruptive User Impact
How to test this PR locally
TEST_RUN_UNTIL_FAILURE
until you're satisfied or it fails againRelated issues
Questions to ask yourself