Repository navigation
Conversation
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR cleanly resolves a test flake in InteractiveBeamComputeTest caused by test_async_computation_result_cancel leaking a 100s background execution thread into subsequent tests. By synchronizing on _execute_pipeline_fragment with threading.Event and ensuring isolated_env.setUp initializes return_value atomically when patching ie.current_env, cross-test state contamination is prevented.
🔍 General Feedback
- The synchronization pattern using
started_eventandrelease_eventwith cleanup in afinallyblock makes the cancellation test deterministic and eliminates the arbitrarytime.sleepdelays. - Guarding
self._cancel_buttonagainstNoneinAsyncComputationResult.cancel()properly handles non-IPython environments whenIS_IPYTHONisFalse.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR resolves a flaky test failure in InteractiveBeamComputeTest caused by test_async_computation_result_cancel leaking a 100-second background thread into subsequent tests. The fix cleanly replaces the time.sleep(100) pipeline execution with a synchronized mock of _execute_pipeline_fragment that is properly joined in a finally block, while also closing a brief mock initialization window in isolated_env.setUp and guarding _cancel_button access when IS_IPYTHON is false.
🔍 General Feedback
- Using
threading.Eventprimitives (started_eventandrelease_event) paired withwait_for_completioninfinallymakestest_async_computation_result_canceldeterministic and eliminates cross-test interference. - Passing
return_value=self.current_envdirectly topatch(...)inmock_env.pypreventsie.current_env()from briefly returning an unconfiguredMagicMockduringsetUp.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #41207 +/- ##
============================================
- Coverage 59.25% 59.15% -0.10%
Complexity 4894 4894
============================================
Files 1461 1461
Lines 186046 186191 +145
Branches 3648 3648
============================================
- Hits 110244 110146 -98
- Misses 72445 72688 +243
Partials 3357 3357
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…for_completion
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR resolves a test flake in InteractiveBeamComputeTest where test_async_computation_result_cancel leaked a background pipeline execution thread running time.sleep(100) into subsequent tests. By mocking RecordingManager._execute_pipeline_fragment with a short sleep and awaiting completion before the test exits, the change cleanly eliminates cross-test pollution of the global InteractiveEnvironment.
🔍 General Feedback
- The root cause analysis and fix are spot-on. Mocking
_execute_pipeline_fragmentand explicitly callingwait_for_completionensures deterministic cleanup of the background worker thread beforeisolated_envtears down the test environment.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
…t_async_computation_result_cancel
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR fixes a flaky test failure in InteractiveBeamComputeTest where test_async_computation_result_cancel leaked a long-running background pipeline computation (time.sleep(100)) into subsequent tests, mutating their InteractiveEnvironment. Shortening the sleep duration to 3 seconds and awaiting async_result.wait_for_completion(timeout=30) before exiting the test cleanly resolves the background execution leak.
🔍 General Feedback
- The fix is minimal, targeted, and directly addresses the cross-test state contamination while preserving the test's verification of in-flight cancellation behavior.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
| # 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) |
There was a problem hiding this comment.
Instead of waiting for completion, is there a way to actually force cancel the job? Then we could reraise the time.sleep to 100
There was a problem hiding this comment.
Under InteractiveRunner (which delegates to DirectRunner -> FnApiRunner), pipeline_to_run.run() executes the pipeline synchronously in-process on the RecordingManager._executor ThreadPoolExecutor worker thread before run() even returns a PipelineResult (recording_manager.py:491). Because Python's ThreadPoolExecutor / threading.Thread cannot forcibly interrupt a running thread that is already blocked inside a C-level time.sleep(100) (Future.cancel() only cancels futures that haven't started running yet), and because line 911 (with self.assertRaises(TimeoutError): async_result.result(timeout=1)) explicitly tests that the background thread is still running after async_result.cancel() returns, cancel() itself cannot kill time.sleep(100).
However, we can keep the 100s timeout AND immediately unblock the worker thread during cleanup by replacing time.sleep(100) with a threading.Event wait (InteractiveBeamComputeTest._cancel_event.wait(100), using a class attribute so the Map lambda isn't rejected by PipelineFragment runner-API pickling) and calling InteractiveBeamComputeTest._cancel_event.set() in a finally: block right before async_result.wait_for_completion(timeout=30). I have applied and verified this locally on the branch.
Note: this PR was auto-generated by tooling. Before moving it out of draft, the author has done a full review of the PR, specifically evaluating it on the following criteria:
Full details of the methodology of generation and review can be found here - https://docs.google.com/document/d/14lj7ECVov4T4EdwmIzNlWrRGE3lLDMOwX5xUMGzaLoc/edit?usp=sharing
If you have concerns with the PR or with the underlying methodology used to generate this, please comment below - they will be addressed by the author not the tooling :)
Fixes a flaky failure in
InteractiveBeamComputeTest.test_compute_blocking(ValueError: All PCollections must belong to the same pipeline.) inPostCommit Python Versions(run 42902232829).Root Cause
In
InteractiveBeamComputeTest.test_async_computation_result_cancel,ib.compute(pcoll, blocking=False)launched a real background thread inRecordingManager._executorrunningtime.sleep(100)onDirectRunner, while the test exited after ~1.1s without waiting for the background thread to finish. Then, the leaked background thread fromtest_async_computation_result_cancelcontinued executing during the subsequenttest_compute_blockingtest and mutatedtest_compute_blocking'sInteractiveEnvironment/ pipeline tracker.Changes
InteractiveBeamComputeTest.test_async_computation_result_cancel, shorten thebeam.Mapsleep fromtime.sleep(100)totime.sleep(3)and callasync_result.wait_for_completion(timeout=30)at the end of the test so the real_execute_pipeline_fragmentruns while ensuring no background thread or pipeline execution leaks into subsequent tests.Verification
InteractiveBeamComputeTestsuite (17/17 passed).beam_PostCommit_Python_Versions.ymlworkflow run on branch:43440309029