From 6f72ceaf386788a87c7df0e3a83e745a1b1bf9a3 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Mon, 17 Jul 2023 11:18:45 +0800 Subject: [PATCH] *: fix `TestGetTSOImmediately` (#6811) close tikv/pd#6795 Signed-off-by: Ryan Leung --- .../mcs/tso/keyspace_group_manager_test.go | 11 +++++++++-- tests/server/apiv2/handlers/testutil.go | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/integrations/mcs/tso/keyspace_group_manager_test.go b/tests/integrations/mcs/tso/keyspace_group_manager_test.go index ec9322cd1ecc..4af10fa71077 100644 --- a/tests/integrations/mcs/tso/keyspace_group_manager_test.go +++ b/tests/integrations/mcs/tso/keyspace_group_manager_test.go @@ -17,6 +17,7 @@ package tso import ( "context" "math/rand" + "net/http" "strings" "sync" "testing" @@ -357,13 +358,19 @@ func waitFinishSplit( splitSourceKeyspaces, splitTargetKeyspaces []uint32, ) { testutil.Eventually(re, func() bool { - kg := handlersutil.MustLoadKeyspaceGroupByID(re, server, splitTargetID) + kg, code := handlersutil.TryLoadKeyspaceGroupByID(re, server, splitTargetID) + if code != http.StatusOK { + return false + } re.Equal(splitTargetID, kg.ID) re.Equal(splitTargetKeyspaces, kg.Keyspaces) return !kg.IsSplitTarget() }) testutil.Eventually(re, func() bool { - kg := handlersutil.MustLoadKeyspaceGroupByID(re, server, splitSourceID) + kg, code := handlersutil.TryLoadKeyspaceGroupByID(re, server, splitSourceID) + if code != http.StatusOK { + return false + } re.Equal(splitSourceID, kg.ID) re.Equal(splitSourceKeyspaces, kg.Keyspaces) return !kg.IsSplitSource() diff --git a/tests/server/apiv2/handlers/testutil.go b/tests/server/apiv2/handlers/testutil.go index 900cd84b8293..aca29ebeb52a 100644 --- a/tests/server/apiv2/handlers/testutil.go +++ b/tests/server/apiv2/handlers/testutil.go @@ -168,6 +168,13 @@ func tryCreateKeyspaceGroup(re *require.Assertions, server *tests.TestServer, re // MustLoadKeyspaceGroupByID loads the keyspace group by ID with HTTP API. func MustLoadKeyspaceGroupByID(re *require.Assertions, server *tests.TestServer, id uint32) *endpoint.KeyspaceGroup { + kg, code := TryLoadKeyspaceGroupByID(re, server, id) + re.Equal(http.StatusOK, code) + return kg +} + +// TryLoadKeyspaceGroupByID loads the keyspace group by ID with HTTP API. +func TryLoadKeyspaceGroupByID(re *require.Assertions, server *tests.TestServer, id uint32) (*endpoint.KeyspaceGroup, int) { httpReq, err := http.NewRequest(http.MethodGet, server.GetAddr()+keyspaceGroupsPrefix+fmt.Sprintf("/%d", id), nil) re.NoError(err) resp, err := dialClient.Do(httpReq) @@ -175,10 +182,13 @@ func MustLoadKeyspaceGroupByID(re *require.Assertions, server *tests.TestServer, defer resp.Body.Close() data, err := io.ReadAll(resp.Body) re.NoError(err) - re.Equal(http.StatusOK, resp.StatusCode, string(data)) + if resp.StatusCode != http.StatusOK { + return nil, resp.StatusCode + } + var kg endpoint.KeyspaceGroup re.NoError(json.Unmarshal(data, &kg)) - return &kg + return &kg, resp.StatusCode } // MustCreateKeyspaceGroup creates a keyspace group with HTTP API.