Skip to content

Commit

Permalink
Enable failures in tools/e2e_test_race.sh and fix races (#13654)
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui authored Sep 18, 2023
1 parent 225e838 commit d0847c2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
6 changes: 6 additions & 0 deletions go/vt/vttablet/endtoend/framework/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package framework
import (
"context"
"errors"
"sync"
"time"

"vitess.io/vitess/go/sqltypes"
Expand All @@ -38,6 +39,7 @@ type QueryClient struct {
target *querypb.Target
server *tabletserver.TabletServer
transactionID int64
reservedIDMu sync.Mutex
reservedID int64
sessionStateChanges string
}
Expand Down Expand Up @@ -112,6 +114,8 @@ func (client *QueryClient) Commit() error {
func (client *QueryClient) Rollback() error {
defer func() { client.transactionID = 0 }()
rID, err := client.server.Rollback(client.ctx, client.target, client.transactionID)
client.reservedIDMu.Lock()
defer client.reservedIDMu.Unlock()
client.reservedID = rID
if err != nil {
return err
Expand Down Expand Up @@ -291,6 +295,8 @@ func (client *QueryClient) MessageAck(name string, ids []string) (int64, error)

// ReserveExecute performs a ReserveExecute.
func (client *QueryClient) ReserveExecute(query string, preQueries []string, bindvars map[string]*querypb.BindVariable) (*sqltypes.Result, error) {
client.reservedIDMu.Lock()
defer client.reservedIDMu.Unlock()
if client.reservedID != 0 {
return nil, errors.New("already reserved a connection")
}
Expand Down
12 changes: 6 additions & 6 deletions go/vt/vttablet/endtoend/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func TestShutdownGracePeriod(t *testing.T) {
err := client.Begin(false)
require.NoError(t, err)
go func() {
_, err = client.Execute("select sleep(10) from dual", nil)
_, err := client.Execute("select sleep(10) from dual", nil)
assert.Error(t, err)
}()

Expand All @@ -346,7 +346,7 @@ func TestShutdownGracePeriod(t *testing.T) {
err = client.Begin(false)
require.NoError(t, err)
go func() {
_, err = client.Execute("select sleep(11) from dual", nil)
_, err := client.Execute("select sleep(11) from dual", nil)
assert.Error(t, err)
}()

Expand All @@ -373,7 +373,7 @@ func TestShutdownGracePeriodWithStreamExecute(t *testing.T) {
err := client.Begin(false)
require.NoError(t, err)
go func() {
_, err = client.StreamExecute("select sleep(10) from dual", nil)
_, err := client.StreamExecute("select sleep(10) from dual", nil)
assert.Error(t, err)
}()

Expand All @@ -398,7 +398,7 @@ func TestShutdownGracePeriodWithStreamExecute(t *testing.T) {
err = client.Begin(false)
require.NoError(t, err)
go func() {
_, err = client.StreamExecute("select sleep(11) from dual", nil)
_, err := client.StreamExecute("select sleep(11) from dual", nil)
assert.Error(t, err)
}()

Expand All @@ -425,7 +425,7 @@ func TestShutdownGracePeriodWithReserveExecute(t *testing.T) {
err := client.Begin(false)
require.NoError(t, err)
go func() {
_, err = client.ReserveExecute("select sleep(10) from dual", nil, nil)
_, err := client.ReserveExecute("select sleep(10) from dual", nil, nil)
assert.Error(t, err)
}()

Expand All @@ -450,7 +450,7 @@ func TestShutdownGracePeriodWithReserveExecute(t *testing.T) {
err = client.Begin(false)
require.NoError(t, err)
go func() {
_, err = client.ReserveExecute("select sleep(11) from dual", nil, nil)
_, err := client.ReserveExecute("select sleep(11) from dual", nil, nil)
assert.Error(t, err)
}()

Expand Down
5 changes: 4 additions & 1 deletion go/vt/vttablet/tabletserver/throttle/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ type Client struct {
checkType ThrottleCheckType
flags CheckFlags

lastSuccessfulThrottle int64
lastSuccessfulThrottleMu sync.Mutex
lastSuccessfulThrottle int64
}

// NewProductionClient creates a client suitable for foreground/production jobs, which have normal priority.
Expand Down Expand Up @@ -96,6 +97,8 @@ func (c *Client) ThrottleCheckOK(ctx context.Context, overrideAppName throttlera
// no throttler
return true
}
c.lastSuccessfulThrottleMu.Lock()
defer c.lastSuccessfulThrottleMu.Unlock()
if c.lastSuccessfulThrottle >= atomic.LoadInt64(&throttleTicks) {
// if last check was OK just very recently there is no need to check again
return true
Expand Down
4 changes: 3 additions & 1 deletion tools/e2e_test_race.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ packages_with_tests=$(echo "$packages_with_tests" | grep -vE "go/test/endtoend"
# endtoend tests should be in a directory called endtoend
all_e2e_tests=$(echo "$packages_with_tests" | cut -d" " -f1)

set -exo pipefail

# Run all endtoend tests.
echo "$all_e2e_tests" | xargs go test $VT_GO_PARALLEL -race 2>&1 | tee $temp_log_file
if [ ${PIPESTATUS[0]} -ne 0 ]; then
if [ ${PIPESTATUS[1]} -ne 0 ]; then
if grep "WARNING: DATA RACE" -q $temp_log_file; then
echo
echo "ERROR: go test -race found a data race. See log above."
Expand Down

0 comments on commit d0847c2

Please sign in to comment.