Skip to content

Commit

Permalink
test: fix data race in the test mocker (#34796)
Browse files Browse the repository at this point in the history
close #34795
  • Loading branch information
breezewish committed May 19, 2022
1 parent 2cf1354 commit 37ba54e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions executor/compact_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"regexp"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -694,15 +695,19 @@ type compactClientHandler struct {

type compactRequestMocker struct {
tikv.Client
handlers []*compactClientHandler
t *testing.T
handlers []*compactClientHandler

mu sync.Mutex
receivedRequestsOfAddr map[string]int
t *testing.T
}

func (client *compactRequestMocker) SendRequest(ctx context.Context, addr string, req *tikvrpc.Request, timeout time.Duration) (*tikvrpc.Response, error) {
if req.Type == tikvrpc.CmdCompact {
client.mu.Lock()
client.receivedRequestsOfAddr[addr]++
handlerKey := fmt.Sprintf("%s/#%d", addr, client.receivedRequestsOfAddr[addr])
client.mu.Unlock()
for _, handler := range client.handlers {
if handler.matcher.MatchString(handlerKey) {
handler.hit.Store(true)
Expand Down

0 comments on commit 37ba54e

Please sign in to comment.