Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
Quality reinforcement (5): fix unstable test cases (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
csuzhangxc committed Oct 13, 2020
1 parent 9ae67af commit 97ae58b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions dumpling/dumpling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/dm/pkg/log"
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb-tools/pkg/filter"

. "github.com/pingcap/check"
)
Expand Down Expand Up @@ -68,6 +69,9 @@ func (d *testDumplingSuite) SetUpSuite(c *C) {
LoaderConfig: config.LoaderConfig{
Dir: dir,
},
BAList: &filter.Rules{
DoDBs: []string{"information_schema"},
},
}
c.Assert(log.InitLogger(&log.Config{}), IsNil)
}
Expand Down
20 changes: 12 additions & 8 deletions pkg/election/election_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (t *testElectionSuite) TearDownTest(c *C) {

func testElection2After1(t *testElectionSuite, c *C, normalExit bool) {
var (
timeout = 3 * time.Second
sessionTTL = 60
key = "unit-test/election-2-after-1"
ID1 = "member1"
Expand Down Expand Up @@ -120,7 +121,7 @@ func testElection2After1(t *testElectionSuite, c *C, normalExit bool) {
select {
case leader := <-e1.LeaderNotify():
c.Assert(leader.ID, Equals, ID1)
case <-time.After(3 * time.Second):
case <-time.After(timeout):
c.Fatal("leader campaign timeout")
}
c.Assert(e1.IsLeader(), IsTrue)
Expand All @@ -141,7 +142,7 @@ func testElection2After1(t *testElectionSuite, c *C, normalExit bool) {
select {
case leader := <-e2.leaderCh:
c.Assert(leader.ID, Equals, ID1)
case <-time.After(time.Second):
case <-time.After(timeout):
c.Fatal("leader campaign timeout")
}
// but the leader should still be e1
Expand Down Expand Up @@ -171,7 +172,7 @@ func testElection2After1(t *testElectionSuite, c *C, normalExit bool) {
select {
case leader := <-e2.LeaderNotify():
c.Assert(leader.ID, Equals, ID2)
case <-time.After(3 * time.Second):
case <-time.After(timeout):
c.Fatal("leader campaign timeout")
}
c.Assert(e2.IsLeader(), IsTrue)
Expand All @@ -196,7 +197,7 @@ func testElection2After1(t *testElectionSuite, c *C, normalExit bool) {
c.Assert(terror.ErrElectionCampaignFail.Equal(err2), IsTrue)
// the old session is done, but we can't create a new one.
c.Assert(err2, ErrorMatches, ".*fail to campaign leader: create a new session.*")
case <-time.After(time.Second):
case <-time.After(timeout):
c.Fatal("do not receive error for e2")
}
}()
Expand All @@ -218,6 +219,7 @@ func (t *testElectionSuite) TestElection2After1(c *C) {

func (t *testElectionSuite) TestElectionAlways1(c *C) {
var (
timeout = 3 * time.Second
sessionTTL = 60
key = "unit-test/election-always-1"
ID1 = "member1"
Expand All @@ -239,7 +241,7 @@ func (t *testElectionSuite) TestElectionAlways1(c *C) {
select {
case leader := <-e1.LeaderNotify():
c.Assert(leader.ID, Equals, ID1)
case <-time.After(3 * time.Second):
case <-time.After(timeout):
c.Fatal("leader campaign timeout")
}
c.Assert(e1.IsLeader(), IsTrue)
Expand Down Expand Up @@ -270,7 +272,7 @@ func (t *testElectionSuite) TestElectionAlways1(c *C) {
select {
case err2 := <-e2.ErrorNotify():
c.Fatalf("cancel the campaign should not get an error, %v", err2)
case <-time.After(time.Second): // wait 1s
case <-time.After(timeout): // wait 3s
}
}()
cancel2()
Expand All @@ -288,6 +290,7 @@ func (t *testElectionSuite) TestElectionAlways1(c *C) {

func (t *testElectionSuite) TestElectionEvictLeader(c *C) {
var (
timeout = 3 * time.Second
sessionTTL = 60
key = "unit-test/election-evict-leader"
ID1 = "member1"
Expand All @@ -309,7 +312,7 @@ func (t *testElectionSuite) TestElectionEvictLeader(c *C) {
select {
case leader := <-e1.LeaderNotify():
c.Assert(leader.ID, Equals, ID1)
case <-time.After(3 * time.Second):
case <-time.After(timeout):
c.Fatal("leader campaign timeout")
}
c.Assert(e1.IsLeader(), IsTrue)
Expand Down Expand Up @@ -354,6 +357,7 @@ func (t *testElectionSuite) TestElectionEvictLeader(c *C) {

func (t *testElectionSuite) TestElectionDeleteKey(c *C) {
var (
timeout = 3 * time.Second
sessionTTL = 60
key = "unit-test/election-delete-key"
ID = "member"
Expand All @@ -373,7 +377,7 @@ func (t *testElectionSuite) TestElectionDeleteKey(c *C) {
select {
case leader := <-e.LeaderNotify():
c.Assert(leader.ID, Equals, ID)
case <-time.After(3 * time.Second):
case <-time.After(timeout):
c.Fatal("leader campaign timeout")
}
c.Assert(e.IsLeader(), IsTrue)
Expand Down
4 changes: 3 additions & 1 deletion tests/http_apis/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ function run() {
echo "kill dm-worker1"
ps aux | grep dm-worker1 |awk '{print $2}'|xargs kill || true
check_port_offline $WORKER1_PORT 20
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"list-member --worker --name=worker1" \
"\"stage\": \"offline\"" 1
curl -X DELETE 127.0.0.1:$MASTER_PORT/apis/${API_VERSION}/members/worker/worker1 > $WORK_DIR/offline-worker.log
check_log_contains $WORK_DIR/offline-worker.log "\"result\": true" 1

echo "check data"
check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
}
Expand Down

0 comments on commit 97ae58b

Please sign in to comment.