From 06ea97ae4572042029f1f2f2767e1e0840d7accd Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Thu, 23 Jul 2015 16:12:37 +0000 Subject: [PATCH] Close and dispose test database setup connections Without explicitly closing and disposing the connections can linger in a non-deterministic fashion and cause intermittent "too many connection" errors in the tests. This is effectively a "backport" of change I8badf2a3094f2d27d381bd178c6d579f2a5c5ffe in aodh, made here for safety despite not seeing the problem regularly in the ceilometer tests. The -N 100 is removed from the setup-test-env so that we are using whatever the postgresql default is, meaning that these tests will be better at exposing errors that users may see. Change-Id: I694d118ff8dc2b5c8be633121fa1037130fbe874 --- ceilometer/tests/db.py | 4 ++++ setup-test-env-postgresql.sh | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ceilometer/tests/db.py b/ceilometer/tests/db.py index cbac5f4e17..7e422ce113 100644 --- a/ceilometer/tests/db.py +++ b/ceilometer/tests/db.py @@ -92,6 +92,8 @@ class PgSQLManager(SQLManager): self._conn.execute( 'CREATE DATABASE %s WITH TEMPLATE template0;' % self._db_name) self._conn.connection.set_isolation_level(1) + self._conn.close() + self._engine.dispose() class MySQLManager(SQLManager): @@ -103,6 +105,8 @@ class MySQLManager(SQLManager): self._url.replace('template1', '')) self._conn = self._engine.connect() self._conn.execute('CREATE DATABASE %s;' % self._db_name) + self._conn.close() + self._engine.dispose() class ElasticSearchManager(fixtures.Fixture): diff --git a/setup-test-env-postgresql.sh b/setup-test-env-postgresql.sh index 002fd9f443..5d68eea875 100755 --- a/setup-test-env-postgresql.sh +++ b/setup-test-env-postgresql.sh @@ -27,7 +27,7 @@ PGSQL_PORT=9823 ${PGSQL_PATH}/initdb -E UTF8 ${PGSQL_DATA} trap "clean_exit_pgsql ${PGSQL_PATH} ${PGSQL_DATA} ${PGSQL_PORT}" EXIT -LANGUAGE=C ${PGSQL_PATH}/pg_ctl -w -D ${PGSQL_DATA} -o "-N 100 -F -k ${PGSQL_DATA} -p ${PGSQL_PORT}" start +LANGUAGE=C ${PGSQL_PATH}/pg_ctl -w -D ${PGSQL_DATA} -o "-F -k ${PGSQL_DATA} -p ${PGSQL_PORT}" start export CEILOMETER_TEST_PGSQL_URL="postgresql:///?host=${PGSQL_DATA}&port=${PGSQL_PORT}&dbname=template1" # Yield execution to venv command