mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #27539 -- Made TransactionTestCase._pre_setup() clear the queries_log so it's less likely to overflow.
TransactionTestCase.assertNumQueries() fails in an overflow situation.
This commit is contained in:
		| @@ -827,6 +827,11 @@ class TransactionTestCase(SimpleTestCase): | ||||
|                     enter=False, | ||||
|                 ) | ||||
|             raise | ||||
|         # Clear the queries_log so that it's less likley to overflow (a single | ||||
|         # test probably won't execute 9K queries). If queries_log overflows, | ||||
|         # then assertNumQueries() doesn't work. | ||||
|         for db_name in self._databases_names(include_mirrors=False): | ||||
|             connections[db_name].queries_log.clear() | ||||
|  | ||||
|     @classmethod | ||||
|     def _databases_names(cls, include_mirrors=True): | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| from unittest import mock | ||||
|  | ||||
| from django.test import TransactionTestCase | ||||
| from django.db import connections | ||||
| from django.test import TestCase, TransactionTestCase, override_settings | ||||
|  | ||||
|  | ||||
| class TestSerializedRollbackInhibitsPostMigrate(TransactionTestCase): | ||||
| @@ -28,3 +29,18 @@ class TestSerializedRollbackInhibitsPostMigrate(TransactionTestCase): | ||||
|             reset_sequences=False, inhibit_post_migrate=True, | ||||
|             database='default', verbosity=0, | ||||
|         ) | ||||
|  | ||||
|  | ||||
| @override_settings(DEBUG=True)  # Enable query logging for test_queries_cleared | ||||
| class TransactionTestCaseMultiDbTests(TestCase): | ||||
|     available_apps = [] | ||||
|     multi_db = True | ||||
|  | ||||
|     def test_queries_cleared(self): | ||||
|         """ | ||||
|         TransactionTestCase._pre_setup() clears the connections' queries_log | ||||
|         so that it's less likely to overflow. An overflow causes | ||||
|         assertNumQueries() to fail. | ||||
|         """ | ||||
|         for alias in connections: | ||||
|             self.assertEqual(len(connections[alias].queries_log), 0, 'Failed for alias %s' % alias) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user