-
Notifications
You must be signed in to change notification settings - Fork 169
fix(pyamber): stop EndWorker from consuming straggler messages #6522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aglinxinyuan
wants to merge
3
commits into
apache:main
Choose a base branch
from
aglinxinyuan:end-worker-straggler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+110
−7
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
b352eb1
fix+test(pyamber): stop EndWorker from consuming straggler messages
aglinxinyuan 87d618b
refactor(pyamber): address review — drop InternalQueue.peek, keep IQueue
aglinxinyuan bbbb779
fix(pyamber): type EndWorker queue as InternalQueue and read the coun…
aglinxinyuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
amber/src/test/python/core/architecture/handlers/control/test_end_worker_handler.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| import asyncio | ||
| from types import SimpleNamespace | ||
|
|
||
| import pytest | ||
|
|
||
| from core.architecture.handlers.control.end_worker_handler import EndWorkerHandler | ||
| from core.models.internal_queue import DCMElement, InternalQueue | ||
| from proto.org.apache.texera.amber.core import ActorVirtualIdentity, ChannelIdentity | ||
| from proto.org.apache.texera.amber.engine.architecture.rpc import ( | ||
| EmptyRequest, | ||
| EmptyReturn, | ||
| ) | ||
| from proto.org.apache.texera.amber.engine.common import DirectControlMessagePayloadV2 | ||
|
|
||
|
|
||
| class TestEndWorkerHandler: | ||
| @pytest.fixture | ||
| def input_queue(self): | ||
| return InternalQueue() | ||
|
|
||
| @pytest.fixture | ||
| def handler(self, input_queue): | ||
| # ControlHandler.__init__ just stashes context; bypass the protobuf | ||
| # base class' __init__ by constructing via __new__. | ||
| instance = EndWorkerHandler.__new__(EndWorkerHandler) | ||
| instance.context = SimpleNamespace(input_queue=input_queue) | ||
| return instance | ||
|
|
||
| @staticmethod | ||
| def make_control_message(seq: int) -> DCMElement: | ||
| channel = ChannelIdentity( | ||
| ActorVirtualIdentity(name="CONTROLLER"), | ||
| ActorVirtualIdentity(name=f"worker-{seq}"), | ||
| is_control=True, | ||
| ) | ||
| return DCMElement(tag=channel, payload=DirectControlMessagePayloadV2()) | ||
|
|
||
| def test_acknowledges_end_worker_on_empty_queue(self, handler): | ||
| result = asyncio.run(handler.end_worker(EmptyRequest())) | ||
| assert isinstance(result, EmptyReturn) | ||
|
|
||
| def test_rejects_end_worker_with_one_unprocessed_message( | ||
| self, handler, input_queue | ||
| ): | ||
| # The controller resolves endWorker's reply as a failed future and | ||
| # retries after the queue drains (terminateWorkersWithRetry), so a | ||
| # straggler message must fail the call — not be dropped with a | ||
| # successful acknowledgement. | ||
| input_queue.put(self.make_control_message(0)) | ||
| with pytest.raises(RuntimeError, match="unprocessed messages"): | ||
| asyncio.run(handler.end_worker(EmptyRequest())) | ||
|
|
||
| @pytest.mark.timeout(2) | ||
| def test_does_not_consume_the_unprocessed_message(self, handler, input_queue): | ||
| straggler = self.make_control_message(0) | ||
| input_queue.put(straggler) | ||
| with pytest.raises(RuntimeError): | ||
| asyncio.run(handler.end_worker(EmptyRequest())) | ||
| # The straggler must survive the failed call so the main loop can | ||
| # still process it before the controller's retry. | ||
| assert input_queue.size() == 1 | ||
| assert input_queue.get() is straggler | ||
|
|
||
| def test_keeps_all_messages_with_multiple_stragglers(self, handler, input_queue): | ||
| input_queue.put(self.make_control_message(0)) | ||
| input_queue.put(self.make_control_message(1)) | ||
| with pytest.raises(RuntimeError): | ||
| asyncio.run(handler.end_worker(EmptyRequest())) | ||
| assert input_queue.size() == 2 | ||
|
|
||
| @pytest.mark.timeout(2) | ||
| def test_succeeds_after_queue_drains(self, handler, input_queue): | ||
| # The retry protocol end-to-end: fail while a message is pending, | ||
| # acknowledge once the queue has drained. | ||
| input_queue.put(self.make_control_message(0)) | ||
| with pytest.raises(RuntimeError): | ||
| asyncio.run(handler.end_worker(EmptyRequest())) | ||
| input_queue.get() | ||
| result = asyncio.run(handler.end_worker(EmptyRequest())) | ||
| assert isinstance(result, EmptyReturn) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.