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

Add new test case for force-leave #16260

Merged
merged 4 commits into from
Mar 3, 2023

Conversation

dttung2905
Copy link
Contributor

Hi team,

This MR aims to add the test case for force-leave on exsisting node

It will solve issue #15559

Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

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

Thanks for this PR @dttung2905!

Comment on lines 129 to 137
time.Sleep(3 * time.Second)

membersAfter, err := a.MembersOpts(&QueryOptions{})

for _, node := range membersAfter.Members {
if node.Name == membersBefore.Members[1].Name {
must.Eq(t, node.Status, "leaving")
}
}
Copy link
Member

Choose a reason for hiding this comment

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

For this kind of thing, rather than waiting a static period of time, we can use shoenig/test/wait to wait until the assertion is true or the timeout expires. That lets us move the test along if the desired state is reached quickly.

For example, the following takes <3sec on my machine instead of >6sec. This adds up given the number of tests we run!

Suggested change
time.Sleep(3 * time.Second)
membersAfter, err := a.MembersOpts(&QueryOptions{})
for _, node := range membersAfter.Members {
if node.Name == membersBefore.Members[1].Name {
must.Eq(t, node.Status, "leaving")
}
}
f := func() error {
membersAfter, err := a.MembersOpts(&QueryOptions{})
if err != nil {
return err
}
for _, node := range membersAfter.Members {
if node.Name == membersBefore.Members[1].Name {
if node.Status != "leaving" {
return fmt.Errorf("node did not leave")
}
}
}
return nil
}
must.Wait(t, wait.InitialSuccess(
wait.ErrorFunc(f),
wait.Timeout(3*time.Second),
wait.Gap(100*time.Millisecond),
))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks alot for the suggestion and the code snippet. This is exactly what I'm looking for when writing this test. Totally agree that we can greatly reduce the test run time by making the wait.Gap() more aggressive instead of waiting for the whole duration.

Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks again @dttung2905!

@tgross tgross merged commit 2ec6575 into hashicorp:main Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

2 participants