2121import sys
2222import threading
2323import time
24+ import traceback
2425import unittest
2526import 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+ '\n ERROR: 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
165185def _all_users (db ):
166186 return set (u ['user' ] for u in db .command ('usersInfo' ).get ('users' , []))
0 commit comments