Skip to content

Commit

Permalink
fix TestReplicaTransactions
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
  • Loading branch information
frouioui committed Feb 20, 2025
1 parent f5ee299 commit 83dc5aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions go/test/endtoend/tabletgateway/vtgate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions go/test/endtoend/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 83dc5aa

Please sign in to comment.