From 0c8614a80bd0db4e12272766961b00799147cbfd Mon Sep 17 00:00:00 2001 From: Yexiang Zhang Date: Tue, 30 Nov 2021 13:01:52 +0800 Subject: [PATCH] executor: fix unstable test of topsql (#30257) --- executor/executor_test.go | 54 ++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/executor/executor_test.go b/executor/executor_test.go index 0c77367e007a2..c821901d5a18d 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -8782,47 +8782,46 @@ func (s *testResourceTagSuite) TestResourceGroupTag(c *C) { cases := []struct { sql string - tagLabels []tipb.ResourceGroupTagLabel + tagLabels map[tipb.ResourceGroupTagLabel]struct{} ignore bool }{ { sql: "insert into t values(1,1),(2,2),(3,3)", - tagLabels: []tipb.ResourceGroupTagLabel{ - tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex, - tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex, + tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{ + tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {}, }, }, { sql: "select * from t use index (idx) where a=1", - tagLabels: []tipb.ResourceGroupTagLabel{ - tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex, - tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow, + tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{ + tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow: {}, + tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {}, }, }, { sql: "select * from t use index (idx) where a in (1,2,3)", - tagLabels: []tipb.ResourceGroupTagLabel{ - tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex, - tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow, + tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{ + tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow: {}, + tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {}, }, }, { sql: "select * from t use index (idx) where a>1", - tagLabels: []tipb.ResourceGroupTagLabel{ - tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex, - tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow, + tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{ + tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow: {}, + tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {}, }, }, { sql: "select * from t where b>1", - tagLabels: []tipb.ResourceGroupTagLabel{ - tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow, + tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{ + tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow: {}, }, }, { sql: "select a from t use index (idx) where a>1", - tagLabels: []tipb.ResourceGroupTagLabel{ - tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex, + tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{ + tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {}, }, }, { @@ -8831,9 +8830,9 @@ func (s *testResourceTagSuite) TestResourceGroupTag(c *C) { }, { sql: "insert into t values(4,4)", - tagLabels: []tipb.ResourceGroupTagLabel{ - tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex, - tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow, + tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{ + tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow: {}, + tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {}, }, }, { @@ -8842,15 +8841,14 @@ func (s *testResourceTagSuite) TestResourceGroupTag(c *C) { }, { sql: "update t set a=5,b=5 where a=5", - tagLabels: []tipb.ResourceGroupTagLabel{ - tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex, + tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{ + tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {}, }, }, { sql: "replace into t values(6,6)", - tagLabels: []tipb.ResourceGroupTagLabel{ - tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex, - tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex, + tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{ + tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {}, }, }, } @@ -8874,10 +8872,8 @@ func (s *testResourceTagSuite) TestResourceGroupTag(c *C) { } c.Assert(sqlDigest.String(), Equals, expectSQLDigest.String(), commentf) c.Assert(planDigest.String(), Equals, expectPlanDigest.String()) - if len(ca.tagLabels) > 0 { - c.Assert(tagLabel, Equals, ca.tagLabels[0]) - ca.tagLabels = ca.tagLabels[1:] // next label - } + _, ok := ca.tagLabels[tagLabel] + c.Assert(ok, Equals, true) checkCnt++ }