Skip to content

Commit 7115324

Browse files
Add a test to verify we respect the overall query timeout (#16800)
Signed-off-by: Manan Gupta <[email protected]>
1 parent 3182049 commit 7115324

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

go/test/endtoend/vtgate/queries/timeout/timeout_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,30 @@ func TestQueryTimeoutWithoutVTGateDefault(t *testing.T) {
179179
_, err = utils.ExecAllowError(t, mcmp.VtConn, "select sleep(5) from dual")
180180
assert.Error(t, err)
181181
}
182+
183+
// TestOverallQueryTimeout tests that the query timeout is applied to the overall execution of a query
184+
// and not just individual routes.
185+
func TestOverallQueryTimeout(t *testing.T) {
186+
utils.SkipIfBinaryIsBelowVersion(t, 21, "vtgate")
187+
mcmp, closer := start(t)
188+
defer closer()
189+
190+
mcmp.Exec("insert into t1(id1, id2) values (2,2),(3,3)")
191+
192+
// After inserting the rows above, if we run the following query, we will end up doing join on vtgate
193+
// that issues one select query on the left side and 2 on the right side. The queries on the right side
194+
// take 2 and 3 seconds each to run. If we have an overall timeout for 4 seconds, then it should fail.
195+
_, err := utils.ExecAllowError(t, mcmp.VtConn, "select /*vt+ QUERY_TIMEOUT_MS=4000 */ sleep(u2.id2), u1.id2 from t1 u1 join t1 u2 where u1.id2 = u2.id1")
196+
assert.Error(t, err)
197+
assert.ErrorContains(t, err, "DeadlineExceeded desc = context deadline exceeded (errno 1317) (sqlstate 70100)")
198+
199+
// Let's also check that setting the session variable also works.
200+
utils.Exec(t, mcmp.VtConn, "set query_timeout=4000")
201+
_, err = utils.ExecAllowError(t, mcmp.VtConn, "select sleep(u2.id2), u1.id2 from t1 u1 join t1 u2 where u1.id2 = u2.id1")
202+
assert.Error(t, err)
203+
assert.ErrorContains(t, err, "DeadlineExceeded desc = context deadline exceeded (errno 1317) (sqlstate 70100)")
204+
205+
// Increasing the timeout should pass the query.
206+
utils.Exec(t, mcmp.VtConn, "set query_timeout=10000")
207+
_ = utils.Exec(t, mcmp.VtConn, "select sleep(u2.id2), u1.id2 from t1 u1 join t1 u2 where u1.id2 = u2.id1")
208+
}

0 commit comments

Comments
 (0)