0001-Parallelize-tests-in-CI-67911.patch
Jenkinsfile | ||
---|---|---|
6 | 6 |
stages { |
7 | 7 |
stage('Unit Tests') { |
8 | 8 |
steps { |
9 |
sh 'tox -rv' |
|
9 |
sh 'tox -rv -p 8'
|
|
10 | 10 |
} |
11 | 11 |
post { |
12 | 12 |
always { |
hobo/test_utils.py | ||
---|---|---|
1 |
import hashlib |
|
2 |
import os |
|
3 | ||
4 | ||
5 |
def get_safe_db_name(prefix): |
|
6 |
""" |
|
7 |
PostgreSQL database name limit is 68 characters, which can become |
|
8 |
an issue during testing, because we need to build a unique |
|
9 |
database name using the branch and tox env. |
|
10 | ||
11 |
Ergo, the following code to ensure the database name is always shorter than 68 |
|
12 |
characters. |
|
13 |
""" |
|
14 |
BRANCH_NAME = os.environ.get('BRANCH_NAME', '').replace('/', '-') |
|
15 |
TOX_ENV_NAME = os.environ.get('TOX_ENV_NAME') |
|
16 |
DB_NAME = '_'.join([part for part in [prefix, BRANCH_NAME, TOX_ENV_NAME] if part]) |
|
17 |
DB_NAME = hashlib.sha256(DB_NAME.encode()).hexdigest()[:10] |
|
18 | ||
19 |
return DB_NAME |
tests/settings.py | ||
---|---|---|
1 | 1 |
import os |
2 | 2 | |
3 |
import hobo.test_utils |
|
4 | ||
3 | 5 |
LANGUAGE_CODE = 'en-us' |
4 | 6 |
BROKER_URL = 'memory://' |
5 | 7 | |
... | ... | |
16 | 18 |
) |
17 | 19 | |
18 | 20 |
HOBO_MANAGER_HOMEPAGE_URL_VAR = 'portal_agent_url' |
19 | ||
20 | 21 |
DATABASES = { |
21 | 22 |
'default': { |
22 | 23 |
'ENGINE': os.environ.get('DB_ENGINE', 'django.db.backends.sqlite3'), |
23 |
'TEST': { |
|
24 |
'NAME': ('hobo-test-%s' % os.environ.get("BRANCH_NAME", "").replace('/', '-'))[:63], |
|
25 |
}, |
|
24 |
'NAME': hobo.test_utils.get_safe_db_name('test-hobo'), |
|
26 | 25 |
} |
27 | 26 |
} |
28 | 27 |
tests_authentic/settings.py | ||
---|---|---|
3 | 3 | |
4 | 4 |
from mock import mock_open, patch |
5 | 5 | |
6 |
import hobo.test_utils |
|
7 | ||
6 | 8 |
# Debian defaults |
7 | 9 |
DEBUG = False |
8 | 10 | |
... | ... | |
13 | 15 |
with patch.object(builtins, 'open', mock_open(read_data=b'xxx')): |
14 | 16 |
exec(open_backup(os.environ['DEBIAN_CONFIG_COMMON']).read()) |
15 | 17 | |
16 |
BRANCH_NAME = os.environ.get("BRANCH_NAME", "").replace('/', '-') |
|
17 |
DATABASES['default']['TEST'] = { |
|
18 |
'NAME': (DATABASES['default']['NAME'] + '-%s' % BRANCH_NAME)[:63], |
|
19 |
} |
|
18 |
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name('test-authentic') |
|
20 | 19 | |
21 | 20 |
# Avoid conflic with real tenants |
22 | 21 |
# that might exist in /var/lib/authentic2_multitenant/tenants |
tests_multipublik/settings.py | ||
---|---|---|
3 | 3 | |
4 | 4 |
from mock import mock_open, patch |
5 | 5 | |
6 |
import hobo.test_utils |
|
6 | 7 |
from hobo.settings import * |
7 | 8 | |
8 | 9 |
LANGUAGE_CODE = 'en-us' |
... | ... | |
13 | 14 |
with patch.object(builtins, 'open', mock_open(read_data=b'xxx')): |
14 | 15 |
exec(open_backup(os.path.join(os.path.dirname(__file__), '../debian/debian_config_common.py')).read()) |
15 | 16 | |
16 |
BRANCH_NAME = os.environ.get("BRANCH_NAME", "").replace('/', '-') |
|
17 |
DATABASES['default']['TEST'] = { |
|
18 |
'NAME': (DATABASES['default']['NAME'] + '-%s' % BRANCH_NAME)[:63], |
|
19 |
} |
|
17 |
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name('test-multipublik') |
|
20 | 18 | |
21 | 19 |
CACHES = { |
22 | 20 |
'default': { |
tests_multitenant/settings.py | ||
---|---|---|
3 | 3 | |
4 | 4 |
from mock import mock_open, patch |
5 | 5 | |
6 |
import hobo.test_utils |
|
7 | ||
6 | 8 |
LANGUAGE_CODE = 'en-us' |
7 | 9 | |
8 | 10 |
INSTALLED_APPS = ( |
... | ... | |
50 | 52 |
with patch.object(builtins, 'open', mock_open(read_data=b'xxx')): |
51 | 53 |
exec(open_backup(os.path.join(os.path.dirname(__file__), '../debian/debian_config_common.py')).read()) |
52 | 54 | |
53 |
BRANCH_NAME = os.environ.get("BRANCH_NAME", "").replace('/', '-') |
|
54 |
DATABASES['default']['TEST'] = { |
|
55 |
'NAME': (DATABASES['default']['NAME'] + '-%s' % BRANCH_NAME)[:63], |
|
56 |
} |
|
55 |
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name('test-multitenant') |
|
57 | 56 | |
58 | 57 |
TENANT_APPS = ( |
59 | 58 |
'django.contrib.auth', |
tests_passerelle/settings.py | ||
---|---|---|
3 | 3 | |
4 | 4 |
from mock import mock_open, patch |
5 | 5 | |
6 |
import hobo.test_utils |
|
7 | ||
6 | 8 |
# Debian defaults |
7 | 9 |
DEBUG = False |
8 | 10 | |
... | ... | |
15 | 17 |
with patch.object(builtins, 'open', mock_open(read_data=b'xxx')): |
16 | 18 |
exec(open_backup(os.environ['DEBIAN_CONFIG_COMMON']).read()) |
17 | 19 | |
18 |
BRANCH_NAME = os.environ.get("BRANCH_NAME", "").replace('/', '-') |
|
19 |
DATABASES['default']['TEST'] = { |
|
20 |
'NAME': (DATABASES['default']['NAME'] + '-%s' % BRANCH_NAME)[:63], |
|
21 |
} |
|
20 |
BRANCH_NAME = os.environ.get("BRANCH_NAME", "").replace('/', '-')[:15] |
|
21 |
DATABASES['default']['NAME'] = hobo.test_utils.get_safe_db_name('test-passerelle') |
|
22 | 22 | |
23 | 23 |
# Avoid conflic with real tenants |
24 | 24 |
# that might exist in /var/lib/passerelle/tenants |
tests_schemas/settings.py | ||
---|---|---|
1 | 1 |
import os |
2 | 2 |
import tempfile |
3 | 3 | |
4 |
import hobo.test_utils |
|
5 | ||
4 | 6 |
TENANT_BASE = tempfile.mkdtemp('hobo-tenant-base') |
5 | 7 |
TENANT_MODEL = 'multitenant.Tenant' |
6 | 8 |
MIDDLEWARE = ('hobo.multitenant.middleware.TenantMiddleware',) + MIDDLEWARE |
7 | 9 |
BRANCH_NAME = ( |
8 | 10 |
os.environ.get("BRANCH_NAME", "").replace('/', '_').replace('-', '_').encode('ascii', 'ignore').decode() |
9 |
) |
|
11 |
)[:15]
|
|
10 | 12 |
DATABASES = { |
11 | 13 |
'default': { |
12 | 14 |
'ENGINE': 'tenant_schemas.postgresql_backend', |
13 |
'TEST': {'NAME': ('hobo_test_schemas_' + BRANCH_NAME)[:63]},
|
|
15 |
'NAME': hobo.test_utils.get_safe_db_name('test-schemas'),
|
|
14 | 16 |
} |
15 | 17 |
} |
16 | 18 |
DATABASE_ROUTERS = ('tenant_schemas.routers.TenantSyncRouter',) |
tox.ini | ||
---|---|---|
14 | 14 |
setenv = |
15 | 15 |
DISABLE_GLOBAL_HANDLERS=1 |
16 | 16 |
BRANCH_NAME={env:BRANCH_NAME:} |
17 |
COVERAGE_FILE={envdir}/coverage |
|
17 | 18 |
DB_ENGINE=django.db.backends.postgresql_psycopg2 |
18 | 19 |
SETUPTOOLS_USE_DISTUTILS=stdlib |
19 | 20 |
JUNIT=--junitxml=junit-{envname}.xml |
... | ... | |
31 | 32 |
passerelle: DEBIAN_CONFIG_COMMON=debian/debian_config_common.py |
32 | 33 |
passerelle: PASSERELLE_SETTINGS_FILE=tests_passerelle/settings.py |
33 | 34 |
passerelle: DJANGO_SETTINGS_MODULE=passerelle.settings |
34 |
coverage: COVERAGE=--cov-report xml:coverage-{envname}.xml --cov-report html:htmlcov-{envname} --cov=hobo/ --cov-config .coveragerc |
|
35 |
coverage: COVERAGE=--cov-report xml:coverage-{envname}.xml --cov-report html:htmlcov-{envname} --cov=hobo/ --cov-config .coveragerc
|
|
35 | 36 |
fast: NOMIGRATIONS=--nomigrations |
36 | 37 |
deps: |
37 | 38 |
drf39: djangorestframework>=3.9.2,<3.10 |
38 |
- |