From 7903a1c4e1c6642adf26649d79773f44f6f5a149 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Wed, 12 Aug 2020 14:55:19 -0700 Subject: [PATCH] PYTHON-2332 Skip threaded SDAM tests when cdecimal is monkey patched (#477) Add 60 second timeout for joining threads in SDAM tests. --- test/test_discovery_and_monitoring.py | 14 +++++++++++++- test/utils.py | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/test/test_discovery_and_monitoring.py b/test/test_discovery_and_monitoring.py index bc05ca78b..c676647e6 100644 --- a/test/test_discovery_and_monitoring.py +++ b/test/test_discovery_and_monitoring.py @@ -38,6 +38,7 @@ from pymongo.topology_description import TOPOLOGY_TYPE from pymongo.uri_parser import parse_uri from test import unittest, IntegrationTest from test.utils import (assertion_context, + cdecimal_patched, client_context, Barrier, get_pool, @@ -334,6 +335,15 @@ class TestIntegration(SpecRunner): event_type = getattr(monitoring, event) return self.pool_listener.event_count(event_type) + def maybe_skip_scenario(self, test): + """Override to skip threaded tests when cdecimal is installed on 2.7 + """ + super(TestIntegration, self).maybe_skip_scenario(test) + # PYTHON-2332 + ops = [op['name'] for op in test['operations']] + if cdecimal_patched() and 'startThread' in ops: + raise unittest.SkipTest('PYTHON-2332 test fails with cdecimal') + def assert_event_count(self, event, count): """Run the assertEventCount test operation. @@ -400,9 +410,11 @@ class TestIntegration(SpecRunner): """Run the 'waitForThread' operation.""" thread = self.targets[name] thread.stop() - thread.join() + thread.join(60) if thread.exc: raise thread.exc + self.assertFalse( + thread.is_alive(), 'Thread %s is still running' % (name,)) def create_spec_test(scenario_def, test, name): diff --git a/test/utils.py b/test/utils.py index 34f62cc44..2f5b84554 100644 --- a/test/utils.py +++ b/test/utils.py @@ -871,6 +871,16 @@ def is_greenthread_patched(): return gevent_monkey_patched() or eventlet_monkey_patched() +def cdecimal_patched(): + """Check if Python 2.7 cdecimal patching is active.""" + try: + import decimal + import cdecimal + return decimal is cdecimal + except ImportError: + return False + + def disable_replication(client): """Disable replication on all secondaries, requires MongoDB 3.2.""" for host, port in client.secondaries: