Skip to content

Commit eb9555d

Browse files
committed
vtcombo: add test for connection leaks on drop + create
Signed-off-by: Brendan Dougherty <brendan.dougherty@shopify.com>
1 parent c51d69e commit eb9555d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

go/test/endtoend/vtcombo/recreate/recreate_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,36 @@ func TestDropAndRecreateWithSameShards(t *testing.T) {
102102

103103
cur := conn.Session(ks1+"@primary", nil)
104104

105+
mysqlConnCountBefore, err := getMySQLConnectionCount(ctx, cur)
106+
require.Nil(t, err)
107+
105108
_, err = cur.Execute(ctx, "DROP DATABASE "+ks1, nil)
106109
require.Nil(t, err)
107110

108111
_, err = cur.Execute(ctx, "CREATE DATABASE "+ks1, nil)
109112
require.Nil(t, err)
110113

111114
assertTabletsPresent(t)
115+
116+
mysqlConnCountAfter, err := getMySQLConnectionCount(ctx, cur)
117+
require.Nil(t, err)
118+
119+
// Assert that we're not leaking mysql connections, but allow for some wiggle room due to transient connections
120+
assert.InDelta(t, mysqlConnCountBefore, mysqlConnCountAfter, 5,
121+
"not within allowable delta: mysqlConnCountBefore=%d, mysqlConnCountAfter=%d", mysqlConnCountBefore, mysqlConnCountAfter)
122+
}
123+
124+
func getMySQLConnectionCount(ctx context.Context, session *vtgateconn.VTGateSession) (int, error) {
125+
result, err := session.Execute(ctx, "SELECT COUNT(*) FROM information_schema.processlist", nil)
126+
if err != nil {
127+
return 0, err
128+
}
129+
row := result.Rows[0][0]
130+
toInt, err := row.ToInt()
131+
if err != nil {
132+
return 0, err
133+
}
134+
return toInt, nil
112135
}
113136

114137
func assertTabletsPresent(t *testing.T) {

0 commit comments

Comments
 (0)