Projet

Général

Profil

0001-tests-add-support-for-pg_virtualenv.patch

Benjamin Dauvergne, 24 septembre 2019 15:28

Télécharger (3,13 ko)

Voir les différences:

Subject: [PATCH 1/7] tests: add support for pg_virtualenv

 Jenkinsfile       | 14 ++++++++++++--
 tests/conftest.py | 15 +++++++++++++--
 tox.ini           |  4 ++++
 3 files changed, 29 insertions(+), 4 deletions(-)
Jenkinsfile
2 2

  
3 3
pipeline {
4 4
    agent any
5
    options { disableConcurrentBuilds() }
6
    environment {
7
        TMPDIR = "/tmp/$BUILD_TAG"
8
    }
5 9
    stages {
6 10
        stage('Unit Tests') {
7 11
            steps {
8
                sh 'tox -rv'
12
                sh """
13
mkdir ${env.TMPDIR}
14
virtualenv venv
15
./venv/bin/pip install tox
16
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
17
"""
9 18
            }
10 19
            post {
11 20
                always {
......
35 44
                utils.mail_notify(currentBuild, env, 'admin+jenkins-wcs-olap@entrouvert.com')
36 45
            }
37 46
        }
38
        success {
47
        cleanup {
48
            sh "rm -rf ${env.TMPDIR}"
39 49
            cleanWs()
40 50
        }
41 51
    }
tests/conftest.py
22 22
    def __init__(self):
23 23
        self.db_name = 'db%s' % random.getrandbits(20)
24 24
        self.dsn = 'dbname=%s' % self.db_name
25
        with closing(psycopg2.connect('')) as conn:
25
        self.connect_kwargs = {
26
            'dbname': 'postgres'
27
        }
28
        for variable, key in [
29
                ('PGHOST', 'host'),
30
                ('PGUSER', 'user'),
31
                ('PGPASSWORD', 'password'),
32
                ('PGPORT', 'port'),
33
                ('PGDATABASE', 'dbname')]:
34
            if variable in os.environ:
35
                self.connect_kwargs[key] = os.environ[variable]
36
        with closing(psycopg2.connect(**self.connect_kwargs)) as conn:
26 37
            conn.set_isolation_level(0)
27 38
            with conn.cursor() as cursor:
28 39
                cursor.execute('CREATE DATABASE %s' % self.db_name)
......
31 42
        return closing(psycopg2.connect(self.dsn))
32 43

  
33 44
    def delete(self):
34
        with closing(psycopg2.connect('')) as conn:
45
        with closing(psycopg2.connect(**self.connect_kwargs)) as conn:
35 46
            conn.set_isolation_level(0)
36 47
            with conn.cursor() as cursor:
37 48
                cursor.execute('DROP DATABASE IF EXISTS %s' % self.db_name)
tox.ini
13 13
setenv =
14 14
	coverage: COVERAGE=--junit-xml=junit.xml --cov=wcs_olap --cov-report xml --cov-report html
15 15
	WCSCTL=wcs/wcsctl.py
16
	PGPORT={env:PGPORT:}
17
	PGHOST={env:PGHOST:}
18
	PGUSER={env:PGUSER:}
19
	PGPASSWORD={env:PGPASSWORD:}
16 20
deps =
17 21
	coverage
18 22
	pytest
19
-