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



##########
File path: tests/models/test_dagbag.py
##########
@@ -657,3 +659,35 @@ 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)
+    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_UPDATE_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))
+
+        with freeze_time(tz.datetime(2020, 1, 5, 0, 0, 6)):
+            example_bash_op_dag.tags += ["new_tag"]
+            SerializedDagModel.write_dag(dag=example_bash_op_dag)
+
+        with freeze_time(tz.datetime(2020, 1, 5, 0, 0, 4)):
+            self.assertEqual(dag_bag.get_dag("example_bash_operator").tags, 
["example"])

Review comment:
       Can you add a comment in here explaining what we're testing? (This is 
that the update interval hasn't passed, so we don't re-get it?)
   
   It also looks a bit off that this goes "back" in time from the previous 
statements.




----------------------------------------------------------------
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