github-actions[bot] commented on code in PR #41824:
URL: https://github.com/apache/beam/pull/41824#discussion_r4747913489
##########
sdks/python/apache_beam/runners/interactive/interactive_beam_test.py:
##########
@@ -909,6 +909,7 @@ def test_async_computation_result_cancel(self):
# This part is hard to test without deeper runner integration
with self.assertRaises(TimeoutError):
async_result.result(timeout=1) # It should not complete successfully
+ async_result.wait_for_completion(timeout=30)
Review Comment:
**🟡 Medium**: If `time.sleep(0.1)` on line 898 finishes *before* the
background thread in `_execute_pipeline_fragment` reaches
`pipeline_to_run.run()` (which takes a few hundred milliseconds to deduce the
fragment and start the runner), the following sequence occurs:
1. The main thread sets
`async_result.set_pipeline_result(mock_pipeline_result)` and calls
`async_result.cancel()`, which sets `self._cancel_requested = True` and calls
`mock_pipeline_result.cancel()`.
2. Shortly after, the background thread reaches
`async_result.set_pipeline_result(pipeline_result)` with the real
`DirectRunner` result.
3. Because `self._cancel_requested` is `True`, `set_pipeline_result`
immediately invokes `self.cancel()` a second time on the real
`pipeline_result`, or if the real `set_pipeline_result` happens just before
line 905, `mock_pipeline_result` gets overwritten and
`mock_pipeline_result.cancel.assert_called_once()` fails.
Additionally, if the machine is heavily loaded and the pipeline takes >1s
just to reach `time.sleep(3)`, `async_result.result(timeout=1)` will still
pass, wait on `wait_for_completion(timeout=30)`, and finish cleanly, though
wrapping `wait_for_completion` in `try ... finally:` (or `self.addCleanup`)
would ensure the background thread is always joined even if an assertion
earlier in the test fails.
--
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]