@@ -1805,6 +1805,67 @@ def test_hold_if_recovering(self, mock_get_member_state):
1805
1805
self .mysql .hold_if_recovering ()
1806
1806
self .assertEqual (mock_get_member_state .call_count , 1 )
1807
1807
1808
+ @patch ("charms.mysql.v0.mysql.MySQLBase.get_available_memory" )
1809
+ def test_render_mysqld_configuration (self , _get_available_memory ):
1810
+ """Test render_mysqld_configuration."""
1811
+ # 32GB of memory, production profile
1812
+ _get_available_memory .return_value = 32341442560
1813
+
1814
+ expected_config = {
1815
+ "bind-address" : "0.0.0.0" ,
1816
+ "mysqlx-bind-address" : "0.0.0.0" ,
1817
+ "report_host" : "127.0.0.1" ,
1818
+ "max_connections" : "724" ,
1819
+ "innodb_buffer_pool_size" : "23219666944" ,
1820
+ "log_error_services" : "log_filter_internal;log_sink_internal" ,
1821
+ "log_error" : "/var/log/mysql/error.log" ,
1822
+ "general_log" : "ON" ,
1823
+ "general_log_file" : "/var/log/mysql/general.log" ,
1824
+ "slow_query_log_file" : "/var/log/mysql/slowquery.log" ,
1825
+ "innodb_buffer_pool_chunk_size" : "2902458368" ,
1826
+ }
1827
+
1828
+ _ , rendered_config = self .mysql .render_mysqld_configuration (profile = "production" )
1829
+ self .assertEqual (rendered_config , expected_config )
1830
+
1831
+ # < 2GB of memory, production profile
1832
+ memory_limit = 2147483600
1833
+
1834
+ expected_config ["innodb_buffer_pool_size" ] = "536870912"
1835
+ del expected_config ["innodb_buffer_pool_chunk_size" ]
1836
+ expected_config ["performance-schema-instrument" ] = "'memory/%=OFF'"
1837
+ expected_config ["max_connections" ] = "127"
1838
+
1839
+ _ , rendered_config = self .mysql .render_mysqld_configuration (
1840
+ profile = "production" , memory_limit = memory_limit
1841
+ )
1842
+ self .assertEqual (rendered_config , expected_config )
1843
+
1844
+ # testing profile
1845
+ expected_config ["innodb_buffer_pool_size" ] = "20971520"
1846
+ expected_config ["innodb_buffer_pool_chunk_size" ] = "1048576"
1847
+ expected_config ["loose-group_replication_message_cache_size" ] = "134217728"
1848
+ expected_config ["max_connections" ] = "100"
1849
+
1850
+ _ , rendered_config = self .mysql .render_mysqld_configuration (profile = "testing" )
1851
+ self .assertEqual (rendered_config , expected_config )
1852
+
1853
+ # 10GB, max connections set by value
1854
+ memory_limit = 10106700800
1855
+ # max_connections set
1856
+ _ , rendered_config = self .mysql .render_mysqld_configuration (
1857
+ profile = "production" , experimental_max_connections = 500 , memory_limit = memory_limit
1858
+ )
1859
+
1860
+ self .assertEqual (rendered_config ["max_connections" ], "500" )
1861
+
1862
+ # max_connections set,constrained by memory, but enforced
1863
+ _ , rendered_config = self .mysql .render_mysqld_configuration (
1864
+ profile = "production" , experimental_max_connections = 800 , memory_limit = memory_limit
1865
+ )
1866
+
1867
+ self .assertEqual (rendered_config ["max_connections" ], "800" )
1868
+
1808
1869
@patch ("charms.mysql.v0.mysql.MySQLBase._run_mysqlsh_script" )
1809
1870
def test_create_replica_cluster (self , _run_mysqlsh_script ):
1810
1871
"""Test create_replica_cluster."""
0 commit comments