|
1 |
| -from clickhouse_driver.dbapi.errors import ( |
2 |
| - OperationalError as ch_driver_OperationalError, |
3 |
| -) |
4 |
| -from clickhouse_driver.errors import PartiallyConsumedQueryError |
5 | 1 | from django.db import connection
|
6 |
| -from django.db.utils import OperationalError as django_OperationalError |
7 | 2 | from django.test import TestCase
|
8 | 3 |
|
9 | 4 | from clickhouse_backend.driver import connect
|
@@ -34,41 +29,19 @@ def setUpTestData(cls):
|
34 | 29 | ]
|
35 | 30 | )
|
36 | 31 |
|
37 |
| - def test_connection_unusable_when_iteration_interrupted(self): |
38 |
| - """ |
39 |
| - This test demonstrates that if a queryset is iterated over and the iteration |
40 |
| - is interrupted (e.g. via a break statement), the connection used for that |
41 |
| - iteration is not cleaned up and is left in a broken state. Any subsequent |
42 |
| - queries using that connection will fail. |
43 |
| - """ |
| 32 | + def test_connection_not_reused_when_iteration_interrupted(self): |
44 | 33 | pool = connection.connection.pool
|
45 |
| - connection_count_before = len(pool._pool) |
46 | 34 |
|
| 35 | + connection_count_before = len(pool._pool) |
47 | 36 | assert connection_count_before == 1
|
48 | 37 |
|
49 |
| - # Asserts most recent exception is Django OperationalError |
50 |
| - with self.assertRaises(django_OperationalError) as ex_context: |
51 |
| - # Get queryset |
52 |
| - authors = models.Author.objects.all() |
53 |
| - # Access iterator, but break after first item |
54 |
| - for author in authors.iterator(1): |
55 |
| - author = author.name |
56 |
| - break |
57 |
| - |
58 |
| - # Assert connection pool size is unchanged despite broken connection |
59 |
| - connection_count_after_iterator = len(pool._pool) |
60 |
| - assert connection_count_after_iterator == 1 |
| 38 | + authors = models.Author.objects.all() |
| 39 | + for author in authors.iterator(1): |
| 40 | + author = author.name |
| 41 | + break |
61 | 42 |
|
62 |
| - # Try to access queryset again, which won't work via same connection |
63 |
| - author = authors.get(id=self.a1.id) |
| 43 | + connection_count_after_iterator = len(pool._pool) |
| 44 | + # Connection was closed and not returned to pool |
| 45 | + assert connection_count_after_iterator == 0 |
64 | 46 |
|
65 |
| - # Caused by ch driver driver Operational error |
66 |
| - self.assertIsInstance( |
67 |
| - ex_context.exception.__cause__, ch_driver_OperationalError |
68 |
| - ) |
69 |
| - |
70 |
| - # ...The context of which is a PartiallyConsumedQueryError |
71 |
| - # https://github.com/mymarilyn/clickhouse-driver/blob/master/clickhouse_driver/connection.py#L801 |
72 |
| - self.assertIsInstance( |
73 |
| - ex_context.exception.__cause__.__context__, PartiallyConsumedQueryError |
74 |
| - ) |
| 47 | + author = authors.get(id=self.a1.id) |
0 commit comments