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

test(dm): fix unsteable test TestRedirectRequestToLeader (#4556) #4649

Merged
Merged
Changes from all commits
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
12 changes: 9 additions & 3 deletions dm/dm/master/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ func (t *openAPISuite) TestRedirectRequestToLeader(c *check.C) {
s1 := NewServer(cfg1)
c.Assert(s1.Start(ctx), check.IsNil)
defer s1.Close()
defer cancel()

// wait the first one become the leader
c.Assert(utils.WaitSomething(30, 100*time.Millisecond, func() bool {
return s1.election.IsLeader()
return s1.election.IsLeader() && s1.scheduler.Started()
}), check.IsTrue)

// join to an existing cluster
Expand All @@ -113,6 +114,12 @@ func (t *openAPISuite) TestRedirectRequestToLeader(c *check.C) {
s2 := NewServer(cfg2)
c.Assert(s2.Start(ctx), check.IsNil)
defer s2.Close()
defer cancel() // this cancel must call before s.Close() to avoid deadlock

// wait the second master ready
c.Assert(utils.WaitSomething(30, 100*time.Millisecond, func() bool {
return s2.election.IsLeader()
}), check.IsFalse)

baseURL := "/api/v1/sources"
// list source from leader
Expand All @@ -128,7 +135,6 @@ func (t *openAPISuite) TestRedirectRequestToLeader(c *check.C) {
// list source not from leader will get a redirect
result2 := testutil.NewRequest().Get(baseURL).GoWithHTTPHandler(t.testT, s2.openapiHandles)
c.Assert(result2.Code(), check.Equals, http.StatusTemporaryRedirect)
cancel()
}

func (t *openAPISuite) TestOpenAPIWillNotStartInDefaultConfig(c *check.C) {
Expand All @@ -151,7 +157,7 @@ func (t *openAPISuite) TestOpenAPIWillNotStartInDefaultConfig(c *check.C) {
}), check.IsTrue)
c.Assert(s1.openapiHandles, check.IsNil)
defer s1.Close()
cancel()
defer cancel()
}

func (t *openAPISuite) TestSourceAPI(c *check.C) {
Expand Down