pabloem commented on a change in pull request #11389: Refactor the BCJ and
capture controls to be more testable
URL: https://github.com/apache/beam/pull/11389#discussion_r407689487
##########
File path:
sdks/python/apache_beam/runners/interactive/interactive_runner_test.py
##########
@@ -196,6 +197,28 @@ def process(self, element):
# applied but needs an IPython environment. So we manually run this here.
ie.current_env().track_user_pipelines()
+ # Create a fake limiter that cancels the BCJ once the main job receives the
+ # expected amount of results.
+ class FakeLimiter:
+ def __init__(self, p, pcoll):
+ self.p = p
+ self.pcoll = pcoll
+
+ def is_triggered(self):
+ result = ie.current_env().pipeline_result(self.p)
+ if result:
+ try:
+ results = result.get(self.pcoll)
+ except ValueError:
+ return False
+ return len(results) >= 10
+ return False
+
+ # This sets the limiters to stop reading when the test receives 10 elements
+ # or after 5 seconds have elapsed (to eliminate the possibility of
hanging).
+ ie.current_env().options.capture_control.set_limiters_for_test(
+ [FakeLimiter(p, data), DurationLimiter(timedelta(seconds=5))])
Review comment:
IIUC, the test will run at most for 5 seconds (at least .5 from the sleep
time of the BCJ checker, right?), but will pass as soon as `>= 10` elements are
available, right?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services