damccorm opened a new pull request, #41207:
URL: https://github.com/apache/beam/pull/41207

   Fixes a flaky failure in `InteractiveBeamComputeTest.test_compute_blocking` 
(`ValueError: All PCollections must belong to the same pipeline.`) in 
`PostCommit Python Versions` (run 
https://github.com/apache/beam/actions/runs/42902232829).
   
   ### Root Cause
   In `InteractiveBeamComputeTest.test_async_computation_result_cancel`, 
`ib.compute(pcoll, blocking=False)` launched a real background thread in 
`RecordingManager._executor` running `time.sleep(100)` on `DirectRunner`, while 
the test exited after ~1.1s without waiting for the background thread to 
finish. Because `RecordingManager._execute_pipeline_fragment`, 
`PipelineFragment`, and `PipelineInstrument` call `ie.current_env()` globally, 
the leaked background thread from `test_async_computation_result_cancel` 
continued executing during the subsequent `test_compute_blocking` test and 
mutated `test_compute_blocking`'s `InteractiveEnvironment` / pipeline tracker. 
Additionally, `isolated_env.setUp` in `mock_env.py` started `self.ie_patcher` 
before assigning `self.m_current_env.return_value = self.current_env`, leaving 
a brief window where concurrent calls to `ie.current_env()` received an 
unconfigured `MagicMock`.
   
   ### Changes
   - In `InteractiveBeamComputeTest.test_async_computation_result_cancel`, 
patch `_execute_pipeline_fragment` with synchronization events 
(`threading.Event`) and wait for completion in `finally` so no background 
thread or 100s pipeline execution leaks into subsequent tests.
   - In `AsyncComputationResult.cancel`, guard `self._cancel_button.disabled = 
True` with `if self._cancel_button is not None:` when `IS_IPYTHON` is false.
   - In `mock_env.py`, pass `return_value=self.current_env` directly when 
constructing `self.ie_patcher` so `ie.current_env()` is never bound to an 
unconfigured mock.
   
   ### Verification
   - Triggered `beam_PostCommit_Python_Versions.yml` workflow run on branch: 
[`43023497457`](https://github.com/apache/beam/actions/runs/43023497457)
   


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