From d143f2a572178f551c4eaec4eec080cd1db4fa0f Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Thu, 9 May 2024 12:01:42 +0530 Subject: [PATCH] test: added e2e test Signed-off-by: Harshit Gangal --- .../vtgate/queries/timeout/timeout_test.go | 23 +++++++++++++++++++ go/vt/vtgate/engine/cached_size.go | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/go/test/endtoend/vtgate/queries/timeout/timeout_test.go b/go/test/endtoend/vtgate/queries/timeout/timeout_test.go index bab9699d027..1f6dcdc7d39 100644 --- a/go/test/endtoend/vtgate/queries/timeout/timeout_test.go +++ b/go/test/endtoend/vtgate/queries/timeout/timeout_test.go @@ -97,3 +97,26 @@ func TestQueryTimeoutWithTables(t *testing.T) { assert.Contains(t, err.Error(), "context deadline exceeded") assert.Contains(t, err.Error(), "(errno 1317) (sqlstate 70100)") } + +// TestQueryTimeoutWithShardTargeting tests the query timeout with shard targeting. +func TestQueryTimeoutWithShardTargeting(t *testing.T) { + mcmp, closer := start(t) + defer closer() + + queries := []string{ + "insert /*vt+ QUERY_TIMEOUT_MS=1 */ into t1(id1, id2) values (1,2)", + "update /*vt+ QUERY_TIMEOUT_MS=1 */ t1 set id2 = 5", + "delete /*vt+ QUERY_TIMEOUT_MS=1 */ from t1 where id2 = 5", + "select /*vt+ QUERY_TIMEOUT_MS=1 */ 1 from t1 where sleep(100)", + } + + // shard targeting to -80 shard. + utils.Exec(t, mcmp.VtConn, "use `ks_misc/-80`") + + for _, query := range queries { + t.Run(query, func(t *testing.T) { + _, err := utils.ExecAllowError(t, mcmp.VtConn, query) + assert.ErrorContains(t, err, "context deadline exceeded (errno 1317) (sqlstate 70100)") + }) + } +} diff --git a/go/vt/vtgate/engine/cached_size.go b/go/vt/vtgate/engine/cached_size.go index 18e22c00378..c1b72382461 100644 --- a/go/vt/vtgate/engine/cached_size.go +++ b/go/vt/vtgate/engine/cached_size.go @@ -1091,7 +1091,7 @@ func (cached *Send) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(48) + size += int64(64) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true)