kaxil commented on code in PR #44907:
URL: https://github.com/apache/airflow/pull/44907#discussion_r1890069049


##########
tests/api_fastapi/execution_api/routes/test_task_instances.py:
##########
@@ -286,6 +286,57 @@ def test_ti_update_state_to_deferred(self, client, 
session, create_task_instance
         assert t[0].classpath == "my-classpath"
         assert t[0].kwargs == {"key": "value"}
 
+    def test_ti_update_state_to_reschedule(self, client, session, 
create_task_instance, time_machine):
+        """
+        Test that tests if the transition to reschedule state is handled 
correctly.
+        """
+
+        from math import ceil
+
+        instant = timezone.datetime(2024, 10, 30)
+        time_machine.move_to(instant, tick=False)
+
+        ti = create_task_instance(
+            task_id="test_ti_update_state_to_reschedule",
+            state=State.RUNNING,
+            session=session,
+        )
+        ti.start_date = instant
+        ti.end_date = DEFAULT_END_DATE
+        session.commit()
+
+        payload = {
+            "state": "up_for_reschedule",
+            "reschedule_date": 
timezone.parse("2025-1-1T12:00:00Z").isoformat(),
+            "end_date": DEFAULT_END_DATE.isoformat(),
+        }
+
+        response = client.patch(f"/execution/task-instances/{ti.id}/state", 
json=payload)
+
+        assert response.status_code == 204
+        assert response.text == ""
+
+        session.expire_all()
+
+        tis = session.query(TaskInstance).all()
+        assert len(tis) == 1
+        assert tis[0].state == TaskInstanceState.UP_FOR_RESCHEDULE
+        assert tis[0].next_method is None
+        assert tis[0].next_kwargs is None
+        assert ceil(tis[0].duration) == 129600
+
+        trs = session.query(TaskReschedule).all()
+        assert len(trs) == 1
+        assert trs[0].dag_id == "dag"
+        assert trs[0].task_id == "test_ti_update_state_to_reschedule"
+        assert trs[0].run_id == "test"
+        assert trs[0].try_number == 0
+        assert trs[0].start_date == instant
+        assert trs[0].end_date == DEFAULT_END_DATE
+        assert trs[0].reschedule_date == timezone.parse("2025-1-1T12:00:00Z")
+        assert trs[0].map_index == -1
+        assert ceil(trs[0].duration) == 129600

Review Comment:
   We shouldn't need `ceil` anymore



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

To unsubscribe, e-mail: [email protected]

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

Reply via email to