Skip to content

Commit

Permalink
planner, executor: fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
caohe committed Mar 2, 2019
1 parent 68c6e5b commit 48c7a31
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 3 additions & 4 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"sort"
"strconv"
"strings"
"testing"
"time"

"github.com/coreos/etcd/integration"
Expand Down Expand Up @@ -50,6 +49,8 @@ import (
"github.com/pingcap/tidb/util/sqlexec"
)

// TestEtcdCluster is a mock etcd cluster used for test `show pump/drainer status`
var TestEtcdCluster *integration.ClusterV3
var etcdDialTimeout = 5 * time.Second

const binlogTest = "/tmp/tidb"
Expand Down Expand Up @@ -1036,9 +1037,7 @@ func (e *ShowExec) fetchShowPumpOrDrainerStatus(kind string) error {
// createRegistry returns an ectd registry
func createRegistry(urls string) (*node.EtcdRegistry, error) {
if urls == binlogTest {
var t *testing.T
testEtcdCluster := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
etcdclient := etcd.NewClient(testEtcdCluster.RandClient(), node.DefaultRootPath)
etcdclient := etcd.NewClient(TestEtcdCluster.RandClient(), node.DefaultRootPath)
return node.NewEtcdRegistry(etcdclient, time.Duration(5)*time.Second), nil
}
ectdEndpoints, err := utils.ParseHostPortAddr(urls)
Expand Down
8 changes: 3 additions & 5 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,11 @@ func (s *testSuite2) TestShowEscape(c *C) {

func (s *testSuite2) TestShowPumpOrDrainerStatus(c *C) {
var t *testing.T
testEtcdCluster := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
executor.TestEtcdCluster = integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})

etcdclient := etcd.NewClient(testEtcdCluster.RandClient(), node.DefaultRootPath)
etcdclient := etcd.NewClient(executor.TestEtcdCluster.RandClient(), node.DefaultRootPath)
r := node.NewEtcdRegistry(etcdclient, time.Duration(5)*time.Second)
defer func() {
testEtcdCluster.Terminate(t)
r.Close()
}()

Expand All @@ -433,6 +432,5 @@ func (s *testSuite2) TestShowPumpOrDrainerStatus(c *C) {
c.Assert(err, IsNil)

tk := testkit.NewTestKit(c, s.store)
result := tk.MustQuery("SHOW PUMP STATUS")
c.Check(result.Rows(), HasLen, 0)
tk.MustQuery("SHOW PUMP STATUS").Check([][]interface{}{{"pump1", "127.0.0.1:8249", "online", "0", "1970-01-01 08:00:00"}})
}

0 comments on commit 48c7a31

Please sign in to comment.