Skip to content

Commit f027d60

Browse files
dima-asanaashb
authored andcommitted
[AIRFLOW-3168] More resillient database use in CI (apache#4014)
1 parent 93a2ea7 commit f027d60

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

scripts/ci/3-setup-databases.sh scripts/ci/3-setup-mysql.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,11 @@ set -exuo pipefail
2020

2121
MYSQL_HOST=mysql
2222

23-
mysql -h ${MYSQL_HOST} -u root -e 'drop database if exists airflow; create database airflow'
23+
retries=3
24+
for ((i=0; i<retries; i++)); do
25+
mysql -h ${MYSQL_HOST} -u root -e 'drop database if exists airflow; create database airflow' && exit 0
26+
echo "mysql db creation did not succeed, waiting 5 seconds to retry"
27+
sleep 5
28+
done
29+
30+
echo "mysql db creation could not succeed" && exit 1

scripts/ci/airflow_travis.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ airflow_home = ~/airflow
2121
dags_folder = ~/airflow/dags
2222
base_log_folder = ~/airflow/logs
2323
executor = LocalExecutor
24-
sql_alchemy_conn = mysql://root@mysql/airflow
24+
sql_alchemy_conn = # overridden by tox.ini
2525
unit_test_mode = True
2626
load_examples = True
2727
donot_pickle = False
@@ -56,7 +56,7 @@ celery_app_name = airflow.executors.celery_executor
5656
worker_concurrency = 16
5757
worker_log_server_port = 8793
5858
broker_url = amqp://guest:guest@rabbitmq:5672/
59-
result_backend = db+mysql://root@mysql/airflow
59+
result_backend = # overridden by tox.ini
6060
flower_port = 5555
6161
default_queue = default
6262

tests/configuration.py

+5
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,9 @@ def test_deprecated_options_cmd(self):
221221
conf.set('celery', 'celery_result_backend_cmd', '/bin/echo 99')
222222

223223
with self.assertWarns(DeprecationWarning):
224+
tmp = None
225+
if 'AIRFLOW__CELERY__RESULT_BACKEND' in os.environ:
226+
tmp = os.environ.pop('AIRFLOW__CELERY__RESULT_BACKEND')
224227
self.assertEquals(conf.getint('celery', 'result_backend'), 99)
228+
if tmp:
229+
os.environ['AIRFLOW__CELERY__RESULT_BACKEND'] = tmp

tests/executors/test_celery_executor.py

+5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@
2424
from airflow.executors.celery_executor import app
2525
from airflow.utils.state import State
2626

27+
from airflow import configuration
28+
configuration.load_test_config()
29+
2730
# leave this it is used by the test worker
2831
import celery.contrib.testing.tasks # noqa: F401
2932

3033

3134
class CeleryExecutorTest(unittest.TestCase):
35+
@unittest.skipIf('sqlite' in configuration.conf.get('core', 'sql_alchemy_conn'),
36+
"sqlite is configured with SequentialExecutor")
3237
def test_celery_integration(self):
3338
executor = CeleryExecutor()
3439
executor.start()

tox.ini

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ setenv =
4444
KRB5_CONFIG=/etc/krb5.conf
4545
KRB5_KTNAME=/etc/airflow.keytab
4646
backend_mysql: AIRFLOW__CORE__SQL_ALCHEMY_CONN=mysql://root@mysql/airflow
47+
backend_mysql: AIRFLOW__CELERY__RESULT_BACKEND=db+mysql://root@mysql/airflow
4748
backend_postgres: AIRFLOW__CORE__SQL_ALCHEMY_CONN=postgresql+psycopg2://postgres:airflow@postgres/airflow
49+
backend_postgres: AIRFLOW__CELERY__RESULT_BACKEND=db+postgresql://postgres:airflow@postgres/airflow
4850
backend_sqlite: AIRFLOW__CORE__SQL_ALCHEMY_CONN=sqlite:///{homedir}/airflow.db
4951
backend_sqlite: AIRFLOW__CORE__EXECUTOR=SequentialExecutor
5052

@@ -55,7 +57,7 @@ commands =
5557
pip install --progress-bar off --find-links={homedir}/.wheelhouse --no-index -e .[devel_ci]
5658
env_docker: {toxinidir}/scripts/ci/1-setup-env.sh
5759
env_docker: {toxinidir}/scripts/ci/2-setup-kdc.sh
58-
env_docker: {toxinidir}/scripts/ci/3-setup-databases.sh
60+
backend_mysql: {toxinidir}/scripts/ci/3-setup-mysql.sh
5961
{toxinidir}/scripts/ci/5-run-tests.sh []
6062
{toxinidir}/scripts/ci/6-check-license.sh
6163
codecov -e TOXENV

0 commit comments

Comments
 (0)