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 912bd66
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 42 deletions.
2 changes: 0 additions & 2 deletions server/tso/tso.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package tso

import (
"path"
"sync"
"sync/atomic"
"time"
"unsafe"
Expand Down Expand Up @@ -46,7 +45,6 @@ type TimestampOracle struct {
ts unsafe.Pointer
lastSavedTime atomic.Value

mu sync.RWMutex
lease *member.LeaderLease

rootPath string
Expand Down
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 912bd66

Please sign in to comment.