Skip to content

Commit

Permalink
refine test
Browse files Browse the repository at this point in the history
Signed-off-by: crazycs520 <[email protected]>
  • Loading branch information
crazycs520 committed Mar 13, 2024
1 parent dc217c3 commit c4546cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions internal/client/client_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ func (a *batchConn) getClientAndSend() {
time.Sleep(time.Duration(timeout * int(time.Millisecond)))
}
}

// Choose a connection by round-robbin.
var (
cli *batchCommandsClient
Expand Down
11 changes: 8 additions & 3 deletions internal/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import (
"github.com/tikv/client-go/v2/internal/client/mockserver"
"github.com/tikv/client-go/v2/internal/logutil"
"github.com/tikv/client-go/v2/tikvrpc"
"github.com/tikv/client-go/v2/util/israce"
"go.uber.org/zap"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/metadata"
Expand Down Expand Up @@ -881,6 +882,10 @@ func TestBatchClientReceiveHealthFeedback(t *testing.T) {
}

func TestConcurrencyRequestLimitWithEnableForwarding(t *testing.T) {
if israce.RaceEnabled {
// The test will failed when run with race. see https://github.com/tikv/client-go/issues/1222
t.Skip()
}
store1, port1 := mockserver.StartMockTikvService()
require.True(t, port1 > 0)
require.True(t, store1.IsRunning())
Expand All @@ -901,7 +906,7 @@ func TestConcurrencyRequestLimitWithEnableForwarding(t *testing.T) {
wg := sync.WaitGroup{}
wg.Add(1)
done := int64(0)
concurrency := 200
concurrency := 500
go func() {
defer wg.Done()
for {
Expand All @@ -922,7 +927,7 @@ func TestConcurrencyRequestLimitWithEnableForwarding(t *testing.T) {
atomic.AddInt64(&done, 1)
wg.Done()
}()
for i := 0; i < 2000; i++ {
for i := 0; i < 5000; i++ {
req := &tikvpb.BatchCommandsRequest_Request{Cmd: &tikvpb.BatchCommandsRequest_Request_Coprocessor{Coprocessor: &coprocessor.Request{}}}
forwardedHost := ""
if i%2 != 0 {
Expand All @@ -947,6 +952,6 @@ func TestConcurrencyRequestLimitWithEnableForwarding(t *testing.T) {
require.Equal(t, int64(9223372036854775807), cli.maxConcurrencyRequestLimit.Load())
require.True(t, cli.available() > 0, fmt.Sprintf("sent: %d", cli.sent.Load()))
// TODO(crazycs520): fix following assertion. cli.sent may be less than 0 in some cases when enable-forwarding is true.
//require.True(t, cli.sent.Load() >= 0, fmt.Sprintf("sent: %d", cli.sent.Load()))
require.True(t, cli.sent.Load() >= 0, fmt.Sprintf("sent: %d", cli.sent.Load()))
}
}

0 comments on commit c4546cb

Please sign in to comment.