-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
Signed-off-by: dttung2905 <[email protected]>
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.
Thanks for this PR @dttung2905!
api/agent_test.go
Outdated
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") | ||
} | ||
} |
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.
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!
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), | |
)) |
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.
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.
Signed-off-by: dttung2905 <[email protected]>
Signed-off-by: dttung2905 <[email protected]>
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.
LGTM! Thanks again @dttung2905!
Hi team,
This MR aims to add the test case for force-leave on exsisting node
It will solve issue #15559