Skip to content

Commit dcfe488

Browse files
takaidohigasiclaude
andcommitted
Fix TiDB unit test failures
- Fix hostname mocking issues by setting reported_hostname directly on instances - Fix JSON serialization error by using proper config class instead of MagicMock - Ensure cloud_metadata is a dict not MagicMock to prevent serialization issues 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a9b65aa commit dcfe488

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

mysql/tests/test_query_activity.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -871,16 +871,21 @@ def test_tidb_activity_multiple_nodes():
871871
check._events_wait_current_enabled = False # Force TiDB path
872872
# Mock the property getter
873873
check.events_wait_current_enabled = False
874+
check.reported_hostname = 'test-host' # Set this to avoid MagicMock in JSON
874875
check.database_monitoring_query_activity = mock.MagicMock()
875876
check.histogram = mock.MagicMock()
876877
check._get_debug_tags = mock.MagicMock(return_value=[])
877878

878-
config = mock.MagicMock()
879-
config.activity_config = {'enabled': True, 'collection_interval': 10}
880-
config.obfuscator_options = {'replace_digits': True}
881-
config.cloud_metadata = {}
882-
config.service = 'test-tidb'
883-
config.min_collection_interval = 1
879+
# Create a proper config object instead of MagicMock to avoid JSON serialization issues
880+
class MockConfig:
881+
def __init__(self):
882+
self.activity_config = {'enabled': True, 'collection_interval': 10}
883+
self.obfuscator_options = {'replace_digits': True}
884+
self.cloud_metadata = {}
885+
self.service = 'test-tidb'
886+
self.min_collection_interval = 1
887+
888+
config = MockConfig()
884889

885890
activity_collector = MySQLActivity(check, config, {})
886891
# Initialize _tags which is normally set by the parent class

0 commit comments

Comments
 (0)