Skip to content

Commit 2eecf52

Browse files
authored
PYTHON-2474 Fix non-disabled client_knobs bug in Data Lake tests (mongodb#537)
1 parent c673d8b commit 2eecf52

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

test/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import sys
2222
import threading
2323
import time
24+
import traceback
2425
import unittest
2526
import warnings
2627

@@ -130,6 +131,8 @@ def __init__(
130131
self.old_min_heartbeat_interval = None
131132
self.old_kill_cursor_frequency = None
132133
self.old_events_queue_frequency = None
134+
self._enabled = True
135+
self._stack = None
133136

134137
def enable(self):
135138
self.old_heartbeat_frequency = common.HEARTBEAT_FREQUENCY
@@ -148,6 +151,9 @@ def enable(self):
148151

149152
if self.events_queue_frequency is not None:
150153
common.EVENTS_QUEUE_FREQUENCY = self.events_queue_frequency
154+
self._enabled = True
155+
# Store the allocation traceback to catch non-disabled client_knobs.
156+
self._stack = ''.join(traceback.format_stack())
151157

152158
def __enter__(self):
153159
self.enable()
@@ -157,10 +163,24 @@ def disable(self):
157163
common.MIN_HEARTBEAT_INTERVAL = self.old_min_heartbeat_interval
158164
common.KILL_CURSOR_FREQUENCY = self.old_kill_cursor_frequency
159165
common.EVENTS_QUEUE_FREQUENCY = self.old_events_queue_frequency
166+
self._enabled = False
160167

161168
def __exit__(self, exc_type, exc_val, exc_tb):
162169
self.disable()
163170

171+
def __del__(self):
172+
if self._enabled:
173+
print(
174+
'\nERROR: client_knobs still enabled! HEARTBEAT_FREQUENCY=%s, '
175+
'MIN_HEARTBEAT_INTERVAL=%s, KILL_CURSOR_FREQUENCY=%s, '
176+
'EVENTS_QUEUE_FREQUENCY=%s, stack:\n%s' % (
177+
common.HEARTBEAT_FREQUENCY,
178+
common.MIN_HEARTBEAT_INTERVAL,
179+
common.KILL_CURSOR_FREQUENCY,
180+
common.EVENTS_QUEUE_FREQUENCY,
181+
self._stack))
182+
self.disable()
183+
164184

165185
def _all_users(db):
166186
return set(u['user'] for u in db.command('usersInfo').get('users', []))

test/test_data_lake.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ class DataLakeTestSpec(TestCrudV2):
3535
TEST_COLLECTION = 'driverdata'
3636

3737
@classmethod
38+
@unittest.skipUnless(client_context.is_data_lake,
39+
'Not connected to Atlas Data Lake')
3840
def setUpClass(cls):
3941
super(DataLakeTestSpec, cls).setUpClass()
40-
# Skip these tests unless connected to data lake.
41-
if not client_context.is_data_lake:
42-
raise unittest.SkipTest('Not connected to Atlas Data Lake')
4342

4443
def setup_scenario(self, scenario_def):
4544
# Spec tests MUST NOT insert data/drop collection for

0 commit comments

Comments
 (0)