Skip to content

Commit

Permalink
executor,store/mockstore: add a test to mock get tso fail (pingcap#8566)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and iamzhoug37 committed Dec 13, 2018
1 parent ce88a67 commit e2d9ef1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3360,3 +3360,15 @@ func (s *testSuite) TestDoSubquery(c *C) {
c.Assert(err, IsNil, Commentf("err %v", err))
c.Assert(r, IsNil, Commentf("result of Do not empty"))
}

func (s *testSuite) TestTSOFail(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec(`use test`)
tk.MustExec(`drop table if exists t`)
tk.MustExec(`create table t(a int)`)

gofail.Enable("github.com/pingcap/tidb/store/mockstore/mocktikv/mockGetTSFail", `return(true)`)
defer gofail.Disable("github.com/pingcap/tidb/store/mockstore/mocktikv/mockGetTSFail")
_, err := tk.Exec(`select * from t`)
c.Assert(err, NotNil)
}
8 changes: 7 additions & 1 deletion store/mockstore/mocktikv/pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"sync"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/pd/client"
"golang.org/x/net/context"
Expand Down Expand Up @@ -46,6 +47,11 @@ func (c *pdClient) GetClusterID(ctx context.Context) uint64 {
}

func (c *pdClient) GetTS(context.Context) (int64, int64, error) {
// gofail: var mockGetTSFail bool
// if mockGetTSFail {
// return 0, 0, errors.New("mock get timestamp fail")
// }

tsMu.Lock()
defer tsMu.Unlock()

Expand Down Expand Up @@ -97,7 +103,7 @@ func (c *pdClient) GetStore(ctx context.Context, storeID uint64) (*metapb.Store,
}

func (c *pdClient) GetAllStores(ctx context.Context) ([]*metapb.Store, error) {
panic("unimplemented")
panic(errors.New("unimplemented"))
}

func (c *pdClient) UpdateGCSafePoint(ctx context.Context, safePoint uint64) (uint64, error) {
Expand Down

0 comments on commit e2d9ef1

Please sign in to comment.