Skip to content

Commit

Permalink
vtcombo: add test for connection leaks on drop + create
Browse files Browse the repository at this point in the history
Signed-off-by: Brendan Dougherty <[email protected]>
  • Loading branch information
brendar committed Aug 20, 2024
1 parent 02ceb02 commit 4cd754c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions go/test/endtoend/vtcombo/recreate/recreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,36 @@ 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)

_, err = cur.Execute(ctx, "CREATE DATABASE "+ks1, nil)
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) {
Expand Down

0 comments on commit 4cd754c

Please sign in to comment.