-
Notifications
You must be signed in to change notification settings - Fork 2.8k
refactor(mcp):used logger to log instead of print and updated unittes… #4324
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
01be269
3a19d07
ed9c451
ceee2b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -388,7 +388,8 @@ async def test_close_success(self): | |||||||||||||||
| assert len(manager._sessions) == 0 | ||||||||||||||||
|
|
||||||||||||||||
| @pytest.mark.asyncio | ||||||||||||||||
| async def test_close_with_errors(self): | ||||||||||||||||
| @patch("google.adk.tools.mcp_tool.mcp_session_manager.logger") | ||||||||||||||||
| async def test_close_with_errors(self, mock_logger): | ||||||||||||||||
| """Test cleanup when some sessions fail to close.""" | ||||||||||||||||
| manager = MCPSessionManager(self.mock_stdio_connection_params) | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -403,20 +404,17 @@ async def test_close_with_errors(self): | |||||||||||||||
| manager._sessions["session1"] = (session1, exit_stack1) | ||||||||||||||||
| manager._sessions["session2"] = (session2, exit_stack2) | ||||||||||||||||
|
|
||||||||||||||||
| custom_errlog = StringIO() | ||||||||||||||||
| manager._errlog = custom_errlog | ||||||||||||||||
|
|
||||||||||||||||
| # Should not raise exception | ||||||||||||||||
| await manager.close() | ||||||||||||||||
|
|
||||||||||||||||
| # Good session should still be closed | ||||||||||||||||
| exit_stack2.aclose.assert_called_once() | ||||||||||||||||
| assert len(manager._sessions) == 0 | ||||||||||||||||
|
|
||||||||||||||||
| # Error should be logged | ||||||||||||||||
| error_output = custom_errlog.getvalue() | ||||||||||||||||
| assert "Warning: Error during MCP session cleanup" in error_output | ||||||||||||||||
| assert "Close error 1" in error_output | ||||||||||||||||
| # Error should be logged via logger.warning | ||||||||||||||||
| mock_logger.warning.assert_called() | ||||||||||||||||
| warning_call = str(mock_logger.warning.call_args) | ||||||||||||||||
| assert "Warning: Error during MCP session cleanup" in warning_call | ||||||||||||||||
|
||||||||||||||||
| mock_logger.warning.assert_called() | |
| warning_call = str(mock_logger.warning.call_args) | |
| assert "Warning: Error during MCP session cleanup" in warning_call | |
| mock_logger.warning.assert_called_once() | |
| args, kwargs = mock_logger.warning.call_args | |
| assert 'Error during MCP session cleanup for session1' in args[0] | |
| assert kwargs.get('exc_info') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log message can be improved for clarity and to follow standard logging practices. The
logger.warningcall already indicates the severity level, so including 'Warning:' in the message string is redundant. Also, a missing space after the colon in the f-string affects readability.