Skip to content

PYTHON-2474 Fix non-disabled client_knobs bug in Data Lake tests #537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import sys
import threading
import time
import traceback
import unittest
import warnings

Expand Down Expand Up @@ -130,6 +131,8 @@ def __init__(
self.old_min_heartbeat_interval = None
self.old_kill_cursor_frequency = None
self.old_events_queue_frequency = None
self._enabled = True
self._stack = None

def enable(self):
self.old_heartbeat_frequency = common.HEARTBEAT_FREQUENCY
Expand All @@ -148,6 +151,9 @@ def enable(self):

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

def __enter__(self):
self.enable()
Expand All @@ -157,10 +163,24 @@ def disable(self):
common.MIN_HEARTBEAT_INTERVAL = self.old_min_heartbeat_interval
common.KILL_CURSOR_FREQUENCY = self.old_kill_cursor_frequency
common.EVENTS_QUEUE_FREQUENCY = self.old_events_queue_frequency
self._enabled = False

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

def __del__(self):
if self._enabled:
print(
'\nERROR: client_knobs still enabled! HEARTBEAT_FREQUENCY=%s, '
'MIN_HEARTBEAT_INTERVAL=%s, KILL_CURSOR_FREQUENCY=%s, '
'EVENTS_QUEUE_FREQUENCY=%s, stack:\n%s' % (
common.HEARTBEAT_FREQUENCY,
common.MIN_HEARTBEAT_INTERVAL,
common.KILL_CURSOR_FREQUENCY,
common.EVENTS_QUEUE_FREQUENCY,
self._stack))
self.disable()


def _all_users(db):
return set(u['user'] for u in db.command('usersInfo').get('users', []))
Expand Down
5 changes: 2 additions & 3 deletions test/test_data_lake.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ class DataLakeTestSpec(TestCrudV2):
TEST_COLLECTION = 'driverdata'

@classmethod
@unittest.skipUnless(client_context.is_data_lake,
'Not connected to Atlas Data Lake')
def setUpClass(cls):
super(DataLakeTestSpec, cls).setUpClass()
# Skip these tests unless connected to data lake.
if not client_context.is_data_lake:
raise unittest.SkipTest('Not connected to Atlas Data Lake')
Copy link
Member Author

@ShaneHarvey ShaneHarvey Dec 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explanation:

  1. The super class' setUpClass method calls client_knobs.enable().
  2. Here we raise SkipTest
  3. tearDownClass is never called because setUpClass raised an error.
  4. The side-effects of client_knobs are still present.

The change here fixes the bug by raising SkipTest before calling setUpClass.


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