@@ -578,6 +578,24 @@ def sec_count():
578
578
return self ._require (lambda : sec_count () >= count ,
579
579
"Not enough secondaries available" )
580
580
581
+ @property
582
+ def supports_secondary_read_pref (self ):
583
+ if self .has_secondaries :
584
+ return True
585
+ if self .is_mongos :
586
+ shard = self .client .config .shards .find_one ()['host' ]
587
+ num_members = shard .count (',' ) + 1
588
+ return num_members > 1
589
+ return False
590
+
591
+ def require_secondary_read_pref (self ):
592
+ """Run a test only if the client is connected to a cluster that
593
+ supports secondary read preference
594
+ """
595
+ return self ._require (lambda : self .supports_secondary_read_pref ,
596
+ "This cluster does not support secondary read "
597
+ "preference" )
598
+
581
599
def require_no_replica_set (self , func ):
582
600
"""Run a test if the client is *not* connected to a replica set."""
583
601
return self ._require (
@@ -628,6 +646,13 @@ def require_load_balancer(self, func):
628
646
"Must be connected to a load balancer" ,
629
647
func = func )
630
648
649
+ def require_no_load_balancer (self , func ):
650
+ """Run a test only if the client is not connected to a load balancer.
651
+ """
652
+ return self ._require (lambda : not self .load_balancer ,
653
+ "Must not be connected to a load balancer" ,
654
+ func = func )
655
+
631
656
def check_auth_with_sharding (self , func ):
632
657
"""Skip a test when connected to mongos < 2.0 and running with auth."""
633
658
condition = lambda : not (self .auth_enabled and
@@ -838,6 +863,9 @@ class IntegrationTest(PyMongoTestCase):
838
863
@classmethod
839
864
@client_context .require_connection
840
865
def setUpClass (cls ):
866
+ if (client_context .load_balancer and
867
+ not getattr (cls , 'RUN_ON_LOAD_BALANCER' , False )):
868
+ raise SkipTest ('this test does not support load balancers' )
841
869
cls .client = client_context .client
842
870
cls .db = cls .client .pymongo_test
843
871
if client_context .auth_enabled :
@@ -861,6 +889,14 @@ class MockClientTest(unittest.TestCase):
861
889
The class temporarily overrides HEARTBEAT_FREQUENCY to speed up tests.
862
890
"""
863
891
892
+ # MockClients tests that use replicaSet, directConnection=True, pass
893
+ # multiple seed addresses, or wait for heartbeat events are incompatible
894
+ # with loadBalanced=True.
895
+ @classmethod
896
+ @client_context .require_no_load_balancer
897
+ def setUpClass (cls ):
898
+ pass
899
+
864
900
def setUp (self ):
865
901
super (MockClientTest , self ).setUp ()
866
902
0 commit comments