-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Framework] Handle ReadTimeout errors (#983)
# Description What - Handle ReadTimeout Errors Why - Requests to port or 3party apps may take a while, on the other hand we want to do out best effort to complete the resync How - Increased the httpx client timeout and not raise exceptions during batch upsert entities ## Type of change Please leave one option from the following and delete the rest: - [X] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] New Integration (non-breaking change which adds a new integration) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Non-breaking change (fix of existing functionality that will not change current behavior) - [ ] Documentation (added/updated documentation) <h4> All tests should be run against the port production environment(using a testing org). </h4> ### Core testing checklist - [x] Integration able to create all default resources from scratch - [x] Resync finishes successfully - [x] Resync able to create entities - [x] Resync able to update entities - [x] Resync able to detect and delete entities - [x] Scheduled resync able to abort existing resync and start a new one - [x] Tested with at least 2 integrations from scratch - [x] Tested with Kafka and Polling event listeners - [x] Tested deletion of entities that don't pass the selector ### Integration testing checklist - [ ] Integration able to create all default resources from scratch - [ ] Resync able to create entities - [ ] Resync able to update entities - [ ] Resync able to detect and delete entities - [ ] Resync finishes successfully - [ ] If new resource kind is added or updated in the integration, add example raw data, mapping and expected result to the `examples` folder in the integration directory. - [ ] If resource kind is updated, run the integration with the example data and check if the expected result is achieved - [ ] If new resource kind is added or updated, validate that live-events for that resource are working as expected - [ ] Docs PR link [here](#) ### Preflight checklist - [ ] Handled rate limiting - [ ] Handled pagination - [ ] Implemented the code in async - [ ] Support Multi account ## Screenshots Include screenshots from your environment showing how the resources of the integration will look. ## API Documentation Provide links to the API documentation used for this integration.
- Loading branch information
Showing
7 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,53 @@ | ||
from typing import Any | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
|
||
from port_ocean.clients.port.mixins.entities import EntityClientMixin | ||
from port_ocean.core.models import Entity | ||
from httpx import ReadTimeout | ||
|
||
|
||
errored_entity_identifier: str = "a" | ||
expected_result_entities = [ | ||
Entity(identifier="b", blueprint="b"), | ||
Entity(identifier="c", blueprint="c"), | ||
] | ||
all_entities = [ | ||
Entity(identifier=errored_entity_identifier, blueprint="a") | ||
] + expected_result_entities | ||
|
||
|
||
async def mock_upsert_entity(entity: Entity, *args: Any, **kwargs: Any) -> Entity: | ||
if entity.identifier == errored_entity_identifier: | ||
raise ReadTimeout("") | ||
else: | ||
return entity | ||
|
||
|
||
@pytest.fixture | ||
async def entity_client(monkeypatch: Any) -> EntityClientMixin: | ||
# Arrange | ||
entity_client = EntityClientMixin(auth=MagicMock(), client=MagicMock()) | ||
monkeypatch.setattr(entity_client, "upsert_entity", mock_upsert_entity) | ||
|
||
return entity_client | ||
|
||
|
||
async def test_batch_upsert_entities_read_timeout_should_raise_false( | ||
entity_client: EntityClientMixin, | ||
) -> None: | ||
result_entities = await entity_client.batch_upsert_entities( | ||
entities=all_entities, request_options=MagicMock(), should_raise=False | ||
) | ||
|
||
assert result_entities == expected_result_entities | ||
|
||
|
||
async def test_batch_upsert_entities_read_timeout_should_raise_true( | ||
entity_client: EntityClientMixin, | ||
) -> None: | ||
with pytest.raises(ReadTimeout): | ||
await entity_client.batch_upsert_entities( | ||
entities=all_entities, request_options=MagicMock(), should_raise=True | ||
) |
This file contains 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