Skip to content

Commit

Permalink
Added multi-test environment for travis: postgres 9.0 tests, updated
Browse files Browse the repository at this point in the history
travis config, updated current docker configs
  • Loading branch information
prawn-cake committed Sep 20, 2015
1 parent 575c180 commit 9b012df
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 28 deletions.
13 changes: 11 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,28 @@ before_install:
- sudo apt-get update
- sudo apt-get install -y python-dev libpq-dev lxc-docker
- docker build -t pgclient/system_test pgclient/system_test
- docker build -t pgclient/system_test_pg90 -f pgclient/system_test/Dockerfile.pg90 pgclient/system_test

- sudo service docker restart ; sleep 10

- docker run --name pgclient_system_test --privileged -d -p "0.0.0.0:15432:5432" -e POSTGRES_PASSWORD=test pgclient/system_test
- docker run --name pgclient_system_test_pg90 --privileged -d -p "0.0.0.0:54390:5432" -e POSTGRES_PASSWORD=test pgclient/system_test_pg90
- sleep 20
- docker ps -a
- docker logs pgclient_system_test
- docker logs pgclient_system_test_pg90
- sudo netstat -ntlp

install:
- pip install -r requirements.txt
- pip install coveralls

script:
- make system_test
# Run tests on postgres:9.0
- export POSTGRES_PORT=54390
- make system_test

after_success:
coveralls
- coveralls
- docker stop pgclient_system_test pgclient_system_test_pg90
- docker rm pgclient_system_test pgclient_system_test_pg90
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Safe transactions
-----------------

All requests inside `with` context will be executed and automatically committed within one transaction
(or rollbacked in case if database errors)
(or rolled back in case if database errors)

with self.pg_client.cursor as transaction:
transaction.execute('INSERT INTO users VALUES name="Mark"')
Expand All @@ -103,12 +103,17 @@ To run integration test you need to install the following:
* [Docker compose](https://docs.docker.com/compose/)


**Run system tests:**
**Run system test:**

* Run postgresql container: `docker-compose up -d postgresql`
* Run system tests: `make system_test`
* Stop postgresql container: `docker-compose stop postgresql`

To test with *postgresql:9.0* run `postgresql_90` container with docker compose.

Both versions are being tested with travis ci.



Bug tracker
===========
Expand Down
7 changes: 2 additions & 5 deletions compose/common.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
postgresql_common:
build: pgclient/system_test
build: ../pgclient/system_test
environment:
POSTGRES_PASSWORD: test # Set password for default (postgres) user
PGPASSWORD: test # For using `psql -c ...` without password

# Override
command: echo "CREATE DATABASE test WITH OWNER postgres;" >> /docker-entrypoint-initdb.d/create_db.sql && /docker-entrypoint.sh
PGPASSWORD: test # For using `psql -c ...` without password
23 changes: 4 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,12 @@ postgresql:
file: compose/common.yml
service: postgresql_common

# Older verions
# Older versions
postgresql_90:
image: postgres:9.0
container_name: pgclient_system
ports:
- "0.0.0.0:54390:5432"
dockerfile: Dockerfile.pg90
extends:
file: compose/common.yml
service: postgresql_common

postgresql_91:
image: postgres:9.1
ports:
- "0.0.0.0:54391:5432"
extends:
file: compose/common.yml
service: postgresql_common

postgresql_92:
image: postgres:9.2
ports:
- "0.0.0.0:54392:5432"
extends:
file: compose/common.yml
service: postgresql_common
service: postgresql_common
6 changes: 6 additions & 0 deletions pgclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import psycopg2.extras as pg_extras


__all__ = ['PostgresClient']


class PostgresClient(object):
def __init__(self, dsn=None, database=None, user=None, password=None,
host=None, port=None, pool_size=1):
Expand All @@ -29,11 +32,14 @@ def acquire_conn(self):
"""Get new pool connection
:return: psycopg2 connection object
:raise: psycopg2.pool.PoolError: when is no available connections
"""
return self._pool.getconn()

def release_conn(self, conn):
"""Release connection to a pool
Connection will be returned into the pool in a consistent state
(idle transaction will be rolled back, unknown - closed)
:param conn: psycopg2 connection object
"""
Expand Down
10 changes: 10 additions & 0 deletions pgclient/system_test/Dockerfile.pg90
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM postgres:9.0
MAINTAINER Maksim Ekimovskii <ekimovsky.maksim@gmail.com>

# Default user is postgres
# ENV POSTGRES_PASSWORD: test

# This dir is supported by official postgresql image
# ENV PSQL_ENTRYPOINT /docker-entrypoint-initdb.d

RUN echo "CREATE DATABASE test WITH OWNER postgres;" >> /docker-entrypoint-initdb.d/create_db.sql

0 comments on commit 9b012df

Please sign in to comment.