21
21
import sys
22
22
import threading
23
23
import time
24
+ import traceback
24
25
import unittest
25
26
import warnings
26
27
@@ -130,6 +131,8 @@ def __init__(
130
131
self .old_min_heartbeat_interval = None
131
132
self .old_kill_cursor_frequency = None
132
133
self .old_events_queue_frequency = None
134
+ self ._enabled = True
135
+ self ._stack = None
133
136
134
137
def enable (self ):
135
138
self .old_heartbeat_frequency = common .HEARTBEAT_FREQUENCY
@@ -148,6 +151,9 @@ def enable(self):
148
151
149
152
if self .events_queue_frequency is not None :
150
153
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 ())
151
157
152
158
def __enter__ (self ):
153
159
self .enable ()
@@ -157,10 +163,24 @@ def disable(self):
157
163
common .MIN_HEARTBEAT_INTERVAL = self .old_min_heartbeat_interval
158
164
common .KILL_CURSOR_FREQUENCY = self .old_kill_cursor_frequency
159
165
common .EVENTS_QUEUE_FREQUENCY = self .old_events_queue_frequency
166
+ self ._enabled = False
160
167
161
168
def __exit__ (self , exc_type , exc_val , exc_tb ):
162
169
self .disable ()
163
170
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
+
164
184
165
185
def _all_users (db ):
166
186
return set (u ['user' ] for u in db .command ('usersInfo' ).get ('users' , []))
0 commit comments