From ed488f83b46f03112f562849e9d2588f9d61027c Mon Sep 17 00:00:00 2001 From: Brendan Dougherty Date: Mon, 19 Aug 2024 17:54:58 -0400 Subject: [PATCH] vtcombo: add test for connection leaks on drop + create Signed-off-by: Brendan Dougherty --- .../vtcombo/recreate/recreate_test.go | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/go/test/endtoend/vtcombo/recreate/recreate_test.go b/go/test/endtoend/vtcombo/recreate/recreate_test.go index e66edb7688a..56d0c454bbf 100644 --- a/go/test/endtoend/vtcombo/recreate/recreate_test.go +++ b/go/test/endtoend/vtcombo/recreate/recreate_test.go @@ -101,6 +101,9 @@ func TestDropAndRecreateWithSameShards(t *testing.T) { cur := conn.Session(ks1+"@primary", nil) + mysqlConnCountBefore, err := getMySQLConnectionCount(ctx, cur) + require.Nil(t, err) + _, err = cur.Execute(ctx, "DROP DATABASE "+ks1, nil) require.Nil(t, err) @@ -108,6 +111,26 @@ func TestDropAndRecreateWithSameShards(t *testing.T) { require.Nil(t, err) assertTabletsPresent(t) + + mysqlConnCountAfter, err := getMySQLConnectionCount(ctx, cur) + require.Nil(t, err) + + // Assert that we're not leaking mysql connections, but allow for some wiggle room due to transient connections + assert.InDelta(t, mysqlConnCountBefore, mysqlConnCountAfter, 5, + "not within allowable delta: mysqlConnCountBefore=%d, mysqlConnCountAfter=%d", mysqlConnCountBefore, mysqlConnCountAfter) +} + +func getMySQLConnectionCount(ctx context.Context, session *vtgateconn.VTGateSession) (int, error) { + result, err := session.Execute(ctx, "SELECT COUNT(*) FROM information_schema.processlist", nil) + if err != nil { + return 0, err + } + row := result.Rows[0][0] + toInt, err := row.ToInt() + if err != nil { + return 0, err + } + return toInt, nil } func assertTabletsPresent(t *testing.T) {