From 2a4a7b76123e241ec98f79aac60b3769e756654c Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Tue, 16 Apr 2024 14:22:36 +0800 Subject: [PATCH] *: make `TestEtcdWithHangLeaderEnableCheck` stable (#8072) close tikv/pd#7292 Signed-off-by: Ryan Leung --- pkg/utils/etcdutil/etcdutil_test.go | 6 +++--- tests/integrations/mcs/scheduling/api_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/utils/etcdutil/etcdutil_test.go b/pkg/utils/etcdutil/etcdutil_test.go index 6ddeafe4573..4c1e20fa73c 100644 --- a/pkg/utils/etcdutil/etcdutil_test.go +++ b/pkg/utils/etcdutil/etcdutil_test.go @@ -300,11 +300,10 @@ func checkEtcdWithHangLeader(t *testing.T) error { etcd2 := MustAddEtcdMember(t, &cfg1, client1) defer etcd2.Close() checkMembers(re, client1, []*embed.Etcd{etcd1, etcd2}) - time.Sleep(1 * time.Second) // wait for etcd client sync endpoints // Hang the etcd1 and wait for the client to connect to etcd2. enableDiscard.Store(true) - time.Sleep(time.Second) + time.Sleep(3 * time.Second) _, err = EtcdKVGet(client1, "test/key1") return err } @@ -366,7 +365,8 @@ func ioCopy(ctx context.Context, dst io.Writer, src io.Reader, enableDiscard *at return nil default: if enableDiscard.Load() { - io.Copy(io.Discard, src) + _, err := io.Copy(io.Discard, src) + return err } readNum, errRead := src.Read(buffer) if readNum > 0 { diff --git a/tests/integrations/mcs/scheduling/api_test.go b/tests/integrations/mcs/scheduling/api_test.go index be51123532d..f615e879e40 100644 --- a/tests/integrations/mcs/scheduling/api_test.go +++ b/tests/integrations/mcs/scheduling/api_test.go @@ -647,11 +647,11 @@ func (suite *apiTestSuite) checkStores(cluster *tests.TestCluster) { Version: "2.0.0", }, } + // prevent the offline store from changing to tombstone + tests.MustPutRegion(re, cluster, 3, 6, []byte("a"), []byte("b")) for _, store := range stores { tests.MustPutStore(re, cluster, store) } - // prevent the offline store from changing to tombstone - tests.MustPutRegion(re, cluster, 3, 6, []byte("a"), []byte("b")) // Test /stores apiServerAddr := cluster.GetLeaderServer().GetAddr() urlPrefix := fmt.Sprintf("%s/pd/api/v1/stores", apiServerAddr)