Skip to content

Commit

Permalink
fix lint issue
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Dec 27, 2024
1 parent 4d8009d commit 5706d89
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 31 deletions.
5 changes: 2 additions & 3 deletions pkg/cgroup/cgroup_cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package cgroup

import (
"fmt"
"regexp"
"runtime"
"strconv"
Expand Down Expand Up @@ -45,10 +44,10 @@ func checkKernelVersionNewerThan(re *require.Assertions, t *testing.T, major, mi
t.Log("kernel release string:", releaseStr)
versionInfoRE := regexp.MustCompile(`[0-9]+\.[0-9]+\.[0-9]+`)
kernelVersion := versionInfoRE.FindAllString(releaseStr, 1)
re.Len(kernelVersion, 1, fmt.Sprintf("release str is %s", releaseStr))
re.Lenf(kernelVersion, 1, "release str is %s", releaseStr)
kernelVersionPartRE := regexp.MustCompile(`[0-9]+`)
kernelVersionParts := kernelVersionPartRE.FindAllString(kernelVersion[0], -1)
re.Len(kernelVersionParts, 3, fmt.Sprintf("kernel version str is %s", kernelVersion[0]))
re.Lenf(kernelVersionParts, 3, "kernel version str is %s", kernelVersion[0])
t.Logf("parsed kernel version parts: major %s, minor %s, patch %s",
kernelVersionParts[0], kernelVersionParts[1], kernelVersionParts[2])
mustConvInt := func(s string) int {
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,10 +985,10 @@ func TestUpdateRegionEquivalence(t *testing.T) {
checkRegions(re, regionsNew)

for _, r := range regionsOld.GetRegions() {
re.Equal(int32(2), r.GetRef(), fmt.Sprintf("inconsistent region %d", r.GetID()))
re.Equalf(int32(2), r.GetRef(), "inconsistent region %d", r.GetID())
}
for _, r := range regionsNew.GetRegions() {
re.Equal(int32(2), r.GetRef(), fmt.Sprintf("inconsistent region %d", r.GetID()))
re.Equalf(int32(2), r.GetRef(), "inconsistent region %d", r.GetID())
}

for i := 1; i <= storeNums; i++ {
Expand Down
5 changes: 2 additions & 3 deletions pkg/mcs/resourcemanager/server/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package server

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -43,8 +42,8 @@ func TestMaxPerSecCostTracker(t *testing.T) {
// Check the max values at the end of each flushPeriod
if (i+1)%20 == 0 {
period := i / 20
re.Equal(tracker.maxPerSecRRU, expectedMaxRU[period], fmt.Sprintf("maxPerSecRRU in period %d is incorrect", period+1))
re.Equal(tracker.maxPerSecWRU, expectedMaxRU[period], fmt.Sprintf("maxPerSecWRU in period %d is incorrect", period+1))
re.Equalf(tracker.maxPerSecRRU, expectedMaxRU[period], "maxPerSecRRU in period %d is incorrect", period+1)
re.Equalf(tracker.maxPerSecWRU, expectedMaxRU[period], "maxPerSecWRU in period %d is incorrect", period+1)
re.Equal(tracker.rruSum, expectedSum[period])
re.Equal(tracker.rruSum, expectedSum[period])
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/mcs/resourcemanager/server/token_buckets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package server

import (
"fmt"
"math"
"testing"
"time"
Expand Down Expand Up @@ -182,9 +181,9 @@ func TestGroupTokenBucketRequestLoop(t *testing.T) {
currentTime := initialTime
for i, tc := range testCases {
tb, trickle := gtb.request(currentTime, tc.requestTokens, uint64(targetPeriod)/uint64(time.Millisecond), clientUniqueID)
re.Equal(tc.globalBucketTokensAfterAssign, gtb.GetTokenBucket().Tokens, fmt.Sprintf("Test case %d failed: expected bucket tokens %f, got %f", i, tc.globalBucketTokensAfterAssign, gtb.GetTokenBucket().Tokens))
re.LessOrEqual(math.Abs(tb.Tokens-tc.assignedTokens), 1e-7, fmt.Sprintf("Test case %d failed: expected tokens %f, got %f", i, tc.assignedTokens, tb.Tokens))
re.Equal(tc.expectedTrickleMs, trickle, fmt.Sprintf("Test case %d failed: expected trickle %d, got %d", i, tc.expectedTrickleMs, trickle))
re.Equalf(tc.globalBucketTokensAfterAssign, gtb.GetTokenBucket().Tokens, "Test case %d failed: expected bucket tokens %f, got %f", i, tc.globalBucketTokensAfterAssign, gtb.GetTokenBucket().Tokens)
re.LessOrEqualf(math.Abs(tb.Tokens-tc.assignedTokens), 1e-7, "Test case %d failed: expected tokens %f, got %f", i, tc.assignedTokens, tb.Tokens)
re.Equalf(tc.expectedTrickleMs, trickle, "Test case %d failed: expected trickle %d, got %d", i, tc.expectedTrickleMs, trickle)
currentTime = currentTime.Add(timeIncrement)
}
}
6 changes: 3 additions & 3 deletions pkg/tso/keyspace_group_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ func collectAssignedKeyspaceGroupIDs(re *require.Assertions, kgm *KeyspaceGroupM
for i := range kgm.kgs {
kg := kgm.kgs[i]
if kg == nil {
re.Nil(kgm.ams[i], fmt.Sprintf("ksg is nil but am is not nil for id %d", i))
re.Nilf(kgm.ams[i], "ksg is nil but am is not nil for id %d", i)
} else {
am := kgm.ams[i]
if am != nil {
Expand Down Expand Up @@ -976,8 +976,8 @@ func (suite *keyspaceGroupManagerTestSuite) TestUpdateKeyspaceGroupMembership()
func verifyLocalKeyspaceLookupTable(
re *require.Assertions, keyspaceLookupTable map[uint32]struct{}, newKeyspaces []uint32,
) {
re.Equal(len(newKeyspaces), len(keyspaceLookupTable),
fmt.Sprintf("%v %v", newKeyspaces, keyspaceLookupTable))
re.Equalf(len(newKeyspaces), len(keyspaceLookupTable),
"%v %v", newKeyspaces, keyspaceLookupTable)
for _, keyspace := range newKeyspaces {
_, ok := keyspaceLookupTable[keyspace]
re.True(ok)
Expand Down
9 changes: 4 additions & 5 deletions pkg/window/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package window

import (
"fmt"
"math"
"testing"
"time"
Expand Down Expand Up @@ -79,11 +78,11 @@ func TestRollingPolicy_Add(t *testing.T) {
asExpected = false
}
if asExpected {
re.Less(math.Abs(point-policy.window.buckets[offset].Points[0]), 1e-6,
fmt.Sprintf("error, time since last append: %vms, last offset: %v", totalTS, lastOffset))
re.Lessf(math.Abs(point-policy.window.buckets[offset].Points[0]), 1e-6,
"error, time since last append: %vms, last offset: %v", totalTS, lastOffset)
}
re.Less(math.Abs(points[i]-policy.window.buckets[offset].Points[0]), 1e-6,
fmt.Sprintf("error, time since last append: %vms, last offset: %v", totalTS, lastOffset))
re.Lessf(math.Abs(points[i]-policy.window.buckets[offset].Points[0]), 1e-6,
"error, time since last append: %vms, last offset: %v", totalTS, lastOffset)
lastOffset = offset
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ func (suite *resourceManagerClientTestSuite) TestBasicResourceGroupCURD() {
re.NoError(err)
re.Contains(dresp, "Success!")
_, err = cli.GetResourceGroup(suite.ctx, g.Name)
re.EqualError(err, fmt.Sprintf("get resource group %v failed, rpc error: code = Unknown desc = resource group not found", g.Name))
re.EqualErrorf(err, "get resource group %v failed, rpc error: code = Unknown desc = resource group not found", g.Name)
}

// to test the deletion of persistence
Expand Down
3 changes: 1 addition & 2 deletions tests/integrations/realcluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,5 @@ func waitTiupReady(t *testing.T, tag string) {
zap.String("tag", tag), zap.Error(err))
time.Sleep(time.Duration(interval) * time.Second)
}
// this check can trigger the cleanup function
require.NotZero(t, 1, "TiUP is not ready", "tag: %s", tag)
require.FailNowf(t, "TiUP is not ready after retry: %s", tag)
}
4 changes: 2 additions & 2 deletions tests/server/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ func (suite *middlewareTestSuite) TestRequestInfoMiddleware() {
re.Equal(http.StatusOK, resp.StatusCode)

re.Equal("Profile", resp.Header.Get("service-label"))
re.Equal("{\"seconds\":[\"1\"]}", resp.Header.Get("url-param"))
re.Equal("{\"testkey\":\"testvalue\"}", resp.Header.Get("body-param"))
re.JSONEq("{\"seconds\":[\"1\"]}", resp.Header.Get("url-param"))
re.JSONEq("{\"testkey\":\"testvalue\"}", resp.Header.Get("body-param"))
re.Equal("HTTP/1.1/POST:/pd/api/v1/debug/pprof/profile", resp.Header.Get("method"))
re.Equal("anonymous", resp.Header.Get("caller-id"))
re.Equal("127.0.0.1", resp.Header.Get("ip"))
Expand Down
12 changes: 6 additions & 6 deletions tools/pd-ctl/tests/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,18 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) {
case "grant-leader-scheduler":
return "paused", !storeInfo.AllowLeaderTransferOut()
default:
re.Fail(fmt.Sprintf("unknown scheduler %s", schedulerName))
re.Failf("unknown scheduler %s", schedulerName)
return "", false
}
}()
if slice.AnyOf(changedStores, func(i int) bool {
return store.GetId() == changedStores[i]
}) {
re.True(isStorePaused,
fmt.Sprintf("store %d should be %s with %s", store.GetId(), status, schedulerName))
re.Truef(isStorePaused,
"store %d should be %s with %s", store.GetId(), status, schedulerName)
} else {
re.False(isStorePaused,
fmt.Sprintf("store %d should not be %s with %s", store.GetId(), status, schedulerName))
re.Falsef(isStorePaused,
"store %d should not be %s with %s", store.GetId(), status, schedulerName)
}
if sche := cluster.GetSchedulingPrimaryServer(); sche != nil {
switch schedulerName {
Expand All @@ -206,7 +206,7 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) {
case "grant-leader-scheduler":
re.Equal(isStorePaused, !sche.GetCluster().GetStore(store.GetId()).AllowLeaderTransferOut())
default:
re.Fail(fmt.Sprintf("unknown scheduler %s", schedulerName))
re.Failf("unknown scheduler %s", schedulerName)
}
}
}
Expand Down

0 comments on commit 5706d89

Please sign in to comment.