Skip to content

Commit 7903a1c

Browse files
authored
PYTHON-2332 Skip threaded SDAM tests when cdecimal is monkey patched (#477)
Add 60 second timeout for joining threads in SDAM tests.
1 parent add995f commit 7903a1c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

test/test_discovery_and_monitoring.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from pymongo.uri_parser import parse_uri
3939
from test import unittest, IntegrationTest
4040
from test.utils import (assertion_context,
41+
cdecimal_patched,
4142
client_context,
4243
Barrier,
4344
get_pool,
@@ -334,6 +335,15 @@ def marked_unknown(e):
334335
event_type = getattr(monitoring, event)
335336
return self.pool_listener.event_count(event_type)
336337

338+
def maybe_skip_scenario(self, test):
339+
"""Override to skip threaded tests when cdecimal is installed on 2.7
340+
"""
341+
super(TestIntegration, self).maybe_skip_scenario(test)
342+
# PYTHON-2332
343+
ops = [op['name'] for op in test['operations']]
344+
if cdecimal_patched() and 'startThread' in ops:
345+
raise unittest.SkipTest('PYTHON-2332 test fails with cdecimal')
346+
337347
def assert_event_count(self, event, count):
338348
"""Run the assertEventCount test operation.
339349
@@ -400,9 +410,11 @@ def wait_for_thread(self, name):
400410
"""Run the 'waitForThread' operation."""
401411
thread = self.targets[name]
402412
thread.stop()
403-
thread.join()
413+
thread.join(60)
404414
if thread.exc:
405415
raise thread.exc
416+
self.assertFalse(
417+
thread.is_alive(), 'Thread %s is still running' % (name,))
406418

407419

408420
def create_spec_test(scenario_def, test, name):

test/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,16 @@ def is_greenthread_patched():
871871
return gevent_monkey_patched() or eventlet_monkey_patched()
872872

873873

874+
def cdecimal_patched():
875+
"""Check if Python 2.7 cdecimal patching is active."""
876+
try:
877+
import decimal
878+
import cdecimal
879+
return decimal is cdecimal
880+
except ImportError:
881+
return False
882+
883+
874884
def disable_replication(client):
875885
"""Disable replication on all secondaries, requires MongoDB 3.2."""
876886
for host, port in client.secondaries:

0 commit comments

Comments
 (0)