This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-8960-6db4a642d0c9eabbc56c2c9a10a61b72da9af064 in repository https://gitbox.apache.org/repos/asf/texera.git
commit a0ab2dc300a3bfdc9cbdd28737074964a93a3fcd Author: carloea2 <[email protected]> AuthorDate: Wed Nov 11 04:37:43 2026 +0000 fix(pyamber): keep peek side effect free (#8960) ### What changes were proposed in this PR? Keep queue peeking from advancing the round-robin cursor. Scan with a local index so observing a queue does not change the next message returned by `get()`. The regression also starts at a nonzero cursor and calls the public `peek()` while wrapping past empty and disabled queues in either order. Repeated peeks preserve the next `get()` result, and an unavailable queue returns `None`. ### Any related issues, documentation, discussions? Closes #8225. Replaces #8226, which the stale bot closed. ### How was this PR tested? Retested with Python 3.12 on Windows from freshly fetched upstream main `1ec692c5da`. Before the implementation, the original regression and both new wraparound cases fail. Afterward, all 56 customized-queue tests pass. From `amber`, with `PYTHONPATH=src/main/python`: ```text python -m pytest src/test/python/core/util/customized_queue -q --tb=short -p no:cacheprovider 56 passed python -m pytest src/test/python/core/util src/test/python/core/architecture src/test/python/core/runnables --deselect=src/test/python/core/util/test_expression_evaluator.py::TestExpressionEvaluator::test_evaluate_object_expression --deselect=src/test/python/core/util/test_expression_evaluator.py::TestExpressionEvaluator::test_evaluate_container_expressions -q --tb=short -p no:cacheprovider 716 passed, 2 deselected ruff check src/main/python src/test/python ruff format --check src/main/python src/test/python ``` The two deselected expression-evaluator tests also fail on unmodified main on Windows because object addresses in `repr()` have leading zeros. No expression-evaluator code changed. Ruff lint and formatting passed for all 218 Python files. `git diff --check` passed. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Codex (GPT-6) --- .../linked_blocking_multi_queue.py | 11 +++----- .../test_linked_blocking_multi_queue.py | 32 +++++++++++++++++++--- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/amber/src/main/python/core/util/customized_queue/linked_blocking_multi_queue.py b/amber/src/main/python/core/util/customized_queue/linked_blocking_multi_queue.py index fcf175d6bc..561b1680cf 100644 --- a/amber/src/main/python/core/util/customized_queue/linked_blocking_multi_queue.py +++ b/amber/src/main/python/core/util/customized_queue/linked_blocking_multi_queue.py @@ -227,16 +227,13 @@ class LinkedBlockingMultiQueue(IKeyedQueue): return None def peek(self) -> Optional[T]: - start_idx = self.next_idx + idx = self.next_idx while True: - child = self.queues[self.next_idx] + child = self.queues[idx] if child.enabled and child.size() > 0: return child.head.next.item - else: - self.next_idx += 1 - if self.next_idx == len(self.queues): - self.next_idx = 0 - if self.next_idx == start_idx: + idx = (idx + 1) % len(self.queues) + if idx == self.next_idx: break return None diff --git a/amber/src/test/python/core/util/customized_queue/test_linked_blocking_multi_queue.py b/amber/src/test/python/core/util/customized_queue/test_linked_blocking_multi_queue.py index 8cdaada6bd..8096972c1d 100644 --- a/amber/src/test/python/core/util/customized_queue/test_linked_blocking_multi_queue.py +++ b/amber/src/test/python/core/util/customized_queue/test_linked_blocking_multi_queue.py @@ -273,7 +273,7 @@ class TestPeek: queue.disable("data") assert queue.peek() is None - def test_priority_group_peek_perturbs_round_robin_state(self): + def test_priority_group_peek_preserves_round_robin_state(self): lbmq = LinkedBlockingMultiQueue() lbmq.add_sub_queue("first", 1) lbmq.add_sub_queue("second", 1) @@ -282,14 +282,38 @@ class TestPeek: assert group.next_idx == 0 assert group.peek() == "s" - # Skipping the empty `first` queue advanced next_idx, so peek is not - # side-effect free on the group's round-robin cursor. - assert group.next_idx == 1 + assert group.next_idx == 0 + + lbmq.put("first", "f") + assert lbmq.get() == "f" def test_priority_group_peek_returns_none_when_all_queues_empty(self, queue): group = queue.get_sub_queue("control").priority_group assert group.peek() is None + @pytest.mark.parametrize("disabled_first", [False, True]) + def test_public_peek_preserves_cursor_when_wrapping(self, disabled_first): + lbmq = LinkedBlockingMultiQueue() + for name in ("first", "second", "third"): + lbmq.add_sub_queue(name, 1) + lbmq.put("first", "initial") + assert lbmq.get() == "initial" + + lbmq.put("first", "first") + disabled = "second" if disabled_first else "third" + lbmq.put(disabled, disabled) + lbmq.disable(disabled) + assert lbmq.peek() == "first" + assert lbmq.peek() == "first" + + if disabled_first: + lbmq.enable("second") + else: + lbmq.put("second", "second") + assert lbmq.get() == "second" + assert lbmq.get() == "first" + assert lbmq.peek() is None + def test_selection_peek_returns_first_non_none_across_groups(self, queue): queue.put("data", 1) assert queue.sub_queue_selection.peek() == 1
