Skip to content

Commit

Permalink
minor update
Browse files Browse the repository at this point in the history
Signed-off-by: disksing <[email protected]>
  • Loading branch information
disksing committed Jul 8, 2020
1 parent 6259042 commit 58f6601
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions tests/server/tso/tso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,46 +53,6 @@ func (s *testTsoSuite) TearDownSuite(c *C) {
s.cancel()
}

func (s *testTsoSuite) TestRequestFollower(c *C) {
cluster, err := tests.NewTestCluster(s.ctx, 2)
c.Assert(err, IsNil)
defer cluster.Destroy()

err = cluster.RunInitialServers()
c.Assert(err, IsNil)
cluster.WaitLeader()

var followerServer *tests.TestServer
for _, s := range cluster.GetServers() {
if s.GetConfig().Name != cluster.GetLeader() {
followerServer = s
}
}
c.Assert(followerServer, NotNil)

grpcPDClient := testutil.MustNewGrpcClient(c, followerServer.GetAddr())
clusterID := followerServer.GetClusterID()
req := &pdpb.TsoRequest{
Header: testutil.NewRequestHeader(clusterID),
Count: 1,
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
tsoClient, err := grpcPDClient.Tso(ctx)
c.Assert(err, IsNil)
defer tsoClient.CloseSend()

start := time.Now()
err = tsoClient.Send(req)
c.Assert(err, IsNil)
_, err = tsoClient.Recv()
c.Assert(err, NotNil)

// Requesting follower should fail fast, or the unavailable time will be
// too long.
c.Assert(time.Since(start), Less, time.Second)
}

func (s *testTsoSuite) testGetTimestamp(c *C, n int) *pdpb.Timestamp {
var err error
cluster, err := tests.NewTestCluster(s.ctx, 1)
Expand Down Expand Up @@ -210,6 +170,46 @@ func (s *testTsoSuite) TestTsoCount0(c *C) {
c.Assert(err, NotNil)
}

func (s *testTsoSuite) TestRequestFollower(c *C) {
cluster, err := tests.NewTestCluster(s.ctx, 2)
c.Assert(err, IsNil)
defer cluster.Destroy()

err = cluster.RunInitialServers()
c.Assert(err, IsNil)
cluster.WaitLeader()

var followerServer *tests.TestServer
for _, s := range cluster.GetServers() {
if s.GetConfig().Name != cluster.GetLeader() {
followerServer = s
}
}
c.Assert(followerServer, NotNil)

grpcPDClient := testutil.MustNewGrpcClient(c, followerServer.GetAddr())
clusterID := followerServer.GetClusterID()
req := &pdpb.TsoRequest{
Header: testutil.NewRequestHeader(clusterID),
Count: 1,
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
tsoClient, err := grpcPDClient.Tso(ctx)
c.Assert(err, IsNil)
defer tsoClient.CloseSend()

start := time.Now()
err = tsoClient.Send(req)
c.Assert(err, IsNil)
_, err = tsoClient.Recv()
c.Assert(err, NotNil)

// Requesting follower should fail fast, or the unavailable time will be
// too long.
c.Assert(time.Since(start), Less, time.Second)
}

var _ = Suite(&testTimeFallBackSuite{})

type testTimeFallBackSuite struct {
Expand Down

0 comments on commit 58f6601

Please sign in to comment.