From dfdad62471371772c18d2a2efac19bfca0a736cb Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Fri, 19 Jul 2024 12:31:28 +0530 Subject: [PATCH] test: add e2e test verifying the changes work as intended Signed-off-by: Manan Gupta --- go/test/endtoend/transaction/twopc/twopc_test.go | 15 +++++++++++++++ go/vt/vtgate/tx_conn.go | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/go/test/endtoend/transaction/twopc/twopc_test.go b/go/test/endtoend/transaction/twopc/twopc_test.go index 2e8f21a453b..1915590c557 100644 --- a/go/test/endtoend/transaction/twopc/twopc_test.go +++ b/go/test/endtoend/transaction/twopc/twopc_test.go @@ -19,8 +19,10 @@ package transaction import ( "context" _ "embed" + "fmt" "reflect" "sort" + "strings" "sync" "testing" "time" @@ -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) diff --git a/go/vt/vtgate/tx_conn.go b/go/vt/vtgate/tx_conn.go index 0e5a7271e85..01eb4cceb0e 100644 --- a/go/vt/vtgate/tx_conn.go +++ b/go/vt/vtgate/tx_conn.go @@ -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" @@ -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) } }