From 297c1d297f4cee55a6aee5eb68583d0139aef076 Mon Sep 17 00:00:00 2001 From: Andrei Korzhevskii Date: Mon, 23 Mar 2015 18:23:53 +0300 Subject: database/sql: provide stats on number of open connections to the database. This change provides a convenient way to monitor database connection pool. Change-Id: I4b3757855b43f3b254acf9312e2a16e2f87840d0 Reviewed-on: https://go-review.googlesource.com/7950 Run-TryBot: Brad Fitzpatrick Reviewed-by: Brad Fitzpatrick --- src/database/sql/sql_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/database/sql/sql_test.go') diff --git a/src/database/sql/sql_test.go b/src/database/sql/sql_test.go index 60bdefa076..e225ffe6fa 100644 --- a/src/database/sql/sql_test.go +++ b/src/database/sql/sql_test.go @@ -1093,6 +1093,26 @@ func TestSingleOpenConn(t *testing.T) { } } +func TestStats(t *testing.T) { + db := newTestDB(t, "people") + stats := db.Stats() + if got := stats.OpenConnections; got != 1 { + t.Errorf("stats.OpenConnections = %d; want 1", got) + } + + tx, err := db.Begin() + if err != nil { + t.Fatal(err) + } + tx.Commit() + + closeDB(t, db) + stats = db.Stats() + if got := stats.OpenConnections; got != 0 { + t.Errorf("stats.OpenConnections = %d; want 0", got) + } +} + // golang.org/issue/5323 func TestStmtCloseDeps(t *testing.T) { if testing.Short() { -- cgit v1.3