kaxil commented on a change in pull request #9851:
URL: https://github.com/apache/airflow/pull/9851#discussion_r456393768



##########
File path: tests/models/test_dagbag.py
##########
@@ -657,3 +659,41 @@ def test_serialized_dags_are_written_to_db_on_sync(self):
 
             new_serialized_dags_count = 
session.query(func.count(SerializedDagModel.dag_id)).scalar()
             self.assertEqual(new_serialized_dags_count, 1)
+
+    @patch("airflow.models.dagbag.settings.STORE_SERIALIZED_DAGS", True)
+    
@patch("airflow.models.dagbag.settings.MIN_SERIALIZED_DAG_UPDATE_INTERVAL", 5)
+    @patch("airflow.models.dagbag.settings.MIN_SERIALIZED_DAG_FETCH_INTERVAL", 
5)
+    def test_get_dag_with_dag_serialization(self):
+        """
+        Test that Serialized DAG is updated in DagBag when it is updated in
+        Serialized DAG table after 'min_serialized_dag_fetch_interval' seconds 
are passed.
+        """
+
+        with freeze_time(tz.datetime(2020, 1, 5, 0, 0, 0)):
+            example_bash_op_dag = 
DagBag(include_examples=True).dags.get("example_bash_operator")
+            SerializedDagModel.write_dag(dag=example_bash_op_dag)
+
+        dag_bag = DagBag(read_dags_from_db=True)
+        ser_dag_1 = dag_bag.get_dag("example_bash_operator")
+        ser_dag_1_update_time = 
dag_bag.dags_last_changed["example_bash_operator"]
+        self.assertEqual(example_bash_op_dag.tags, ser_dag_1.tags)
+        self.assertEqual(ser_dag_1_update_time, tz.datetime(2020, 1, 5, 0, 0, 
0))
+
+        # Check that if min_serialized_dag_fetch_interval has not passed we do 
not fetch the DAG
+        # from DB
+        with freeze_time(tz.datetime(2020, 1, 5, 0, 0, 4)):
+            self.assertEqual(dag_bag.get_dag("example_bash_operator").tags, 
["example"])

Review comment:
       Updated in 
https://github.com/apache/airflow/pull/9851/commits/02856d63a5d500788c8aab7c49a235b036800364




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to