turbaszek commented on a change in pull request #9280:
URL: https://github.com/apache/airflow/pull/9280#discussion_r444053678



##########
File path: tests/hooks/test_hive_hook.py
##########
@@ -390,6 +390,25 @@ def test_table_exists(self):
             self.hook.table_exists(str(random.randint(1, 10000)))
         )
 
+    def test_check_hms_clients_load_balance(self):
+        #   checks if every time HMS Hook is instantiated, it gets to
+        #   different HMS server most of the time and not to the same HMS 
server.
+        connection_count = {}
+        hms_hook = HiveMetastoreHook()
+        hms_server_count = len(hms_hook.get_connections('metastore_default'))
+
+        if hms_server_count > 2:
+            for index in range(2 * hms_server_count):
+                conn = HiveMetastoreHook()._find_valid_server().host
+                if conn in connection_count:
+                    if connection_count[conn] >= (2 * hms_server_count) - 1:
+                        self.assertTrue(1 == 2)
+                    else:
+                        connection_count[conn] = connection_count[conn] + 1
+                else:
+                    connection_count[conn] = 1
+        self.assertTrue(1 == 1)

Review comment:
       I appreciate the test, however I'm wondering if it would be sufficient 
to mock the `random.shuffle` and assert that it was called? Additionaly we can 
mock it with callable that gives deterministic result i.e `lambda xs: 
xs[::-1]`, WDYT?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to