Skip to content

Commit

Permalink
test: add e2e test verifying the changes work as intended
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <manan@planetscale.com>
  • Loading branch information
GuptaManan100 committed Jul 23, 2024
1 parent c19cd1c commit dfdad62
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions go/test/endtoend/transaction/twopc/twopc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ package transaction
import (
"context"
_ "embed"
"fmt"
"reflect"
"sort"
"strings"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -849,6 +851,19 @@ func TestDTResolveAfterTransactionRecord(t *testing.T) {
_, err = conn.Execute(newCtx, "commit", nil)
require.ErrorContains(t, err, "Fail After TR created")

t.Run("ReadTransactionState", func(t *testing.T) {
errStr := err.Error()
indx := strings.Index(errStr, "Fail")
require.Greater(t, indx, 0)
dtid := errStr[0 : indx-2]
res, err := conn.Execute(context.Background(), fmt.Sprintf(`show transaction status for '%v'`, dtid), nil)
require.NoError(t, err)
resStr := fmt.Sprintf("%v", res.Rows)
require.Contains(t, resStr, `[[VARCHAR("ks:80-`)
require.Contains(t, resStr, `VARCHAR("PREPARE") DATETIME("`)
require.Contains(t, resStr, `+0000 UTC") VARCHAR("ks:-80")]]`)
})

// Below check ensures that the transaction is resolved by the resolver on receiving unresolved transaction signal from MM.
tableMap := make(map[string][]*querypb.Field)
dtMap := make(map[string]string)
Expand Down
4 changes: 3 additions & 1 deletion go/vt/vtgate/tx_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"strings"
"sync"

"github.com/pkg/errors"

"vitess.io/vitess/go/mysql/sqlerror"
"vitess.io/vitess/go/vt/callerid"
"vitess.io/vitess/go/vt/concurrency"
Expand Down Expand Up @@ -204,7 +206,7 @@ func (txc *TxConn) commit2PC(ctx context.Context, session *SafeSession) error {
if DEBUG_2PC {
// Test code to simulate a failure after RM prepare
if failNow, err := checkTestFailure(callerid.EffectiveCallerIDFromContext(ctx), "TRCreated_FailNow", nil); failNow {
return err
return errors.Wrapf(err, "%v", dtid)
}
}

Expand Down

0 comments on commit dfdad62

Please sign in to comment.