Rework pdo_pgsql tests to not re-connect to the database every time; this seems
authorChuck Hagenbuch <chuck@horde.org>
Thu, 7 Jan 2010 02:45:57 +0000 (21:45 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Thu, 7 Jan 2010 03:19:55 +0000 (22:19 -0500)
to inevitably overflow the max_connections setting, at least on a
developer-tuned postgres install.

framework/Db/test/Horde/Db/Adapter/Pdo/PgsqlSuite.php
framework/Db/test/Horde/Db/Adapter/Pdo/PgsqlTest.php
framework/Db/test/Horde/Db/Adapter/Postgresql/ColumnDefinitionTest.php
framework/Db/test/Horde/Db/Adapter/Postgresql/TableDefinitionTest.php

index 7bd9997..0c1f89e 100644 (file)
@@ -24,6 +24,8 @@
  */
 class Horde_Db_Adapter_Pdo_PgsqlSuite extends PHPUnit_Framework_TestSuite
 {
+    public static $conn = null;
+
     public static function suite()
     {
         $suite = new self('Horde Framework - Horde_Db - PDO-PostgreSQL Adapter');
@@ -31,9 +33,8 @@ class Horde_Db_Adapter_Pdo_PgsqlSuite extends PHPUnit_Framework_TestSuite
         $skip = true;
         if (extension_loaded('pdo') && in_array('pgsql', PDO::getAvailableDrivers())) {
             try {
-                list($conn,) = $suite->getConnection();
+                self::$conn = $suite->getConnection();
                 $skip = false;
-                $conn->disconnect();
             } catch (Exception $e) {}
         }
 
@@ -59,6 +60,8 @@ class Horde_Db_Adapter_Pdo_PgsqlSuite extends PHPUnit_Framework_TestSuite
 
     public function getConnection()
     {
+        if (!is_null(self::$conn)) { return self::$conn; }
+
         if (!class_exists('CacheMock', false)) eval('class CacheMock { function get($key) { return $this->$key; } function set($key, $val) { $this->$key = $val; } } ?>');
         $cache = new CacheMock;
 
index 237f0e3..233aa22 100644 (file)
@@ -78,9 +78,6 @@ class Horde_Db_Adapter_Pdo_PgsqlTest extends PHPUnit_Framework_TestCase
     {
         // clean up
         $this->_dropTestTables();
-
-        // close connection
-        $this->_conn->disconnect();
     }
 
 
index 64c2854..3c40fc6 100644 (file)
@@ -29,13 +29,6 @@ class Horde_Db_Adapter_Postgresql_ColumnDefinitionTest extends PHPUnit_Framework
         list($this->_conn,) = $this->sharedFixture->getConnection();
     }
 
-    protected function tearDown()
-    {
-        // close connection
-        $this->_conn->disconnect();
-    }
-
-
     public function testConstruct()
     {
         $col = new Horde_Db_Adapter_Base_ColumnDefinition(
index 52d18ab..327b82a 100644 (file)
@@ -29,12 +29,6 @@ class Horde_Db_Adapter_Postgresql_TableDefinitionTest extends PHPUnit_Framework_
         list($this->_conn,) = $this->sharedFixture->getConnection();
     }
 
-    protected function tearDown()
-    {
-        // close connection
-        $this->_conn->disconnect();
-    }
-
 
     /*##########################################################################
     # Public methods