From 7b075b659261446fc52832127069ee7b4ae48273 Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Sat, 19 Sep 2020 10:06:58 +0530 Subject: [PATCH] end to end test for reserved connection in autocommit mode Signed-off-by: Harshit Gangal --- .../vtgate/setstatement/sysvar_test.go | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/go/test/endtoend/vtgate/setstatement/sysvar_test.go b/go/test/endtoend/vtgate/setstatement/sysvar_test.go index 0eccc545ec6..9a7e98bafc3 100644 --- a/go/test/endtoend/vtgate/setstatement/sysvar_test.go +++ b/go/test/endtoend/vtgate/setstatement/sysvar_test.go @@ -192,6 +192,36 @@ func TestSetSystemVariableAndThenSuccessfulTx(t *testing.T) { assertMatches(t, conn, "select @@sql_safe_updates", "[[INT64(1)]]") } +func TestSetSystemVariableAndThenSuccessfulAutocommitDML(t *testing.T) { + vtParams := mysql.ConnParams{ + Host: "localhost", + Port: clusterInstance.VtgateMySQLPort, + } + + conn, err := mysql.Connect(context.Background(), &vtParams) + require.NoError(t, err) + defer conn.Close() + checkedExec(t, conn, `delete from test`) + + checkedExec(t, conn, `set sql_safe_updates = 1`) + + checkedExec(t, conn, `insert into test (id, val1) values (80, null)`) + assertMatches(t, conn, `select id, val1 from test`, `[[INT64(80) NULL]]`) + assertMatches(t, conn, `select @@sql_safe_updates`, `[[INT64(1)]]`) + + checkedExec(t, conn, `update test set val2 = 2 where val1 is null`) + assertMatches(t, conn, `select id, val1, val2 from test`, `[[INT64(80) NULL INT64(2)]]`) + assertMatches(t, conn, `select @@sql_safe_updates`, `[[INT64(1)]]`) + + checkedExec(t, conn, `update test set val1 = 'text' where val1 is null`) + assertMatches(t, conn, `select id, val1, val2 from test`, `[[INT64(80) VARCHAR("text") INT64(2)]]`) + assertMatches(t, conn, `select @@sql_safe_updates`, `[[INT64(1)]]`) + + checkedExec(t, conn, `delete from test where val1 = 'text'`) + assertMatches(t, conn, `select id, val1, val2 from test`, `[]`) + assertMatches(t, conn, `select @@sql_safe_updates`, `[[INT64(1)]]`) +} + func TestStartTxAndSetSystemVariableAndThenSuccessfulCommit(t *testing.T) { vtParams := mysql.ConnParams{ Host: "localhost",