Skip to content

Commit

Permalink
Merge branch 'master' into start-time-2
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Feb 14, 2022
2 parents 3ba5edd + e230160 commit eed3ec1
Showing 1 changed file with 9 additions and 3 deletions.
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

0 comments on commit eed3ec1

Please sign in to comment.