Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout add unit test #109

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions tests/models/test_dagbag.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,46 @@ def test_serialized_dag_errors_are_import_errors(self, mock_serialize, caplog):
assert "SerializationError" in err
session.rollback()

def test_timeout_dag_errors_are_import_errors(self, tmp_path, caplog):
"""
Test that if the DAG contains Timeout error it will be still loaded to DB as import_errors
"""
code_to_save = """
# Define Dag to load
import datetime
import time

import airflow
from airflow.operators.python import PythonOperator

time.sleep(31)

with airflow.DAG(
"import_timeout",
start_date=datetime.datetime(2022, 1, 1),
schedule=None) as dag:
def f():
print("Sleeping")
time.sleep(2)


for ind in range(10):
PythonOperator(
dag=dag,
task_id=f"sleep_2_{ind}",
python_callable=f,
)
"""
with open("tmp_file.py", "w") as f:
f.write(code_to_save)

dagbag = DagBag(dag_folder=os.fspath("tmp_file.py"), include_examples=False)
dag = dagbag._load_modules_from_file("tmp_file.py", safe_mode=False)

assert dag is not None
assert "tmp_file.py" in dagbag.import_errors
assert "DagBag import timeout for" in caplog.text

@patch("airflow.models.dagbag.DagBag.collect_dags")
@patch("airflow.models.serialized_dag.SerializedDagModel.write_dag")
@patch("airflow.models.dag.DAG.bulk_write_to_db")
Expand Down
Loading