Skip to content

Commit cee37a8

Browse files
committed
PYTHON-2762 Avoid duplicating unified test files for LB testing (#649)
Create new client for each cursor/session __del__ test. Always close cursors in spec tests. (cherry picked from commit b4b7a07)
1 parent c212c28 commit cee37a8

32 files changed

+96
-272
lines changed

.evergreen/run-tests.sh

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,19 +225,8 @@ if [ -z "$GREEN_FRAMEWORK" ]; then
225225
# causing this script to exit.
226226
$PYTHON -c "from bson import _cbson; from pymongo import _cmessage"
227227
fi
228-
if [ -n "$TEST_LOADBALANCER" ]; then
229-
IS_PRE_35=$(python -c "import sys; sys.stdout.write('1' if sys.version_info < (3, 5) else '0')")
230-
if [ "$IS_PRE_35" = "1" ]; then
231-
RUNNER="unittest"
232-
RUNNER_ARGS=""
233-
else
234-
RUNNER="xmlrunner"
235-
RUNNER_ARGS="--locals -o $XUNIT_DIR"
236-
fi
237-
$COVERAGE_OR_PYTHON $PYTHON_ARGS $COVERAGE_ARGS -m $RUNNER discover $RUNNER_ARGS -s test/load_balancer -v
238-
else
239-
$COVERAGE_OR_PYTHON $PYTHON_ARGS $COVERAGE_ARGS setup.py $C_EXTENSIONS test $TEST_ARGS $OUTPUT
240-
fi
228+
229+
$PYTHON $COVERAGE_ARGS setup.py $C_EXTENSIONS test $TEST_ARGS $OUTPUT
241230
else
242231
# --no_ext has to come before "test" so there is no way to toggle extensions here.
243232
$PYTHON green_framework_test.py $GREEN_FRAMEWORK $OUTPUT

test/__init__.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,24 @@ def sec_count():
578578
return self._require(lambda: sec_count() >= count,
579579
"Not enough secondaries available")
580580

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+
581599
def require_no_replica_set(self, func):
582600
"""Run a test if the client is *not* connected to a replica set."""
583601
return self._require(
@@ -628,6 +646,13 @@ def require_load_balancer(self, func):
628646
"Must be connected to a load balancer",
629647
func=func)
630648

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+
631656
def check_auth_with_sharding(self, func):
632657
"""Skip a test when connected to mongos < 2.0 and running with auth."""
633658
condition = lambda: not (self.auth_enabled and
@@ -838,6 +863,9 @@ class IntegrationTest(PyMongoTestCase):
838863
@classmethod
839864
@client_context.require_connection
840865
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')
841869
cls.client = client_context.client
842870
cls.db = cls.client.pymongo_test
843871
if client_context.auth_enabled:
@@ -861,6 +889,14 @@ class MockClientTest(unittest.TestCase):
861889
The class temporarily overrides HEARTBEAT_FREQUENCY to speed up tests.
862890
"""
863891

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+
864900
def setUp(self):
865901
super(MockClientTest, self).setUp()
866902

test/load_balancer/test_command_monitoring_unified.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/load_balancer/test_crud_unified.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)