tests: add support for pg_virtualenv

This commit is contained in:
Benjamin Dauvergne 2019-04-11 19:19:59 +02:00
parent 8e60ac10d1
commit 6dd398b693
3 changed files with 29 additions and 4 deletions

14
Jenkinsfile vendored
View File

@ -2,10 +2,19 @@
pipeline {
agent any
options { disableConcurrentBuilds() }
environment {
TMPDIR = "/tmp/$BUILD_TAG"
}
stages {
stage('Unit Tests') {
steps {
sh 'tox -rv'
sh """
mkdir ${env.TMPDIR}
virtualenv venv
./venv/bin/pip install tox
PGPORT=`python -c 'import struct; import socket; s=socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0)); s.bind(("", 0)); print(s.getsockname()[1]); s.close()'` pg_virtualenv -o fsync=off ./venv/bin/tox -rv
"""
}
post {
always {
@ -35,7 +44,8 @@ pipeline {
utils.mail_notify(currentBuild, env, 'admin+jenkins-wcs-olap@entrouvert.com')
}
}
success {
cleanup {
sh "rm -rf ${env.TMPDIR}"
cleanWs()
}
}

View File

@ -22,7 +22,18 @@ class Database(object):
def __init__(self):
self.db_name = 'db%s' % random.getrandbits(20)
self.dsn = 'dbname=%s' % self.db_name
with closing(psycopg2.connect('')) as conn:
self.connect_kwargs = {
'dbname': 'postgres'
}
for variable, key in [
('PGHOST', 'host'),
('PGUSER', 'user'),
('PGPASSWORD', 'password'),
('PGPORT', 'port'),
('PGDATABASE', 'dbname')]:
if variable in os.environ:
self.connect_kwargs[key] = os.environ[variable]
with closing(psycopg2.connect(**self.connect_kwargs)) as conn:
conn.set_isolation_level(0)
with conn.cursor() as cursor:
cursor.execute('CREATE DATABASE %s' % self.db_name)
@ -31,7 +42,7 @@ class Database(object):
return closing(psycopg2.connect(self.dsn))
def delete(self):
with closing(psycopg2.connect('')) as conn:
with closing(psycopg2.connect(**self.connect_kwargs)) as conn:
conn.set_isolation_level(0)
with conn.cursor() as cursor:
cursor.execute('DROP DATABASE IF EXISTS %s' % self.db_name)

View File

@ -13,6 +13,10 @@ basepython = python2
setenv =
coverage: COVERAGE=--junit-xml=junit.xml --cov=wcs_olap --cov-report xml --cov-report html
WCSCTL=wcs/wcsctl.py
PGPORT={env:PGPORT:}
PGHOST={env:PGHOST:}
PGUSER={env:PGUSER:}
PGPASSWORD={env:PGPASSWORD:}
deps =
coverage
pytest