From a109f9c9ee63b7ba19d2a83d38bf8725f350e93a Mon Sep 17 00:00:00 2001 From: Hu# Date: Mon, 15 Apr 2024 18:55:35 +0800 Subject: [PATCH 1/6] cluster: make TestStoreOverloadedWithReplace stable (#8068) ref tikv/pd#7969 Signed-off-by: husharp Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- server/cluster/cluster_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/cluster/cluster_test.go b/server/cluster/cluster_test.go index d01446ba143..ecd579d8881 100644 --- a/server/cluster/cluster_test.go +++ b/server/cluster/cluster_test.go @@ -3480,10 +3480,11 @@ func TestStoreOverloadedWithReplace(t *testing.T) { re.False(oc.AddOperator(op3)) ops, _ := lb.Schedule(tc, false /* dryRun */) re.Empty(ops) - // sleep 2 seconds to make sure that token is filled up - time.Sleep(2 * time.Second) - ops, _ = lb.Schedule(tc, false /* dryRun */) - re.NotEmpty(ops) + // make sure that token is filled up + testutil.Eventually(re, func() bool { + ops, _ = lb.Schedule(tc, false /* dryRun */) + return len(ops) != 0 + }) } func TestDownStoreLimit(t *testing.T) { From a767a5f5fd8c892d4e7b430d372fc18c1356791b Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Tue, 16 Apr 2024 10:25:35 +0800 Subject: [PATCH 2/6] *: make `TestEtcdScaleInAndOut` stable (#8067) close tikv/pd#6892 Signed-off-by: Ryan Leung Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- pkg/utils/etcdutil/testutil.go | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/pkg/utils/etcdutil/testutil.go b/pkg/utils/etcdutil/testutil.go index 3ea4d057645..d9464eeceeb 100644 --- a/pkg/utils/etcdutil/testutil.go +++ b/pkg/utils/etcdutil/testutil.go @@ -122,18 +122,27 @@ func MustAddEtcdMember(t *testing.T, cfg1 *embed.Config, client *clientv3.Client func checkMembers(re *require.Assertions, client *clientv3.Client, etcds []*embed.Etcd) { // Check the client can get the new member. - listResp, err := ListEtcdMembers(client.Ctx(), client) - re.NoError(err) - re.Len(listResp.Members, len(etcds)) - inList := func(m *etcdserverpb.Member) bool { - for _, etcd := range etcds { - if m.ID == uint64(etcd.Server.ID()) { - return true + testutil.Eventually(re, func() bool { + listResp, err := ListEtcdMembers(client.Ctx(), client) + if err != nil { + return false + } + if len(etcds) != len(listResp.Members) { + return false + } + inList := func(m *etcdserverpb.Member) bool { + for _, etcd := range etcds { + if m.ID == uint64(etcd.Server.ID()) { + return true + } } + return false } - return false - } - for _, m := range listResp.Members { - re.True(inList(m)) - } + for _, m := range listResp.Members { + if !inList(m) { + return false + } + } + return true + }) } From 2a4a7b76123e241ec98f79aac60b3769e756654c Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Tue, 16 Apr 2024 14:22:36 +0800 Subject: [PATCH 3/6] *: 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) From 41ff34bafec95b45968f1e74f14ba6cdcb62531d Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Tue, 16 Apr 2024 16:25:36 +0800 Subject: [PATCH 4/6] *: make `TestLogicalOverflow` stable (#8075) close tikv/pd#7017 Signed-off-by: Ryan Leung --- tests/server/tso/global_tso_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/server/tso/global_tso_test.go b/tests/server/tso/global_tso_test.go index f705bdf12b5..8dd98b1d628 100644 --- a/tests/server/tso/global_tso_test.go +++ b/tests/server/tso/global_tso_test.go @@ -165,7 +165,7 @@ func TestLogicalOverflow(t *testing.T) { re.NoError(err) if i == 1 { // the 2nd request may (but not must) overflow, as max logical interval is 262144 - re.Less(time.Since(begin), updateInterval+20*time.Millisecond) // additional 20ms for gRPC latency + re.Less(time.Since(begin), updateInterval+50*time.Millisecond) // additional 50ms for gRPC latency } } // the 3rd request must overflow From f5fd36f259a9078f083b35862b774a53179a774c Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Tue, 16 Apr 2024 16:36:05 +0800 Subject: [PATCH 5/6] schedule: enlarge waiting list cache size (#7559) ref tikv/pd#7963 Signed-off-by: Ryan Leung Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- pkg/schedule/checker/checker_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/schedule/checker/checker_controller.go b/pkg/schedule/checker/checker_controller.go index 355226cd2d8..cdc826a1dda 100644 --- a/pkg/schedule/checker/checker_controller.go +++ b/pkg/schedule/checker/checker_controller.go @@ -31,7 +31,7 @@ import ( ) // DefaultCacheSize is the default length of waiting list. -const DefaultCacheSize = 1000 +const DefaultCacheSize = 100000 var denyCheckersByLabelerCounter = labeler.LabelerEventCounter.WithLabelValues("checkers", "deny") From 22543a9cc3dea19ce19ea9d3354db0c2330c0e57 Mon Sep 17 00:00:00 2001 From: Hu# Date: Tue, 16 Apr 2024 16:46:35 +0800 Subject: [PATCH 6/6] tools/pd-ut: accelarate build by `compile-without-link` (#8069) ref tikv/pd#7969 Signed-off-by: husharp Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- tools/pd-ut/go-compile-without-link.sh | 20 ++++++++++++++++++++ tools/pd-ut/ut.go | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 tools/pd-ut/go-compile-without-link.sh diff --git a/tools/pd-ut/go-compile-without-link.sh b/tools/pd-ut/go-compile-without-link.sh new file mode 100755 index 00000000000..88e6282b076 --- /dev/null +++ b/tools/pd-ut/go-compile-without-link.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# See https://gist.github.com/howardjohn/c0f5d0bc293ef7d7fada533a2c9ffaf4 +# Usage: go test -exec=true -toolexec=go-compile-without-link -vet=off ./... +# Preferably as an alias like `alias go-test-compile='go test -exec=true -toolexec=go-compile-without-link -vet=off'` +# This will compile all tests, but not link them (which is the least cacheable part) + +if [[ "${2}" == "-V=full" ]]; then + "$@" + exit 0 +fi +case "$(basename ${1})" in + link) + # Output a dummy file + touch "${3}" + ;; + # We could skip vet as well, but it can be done with -vet=off if desired + *) + "$@" +esac diff --git a/tools/pd-ut/ut.go b/tools/pd-ut/ut.go index 69a83f007b6..7fc96ee11cf 100644 --- a/tools/pd-ut/ut.go +++ b/tools/pd-ut/ut.go @@ -589,8 +589,28 @@ func skipDIR(pkg string) bool { return false } +func generateBuildCache() error { + // cd cmd/pd-server && go test -tags=tso_function_test,deadlock -exec-=true -vet=off -toolexec=go-compile-without-link + cmd := exec.Command("go", "test", "-exec=true", "-vet", "off", "--tags=tso_function_test,deadlock") + goCompileWithoutLink := fmt.Sprintf("-toolexec=%s/tools/pd-ut/go-compile-without-link.sh", workDir) + cmd.Args = append(cmd.Args, goCompileWithoutLink) + cmd.Dir = fmt.Sprintf("%s/cmd/pd-server", workDir) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + return withTrace(err) + } + return nil +} + // buildTestBinaryMulti is much faster than build the test packages one by one. func buildTestBinaryMulti(pkgs []string) error { + // staged build, generate the build cache for all the tests first, then generate the test binary. + // This way is faster than generating test binaries directly, because the cache can be used. + if err := generateBuildCache(); err != nil { + return withTrace(err) + } + // go test --exec=xprog --tags=tso_function_test,deadlock -vet=off --count=0 $(pkgs) xprogPath := path.Join(workDir, "bin/xprog") packages := make([]string, 0, len(pkgs))