Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id CB0099FBD90 for ; Fri, 20 Jul 2007 16:14:19 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 18232-07 for ; Fri, 20 Jul 2007 16:14:07 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from gw03.mail.saunalahti.fi (gw03.mail.saunalahti.fi [195.197.172.111]) by postgresql.org (Postfix) with ESMTP id 95FEF9FC05A for ; Fri, 20 Jul 2007 16:14:09 -0300 (ADT) Received: from [10.0.0.4] (a88-113-10-143.elisa-laajakaista.fi [88.113.10.143]) (using SSLv3 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by gw03.mail.saunalahti.fi (Postfix) with ESMTP id 662772165F9 for ; Fri, 20 Jul 2007 22:14:07 +0300 (EEST) Subject: [PATCH] Stop test cases from leaking connections From: Mikko Tiihonen To: pgsql-jdbc Content-Type: text/plain Date: Fri, 20 Jul 2007 22:14:06 +0300 Message-Id: <1184958846.1632.33.camel@dual.local> Mime-Version: 1.0 X-Mailer: Evolution 2.10.2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200707/93 X-Sequence-Number: 17267 Hi, The following patch fixes connection leaks in the current unit test cases. The patch allows passing the tests with under 10 connections in the server. Index: org/postgresql/test/jdbc2/TimezoneTest.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/TimezoneTest.java,v retrieving revision 1.4 diff -u -r1.4 TimezoneTest.java --- org/postgresql/test/jdbc2/TimezoneTest.java 16 Apr 2007 18:31:38 -0000 1.4 +++ org/postgresql/test/jdbc2/TimezoneTest.java 20 Jul 2007 19:04:12 -0000 @@ -97,6 +97,7 @@ TimeZone.setDefault(saveTZ); TestUtil.dropTable(con, "testtimezone"); + TestUtil.closeDB(con); } public void testGetTimestamp() throws Exception Index: org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java,v retrieving revision 1.11 diff -u -r1.11 BaseDataSourceTest.java --- org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java 11 Jan 2005 08:25:48 -0000 1.11 +++ org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java 20 Jul 2007 19:04:12 -0000 @@ -62,6 +62,7 @@ */ protected void tearDown() throws Exception { + TestUtil.closeDB(con); con = TestUtil.openDB(); TestUtil.dropTable(con, "poolingtest"); TestUtil.closeDB(con); Index: org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java,v retrieving revision 1.15 diff -u -r1.15 ConnectionPoolTest.java --- org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java 11 Jan 2005 08:25:48 -0000 1.15 +++ org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java 20 Jul 2007 19:04:12 -0000 @@ -320,7 +320,7 @@ try { PooledConnection pc = getPooledConnection(); - Connection con = pc.getConnection(); + con = pc.getConnection(); assertTrue(!con.isClosed()); con.close(); assertTrue(con.isClosed()); @@ -346,7 +346,7 @@ try { PooledConnection pc = getPooledConnection(); - Connection con = pc.getConnection(); + con = pc.getConnection(); Statement s = con.createStatement(); Connection conRetrieved = s.getConnection(); @@ -368,7 +368,7 @@ try { PooledConnection pc = getPooledConnection(); - Connection con = pc.getConnection(); + con = pc.getConnection(); s = con.createStatement(); } catch (SQLException e) @@ -400,7 +400,7 @@ try { PooledConnection pc = getPooledConnection(); - Connection con = pc.getConnection(); + con = pc.getConnection(); PreparedStatement s = con.prepareStatement("select 'x'"); Connection conRetrieved = s.getConnection(); @@ -422,7 +422,7 @@ try { PooledConnection pc = getPooledConnection(); - Connection con = pc.getConnection(); + con = pc.getConnection(); CallableStatement s = con.prepareCall("select 'x'"); Connection conRetrieved = s.getConnection(); Index: org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java,v retrieving revision 1.7 diff -u -r1.7 PoolingDataSourceTest.java --- org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java 11 Jan 2005 08:25:48 -0000 1.7 +++ org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java 20 Jul 2007 19:04:13 -0000 @@ -34,11 +34,11 @@ protected void tearDown() throws Exception { - super.tearDown(); if (bds instanceof PoolingDataSource) { ((PoolingDataSource) bds).close(); } + super.tearDown(); } /** Index: org/postgresql/test/jdbc3/Jdbc3CallableStatementTest.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc3/Jdbc3CallableStatementTest.java,v retrieving revision 1.3 diff -u -r1.3 Jdbc3CallableStatementTest.java --- org/postgresql/test/jdbc3/Jdbc3CallableStatementTest.java 15 Jul 2007 15:03:31 -0000 1.3 +++ org/postgresql/test/jdbc3/Jdbc3CallableStatementTest.java 20 Jul 2007 19:04:13 -0000 @@ -94,7 +94,7 @@ stmt.execute("drop function myiofunc(a INOUT int, b OUT int) "); stmt.execute("drop function myif(a INOUT int, b IN int)"); stmt.close(); - + TestUtil.closeDB(con); } public void testSomeInOut() throws Throwable {