Skip to content

Commit a60e75e

Browse files
jk-ozlabsstephenfin
authored andcommitted
tests: ensure we don't see database errors during duplicate insert
Currently, the parser causes IntegrityErrors while inserting duplicate patches; these tend to pollute database logs. This change adds a check, which currently fails, to ensure we do not cause errors during a duplicate patch parse. Signed-off-by: Jeremy Kerr <[email protected]> Signed-off-by: Stephen Finucane <[email protected]> [stephenfin: Add 'expectedFailure' marker to keep all tests green]
1 parent d4b5fbd commit a60e75e

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

patchwork/tests/test_parser.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from django.test import TestCase
1616
from django.test import TransactionTestCase
1717
from django.db.transaction import atomic
18+
from django.db import connection
1819

1920
from patchwork.models import Comment
2021
from patchwork.models import Patch
@@ -1114,15 +1115,30 @@ def setUp(self):
11141115
create_state()
11151116

11161117
def _test_duplicate_mail(self, mail):
1118+
errors = []
1119+
1120+
def log_query_errors(execute, sql, params, many, context):
1121+
try:
1122+
result = execute(sql, params, many, context)
1123+
except Exception as e:
1124+
errors.append(e)
1125+
raise
1126+
return result
1127+
11171128
_parse_mail(mail)
1129+
11181130
with self.assertRaises(DuplicateMailError):
1119-
# If we see any database errors from the duplicate insert
1120-
# (typically an IntegrityError), the insert will abort the current
1121-
# transaction. This atomic() ensures that we can recover, and
1122-
# perform subsequent queries.
1123-
with atomic():
1124-
_parse_mail(mail)
1131+
with connection.execute_wrapper(log_query_errors):
1132+
# If we see any database errors from the duplicate insert
1133+
# (typically an IntegrityError), the insert will abort the
1134+
# current transaction. This atomic() ensures that we can
1135+
# recover, and perform subsequent queries.
1136+
with atomic():
1137+
_parse_mail(mail)
1138+
1139+
self.assertEqual(errors, [])
11251140

1141+
@unittest.expectedFailure
11261142
def test_duplicate_patch(self):
11271143
diff = read_patch('0001-add-line.patch')
11281144
m = create_email(diff, listid=self.listid, msgid='[email protected]')

0 commit comments

Comments
 (0)