mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 02:48:00 +00:00
tests: Ignore SAVEPOINT queries in queries_captured().
We use the queries_captured() context manager in our tests to capture queries that happen during certain actions. Usually we use the list of queries to validate that we're not doing too many database calls. For most tests the database calls are fairly deterministic, but SAVEPOINT-related things seem to be more random, and the number of savepoints is usually not relevant to what the test is trying to prevent, which is more serious problems like O(N) database fetches.
This commit is contained in:
@@ -103,8 +103,8 @@ def simulated_empty_cache():
|
||||
cache.cache_get_many = old_get_many
|
||||
|
||||
@contextmanager
|
||||
def queries_captured():
|
||||
# type: () -> Generator[List[Dict[str, Union[str, binary_type]]], None, None]
|
||||
def queries_captured(include_savepoints=False):
|
||||
# type: (Optional[bool]) -> Generator[List[Dict[str, Union[str, binary_type]]], None, None]
|
||||
'''
|
||||
Allow a user to capture just the queries executed during
|
||||
the with statement.
|
||||
@@ -120,10 +120,11 @@ def queries_captured():
|
||||
finally:
|
||||
stop = time.time()
|
||||
duration = stop - start
|
||||
queries.append({
|
||||
'sql': self.mogrify(sql, params).decode('utf-8'),
|
||||
'time': "%.3f" % duration,
|
||||
})
|
||||
if include_savepoints or ('SAVEPOINT' not in sql):
|
||||
queries.append({
|
||||
'sql': self.mogrify(sql, params).decode('utf-8'),
|
||||
'time': "%.3f" % duration,
|
||||
})
|
||||
|
||||
old_execute = TimeTrackingCursor.execute
|
||||
old_executemany = TimeTrackingCursor.executemany
|
||||
|
||||
Reference in New Issue
Block a user