This is an automated email from the ASF dual-hosted git repository.

jscheffl pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new b0921fe6657 Fix flaky AzureDataFactory operator test by mocking time 
(#67427)
b0921fe6657 is described below

commit b0921fe6657fe51509d0f3bf88c618dc4bee50ec
Author: Shubham Raj <[email protected]>
AuthorDate: Mon May 25 01:06:55 2026 +0530

    Fix flaky AzureDataFactory operator test by mocking time (#67427)
    
    The test_execute_wait_for_termination[*-timeout] cases relied on real
    wall-clock time.sleep(1) calls with timeout=3, expecting exactly 4
    get_pipeline_run calls. On loaded CI machines where time.sleep(1)
    overshoots by >0.5s, only 2 loop iterations complete before the
    3-second timeout fires, giving 3 calls instead of 4.
    
    Fix by patching time.monotonic (via itertools.count) and time.sleep
    in the hook module, making the iteration count deterministic regardless
    of system load.
---
 .../microsoft/azure/operators/test_data_factory.py   | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git 
a/providers/microsoft/azure/tests/unit/microsoft/azure/operators/test_data_factory.py
 
b/providers/microsoft/azure/tests/unit/microsoft/azure/operators/test_data_factory.py
index b94c34faff5..c6403030480 100644
--- 
a/providers/microsoft/azure/tests/unit/microsoft/azure/operators/test_data_factory.py
+++ 
b/providers/microsoft/azure/tests/unit/microsoft/azure/operators/test_data_factory.py
@@ -17,6 +17,7 @@
 from __future__ import annotations
 
 import functools
+import itertools
 from typing import TYPE_CHECKING
 from unittest import mock
 from unittest.mock import MagicMock, patch
@@ -142,11 +143,20 @@ class TestAzureDataFactoryRunPipelineOperator:
                     operator.execute(context=self.mock_context)
             else:
                 # Demonstrating the operator timing out after surpassing the 
configured timeout value.
-                with pytest.raises(
-                    AzureDataFactoryPipelineRunException,
-                    match=(
-                        f"Pipeline run {PIPELINE_RUN_RESPONSE['run_id']} has 
not reached a terminal status "
-                        f"after {self.config['timeout']} seconds."
+                # Mock time.monotonic and time.sleep so the poll count is 
deterministic regardless of
+                # CI load; real sleep durations can vary enough to change how 
many iterations complete.
+                with (
+                    patch(
+                        
"airflow.providers.microsoft.azure.hooks.data_factory.time.monotonic",
+                        side_effect=itertools.count(0.0, 1.0),
+                    ),
+                    
patch("airflow.providers.microsoft.azure.hooks.data_factory.time.sleep"),
+                    pytest.raises(
+                        AzureDataFactoryPipelineRunException,
+                        match=(
+                            f"Pipeline run {PIPELINE_RUN_RESPONSE['run_id']} 
has not reached a terminal status "
+                            f"after {self.config['timeout']} seconds."
+                        ),
                     ),
                 ):
                     operator.execute(context=self.mock_context)

Reply via email to