Skip to content

Commit

Permalink
Merge pull request #1754 from fetchai/feature/conn_excep
Browse files Browse the repository at this point in the history
change default connection exception policy
  • Loading branch information
DavidMinarsch authored Sep 17, 2020
2 parents 62cf0bb + 7b651ab commit 45f7f2f
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion aea/aea.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(
DecisionMakerHandler
] = DefaultDecisionMakerHandler,
skill_exception_policy: ExceptionPolicyEnum = ExceptionPolicyEnum.propagate,
connection_exception_policy: ExceptionPolicyEnum = ExceptionPolicyEnum.just_log,
connection_exception_policy: ExceptionPolicyEnum = ExceptionPolicyEnum.propagate,
loop_mode: Optional[str] = None,
runtime_mode: Optional[str] = None,
default_connection: Optional[PublicId] = None,
Expand Down
2 changes: 1 addition & 1 deletion aea/aea_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class AEABuilder:
DecisionMakerHandler
] = DefaultDecisionMakerHandler
DEFAULT_SKILL_EXCEPTION_POLICY = ExceptionPolicyEnum.propagate
DEFAULT_CONNECTION_EXCEPTION_POLICY = ExceptionPolicyEnum.just_log
DEFAULT_CONNECTION_EXCEPTION_POLICY = ExceptionPolicyEnum.propagate
DEFAULT_LOOP_MODE = "async"
DEFAULT_RUNTIME_MODE = "threaded"
DEFAULT_SEARCH_SERVICE_ADDRESS = "fetchai/soef:*"
Expand Down
2 changes: 1 addition & 1 deletion aea/multiplexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(
connections: Optional[Sequence[Connection]] = None,
default_connection_index: int = 0,
loop: Optional[AbstractEventLoop] = None,
exception_policy: ExceptionPolicyEnum = ExceptionPolicyEnum.just_log,
exception_policy: ExceptionPolicyEnum = ExceptionPolicyEnum.propagate,
):
"""
Initialize the connection multiplexer.
Expand Down
2 changes: 1 addition & 1 deletion aea/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def multiplexer(self) -> Multiplexer:
def _get_multiplexer_instance(self) -> Multiplexer:
"""Create multiplexer instance."""
exception_policy = getattr(
self._agent, "_connection_exception_policy", ExceptionPolicyEnum.just_log
self._agent, "_connection_exception_policy", ExceptionPolicyEnum.propagate
)
return Multiplexer(
self._agent.connections, loop=self.loop, exception_policy=exception_policy
Expand Down
2 changes: 1 addition & 1 deletion docs/api/aea.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This class implements an autonomous economic agent.
```python
| __init__(identity: Identity, wallet: Wallet, resources: Resources, loop: Optional[AbstractEventLoop] = None, period: float = 0.05, execution_timeout: float = 0, max_reactions: int = 20, decision_maker_handler_class: Type[
| DecisionMakerHandler
| ] = DefaultDecisionMakerHandler, skill_exception_policy: ExceptionPolicyEnum = ExceptionPolicyEnum.propagate, connection_exception_policy: ExceptionPolicyEnum = ExceptionPolicyEnum.just_log, loop_mode: Optional[str] = None, runtime_mode: Optional[str] = None, default_connection: Optional[PublicId] = None, default_routing: Optional[Dict[PublicId, PublicId]] = None, connection_ids: Optional[Collection[PublicId]] = None, search_service_address: str = "fetchai/soef:*", **kwargs, ,) -> None
| ] = DefaultDecisionMakerHandler, skill_exception_policy: ExceptionPolicyEnum = ExceptionPolicyEnum.propagate, connection_exception_policy: ExceptionPolicyEnum = ExceptionPolicyEnum.propagate, loop_mode: Optional[str] = None, runtime_mode: Optional[str] = None, default_connection: Optional[PublicId] = None, default_routing: Optional[Dict[PublicId, PublicId]] = None, connection_ids: Optional[Collection[PublicId]] = None, search_service_address: str = "fetchai/soef:*", **kwargs, ,) -> None
```

Instantiate the agent.
Expand Down
2 changes: 1 addition & 1 deletion docs/api/multiplexer.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ This class can handle multiple connections at once.
#### `__`init`__`

```python
| __init__(connections: Optional[Sequence[Connection]] = None, default_connection_index: int = 0, loop: Optional[AbstractEventLoop] = None, exception_policy: ExceptionPolicyEnum = ExceptionPolicyEnum.just_log)
| __init__(connections: Optional[Sequence[Connection]] = None, default_connection_index: int = 0, loop: Optional[AbstractEventLoop] = None, exception_policy: ExceptionPolicyEnum = ExceptionPolicyEnum.propagate)
```

Initialize the connection multiplexer.
Expand Down
1 change: 1 addition & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ execution_timeout: 0 # The execution time limit on ea
timeout: 0.05 # The sleep time on each AEA loop spin (only relevant for the `sync` mode)
max_reactions: 20 # The maximum number of envelopes processed per call to `react` (only relevant for the `sync` mode)
skill_exception_policy: propagate # The exception policy applied to skills (must be one of "propagate", "just_log", or "stop_and_exit")
connection_exception_policy: propagate # The exception policy applied to connections (must be one of "propagate", "just_log", or "stop_and_exit")
default_routing: {} # The default routing scheme applied to envelopes sent by the AEA, it maps from protocol public ids to connection public ids (both keys and values must satisfy PUBLIC_ID_REGEX)
loop_mode: async # The agent loop mode (must be one of "sync" or "async")
runtime_mode: threaded # The runtime mode (must be one of "threaded" or "async") and determines how agent loop and multiplexer are run
Expand Down
2 changes: 1 addition & 1 deletion tests/test_configurations/test_aea_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class TestConnectionExceptionPolicyConfigVariable(BaseConfigTestVariable):
INCORRECT_VALUES = [None, "sTrING?", -1]
REQUIRED = False
AEA_ATTR_NAME = "_connection_exception_policy"
AEA_DEFAULT_VALUE = ExceptionPolicyEnum.just_log
AEA_DEFAULT_VALUE = ExceptionPolicyEnum.propagate


class TestRuntimeModeConfigVariable(BaseConfigTestVariable):
Expand Down
1 change: 1 addition & 0 deletions tests/test_docs/test_bash_yaml/md_files/bash-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ execution_timeout: 0 # The execution time limit on ea
timeout: 0.05 # The sleep time on each AEA loop spin (only relevant for the `sync` mode)
max_reactions: 20 # The maximum number of envelopes processed per call to `react` (only relevant for the `sync` mode)
skill_exception_policy: propagate # The exception policy applied to skills (must be one of "propagate", "just_log", or "stop_and_exit")
connection_exception_policy: propagate # The exception policy applied to connections (must be one of "propagate", "just_log", or "stop_and_exit")
default_routing: {} # The default routing scheme applied to envelopes sent by the AEA, it maps from protocol public ids to connection public ids (both keys and values must satisfy PUBLIC_ID_REGEX)
loop_mode: async # The agent loop mode (must be one of "sync" or "async")
runtime_mode: threaded # The runtime mode (must be one of "threaded" or "async") and determines how agent loop and multiplexer are run
Expand Down
8 changes: 4 additions & 4 deletions tests/test_multiplexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,19 +612,19 @@ def teardown(self):
"""Tear down test case."""
self.multiplexer.disconnect()

def test_default_policy(self):
def test_log_policy(self):
"""Test just log exception."""
assert self.multiplexer._exception_policy == ExceptionPolicyEnum.just_log

with patch.object(self.connection, "send", side_effect=self.exception):
self.multiplexer._exception_policy = ExceptionPolicyEnum.just_log
self.multiplexer.put(self.envelope)
time.sleep(1)
assert not self.multiplexer._send_loop_task.done()

def test_propagate_policy(self):
"""Test propagate exception."""
assert self.multiplexer._exception_policy == ExceptionPolicyEnum.propagate

with patch.object(self.connection, "send", side_effect=self.exception):
self.multiplexer._exception_policy = ExceptionPolicyEnum.propagate
self.multiplexer.put(self.envelope)
time.sleep(1)
wait_for_condition(
Expand Down

0 comments on commit 45f7f2f

Please sign in to comment.