From 83dc5aa46a4bfc4ba9c647f88d35868e0b1d2fa6 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Thu, 20 Feb 2025 14:28:41 -0600 Subject: [PATCH] fix TestReplicaTransactions Signed-off-by: Florent Poinsard --- go/test/endtoend/tabletgateway/vtgate_test.go | 5 +++-- go/test/endtoend/utils/utils.go | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/go/test/endtoend/tabletgateway/vtgate_test.go b/go/test/endtoend/tabletgateway/vtgate_test.go index 6e69ef958ed..5104a505ece 100644 --- a/go/test/endtoend/tabletgateway/vtgate_test.go +++ b/go/test/endtoend/tabletgateway/vtgate_test.go @@ -261,7 +261,7 @@ func TestReplicaTransactions(t *testing.T) { _ = replicaTablet.VttabletProcess.TearDown() // Healthcheck interval on tablet is set to 1s, so sleep for 2s time.Sleep(2 * time.Second) - utils.AssertContainsError(t, readConn, fetchAllCustomers, "is either down or nonexistent") + utils.AssertContainsMultipleErrors(t, readConn, fetchAllCustomers, "VT15001", "is either down or nonexistent") // bring up the tablet again // trying to use the same session/transaction should fail as the vtgate has @@ -271,7 +271,8 @@ func TestReplicaTransactions(t *testing.T) { require.NoError(t, err) serving := replicaTablet.VttabletProcess.WaitForStatus("SERVING", 60*time.Second) assert.Equal(t, serving, true, "Tablet did not become ready within a reasonable time") - utils.Exec(t, readConn, fetchAllCustomers) + utils.AssertContainsError(t, readConn, fetchAllCustomers, "VT15002") + utils.Exec(t, readConn, "rollback") // create a new connection, should be able to query again readConn, err = mysql.Connect(ctx, &vtParams) diff --git a/go/test/endtoend/utils/utils.go b/go/test/endtoend/utils/utils.go index baa82821306..b4ed09b715c 100644 --- a/go/test/endtoend/utils/utils.go +++ b/go/test/endtoend/utils/utils.go @@ -118,6 +118,17 @@ func AssertContainsError(t *testing.T, conn *mysql.Conn, query, expected string) assert.ErrorContains(t, err, expected, "actual error: %s", err.Error()) } +// AssertContainsMultipleErrors acts the same way as AssertContainsError, but it will assert that +// multiple sub-strings are present in the error +func AssertContainsMultipleErrors(t *testing.T, conn *mysql.Conn, query string, expected ...string) { + t.Helper() + _, err := ExecAllowError(t, conn, query) + require.Error(t, err) + for _, s := range expected { + assert.ErrorContains(t, err, s, "actual error: %s", err.Error()) + } +} + // AssertMatchesNoOrder executes the given query and makes sure it matches the given `expected` string. // The order applied to the results or expectation is ignored. They are both re-sorted. func AssertMatchesNoOrder(t *testing.T, conn *mysql.Conn, query, expected string) {