-
Couldn't load subscription status.
- Fork 0
Implement connect() and disconnect() #5
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
Merged
mikeprosserni
merged 17 commits into
main
from
users/mprosser/task-3095680-connect-disconnect
Apr 26, 2025
Merged
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c971b3a
first draft (breaks tests)
394b74a
PanelNotFoundError when gRPC status code is NOT_FOUND
5d5404f
fix linter issues
d0835f1
create a basic fake server and passing basic tests for it
fc049cc
use FakePanel to fix failing tests
a6c76d6
move fixture to conftest.py
bb5ea94
remove unused serve() function
a7e4914
cleanup
c7f5f78
use a channel pool
d971106
add a retry if connect fails, and remove PanelNotFoundError
426aa54
cleanup
74847dc
refactor to use PanelClient
e3bc460
misc feedback and FakePythonPanelService
13cc155
PanelClient cleanup
2e1aeb2
use channel parameter for testing instead of PortPanel, and move prov…
5b0cf66
misc feedback
5f873b7
don't return tuples from fixtures
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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 |
|---|---|---|
| @@ -1,37 +1,42 @@ | ||
| """Fixtures for testing.""" | ||
|
|
||
| from collections.abc import Generator | ||
| from concurrent import futures | ||
| from typing import Any, Generator | ||
|
|
||
| import grpc | ||
| import pytest | ||
| from ni.pythonpanel.v1.python_panel_service_pb2_grpc import ( | ||
| PythonPanelServiceStub, | ||
| add_PythonPanelServiceServicer_to_server, | ||
| ) | ||
|
|
||
| from tests.utils._fake_python_panel_servicer import FakePythonPanelServicer | ||
| from tests.utils._fake_python_panel_service import FakePythonPanelService | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def fake_python_panel_service() -> Generator[tuple[FakePythonPanelServicer, int], Any, None]: | ||
| def fake_python_panel_service() -> Generator[FakePythonPanelService]: | ||
| """Fixture to create a FakePythonPanelServicer for testing.""" | ||
| thread_pool = futures.ThreadPoolExecutor(max_workers=10) | ||
| server = grpc.server(thread_pool) | ||
| servicer = FakePythonPanelServicer() | ||
| add_PythonPanelServiceServicer_to_server(servicer, server) | ||
| port = server.add_insecure_port("[::]:0") | ||
| server.start() | ||
| yield servicer, port | ||
| server.stop(None) | ||
| with futures.ThreadPoolExecutor(max_workers=10) as thread_pool: | ||
| service = FakePythonPanelService() | ||
| service.start(thread_pool) | ||
| yield service | ||
| service.stop() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def fake_python_panel_service_stub( | ||
| fake_python_panel_service: tuple[FakePythonPanelServicer, int], | ||
| ) -> Generator[PythonPanelServiceStub, Any, None]: | ||
| """Fixture to attach a PythonPanelSericeStub to a FakePythonPanelService.""" | ||
| _, port = fake_python_panel_service | ||
| channel = grpc.insecure_channel(f"localhost:{port}") | ||
| yield PythonPanelServiceStub(channel) | ||
| def grpc_channel_and_fake_panel_service( | ||
| fake_python_panel_service: FakePythonPanelService, | ||
| ) -> Generator[tuple[grpc.Channel, FakePythonPanelService]]: | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Fixture to get a channel to the FakePythonPanelService.""" | ||
| service = fake_python_panel_service | ||
| channel = grpc.insecure_channel(f"localhost:{service.port}") | ||
| yield channel, service | ||
| channel.close() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def python_panel_service_stub( | ||
| grpc_channel_and_fake_panel_service: tuple[grpc.Channel, FakePythonPanelService], | ||
| ) -> Generator[PythonPanelServiceStub]: | ||
| """Fixture to get a PythonPanelServiceStub, attached to a FakePythonPanelService.""" | ||
| channel, _ = grpc_channel_and_fake_panel_service | ||
| yield PythonPanelServiceStub(channel) | ||
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.