mirror of
https://github.com/django/django.git
synced 2024-12-31 21:46:05 +00:00
Refs #34986 -- Fixed backends.postgresql.test_server_side_cursors.ServerSideCursorsPostgres tests for PyPy.
This commit is contained in:
parent
958a590e53
commit
af6e7e3de8
@ -5,6 +5,8 @@ from contextlib import contextmanager
|
|||||||
|
|
||||||
from django.db import connection, models
|
from django.db import connection, models
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
from django.test.utils import garbage_collect
|
||||||
|
from django.utils.version import PYPY
|
||||||
|
|
||||||
from ..models import Person
|
from ..models import Person
|
||||||
|
|
||||||
@ -88,14 +90,21 @@ class ServerSideCursorsPostgres(TestCase):
|
|||||||
persons = Person.objects.iterator()
|
persons = Person.objects.iterator()
|
||||||
next(persons) # Open a server-side cursor
|
next(persons) # Open a server-side cursor
|
||||||
del persons
|
del persons
|
||||||
|
garbage_collect()
|
||||||
cursors = self.inspect_cursors()
|
cursors = self.inspect_cursors()
|
||||||
self.assertEqual(len(cursors), 0)
|
self.assertEqual(len(cursors), 0)
|
||||||
|
|
||||||
|
@unittest.skipIf(
|
||||||
|
PYPY,
|
||||||
|
reason="Cursor not closed properly due to differences in garbage collection.",
|
||||||
|
)
|
||||||
def test_server_side_cursors_setting(self):
|
def test_server_side_cursors_setting(self):
|
||||||
with self.override_db_setting(DISABLE_SERVER_SIDE_CURSORS=False):
|
with self.override_db_setting(DISABLE_SERVER_SIDE_CURSORS=False):
|
||||||
persons = Person.objects.iterator()
|
persons = Person.objects.iterator()
|
||||||
self.assertUsesCursor(persons)
|
self.assertUsesCursor(persons)
|
||||||
del persons # Close server-side cursor
|
del persons # Close server-side cursor
|
||||||
|
|
||||||
|
# On PyPy, the cursor is left open here and attempting to force garbage
|
||||||
|
# collection breaks the transaction wrapping the test.
|
||||||
with self.override_db_setting(DISABLE_SERVER_SIDE_CURSORS=True):
|
with self.override_db_setting(DISABLE_SERVER_SIDE_CURSORS=True):
|
||||||
self.assertNotUsesCursor(Person.objects.iterator())
|
self.assertNotUsesCursor(Person.objects.iterator())
|
||||||
|
Loading…
Reference in New Issue
Block a user