aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2020-04-16 09:29:25 +0800
committerStephen Finucane <stephen@that.guru>2020-04-18 12:30:30 +0100
commita60e75e2c6897fd262ec95a35e0e94b9027c11d4 (patch)
treeb6702bae9f942bbb1c6f87d709b2a00b2cf392e1
parentd4b5fbd1d0c743003d59cef025f54b8d97586ddf (diff)
downloadpatchwork-a60e75e2c6897fd262ec95a35e0e94b9027c11d4.tar
patchwork-a60e75e2c6897fd262ec95a35e0e94b9027c11d4.tar.gz
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 <jk@ozlabs.org> Signed-off-by: Stephen Finucane <stephen@that.guru> [stephenfin: Add 'expectedFailure' marker to keep all tests green]
-rw-r--r--patchwork/tests/test_parser.py28
1 files changed, 22 insertions, 6 deletions
diff --git a/patchwork/tests/test_parser.py b/patchwork/tests/test_parser.py
index 442e719..0122fb8 100644
--- a/patchwork/tests/test_parser.py
+++ b/patchwork/tests/test_parser.py
@@ -15,6 +15,7 @@ import unittest
from django.test import TestCase
from django.test import TransactionTestCase
from django.db.transaction import atomic
+from django.db import connection
from patchwork.models import Comment
from patchwork.models import Patch
@@ -1114,15 +1115,30 @@ class DuplicateMailTest(TestCase):
create_state()
def _test_duplicate_mail(self, mail):
+ errors = []
+
+ def log_query_errors(execute, sql, params, many, context):
+ try:
+ result = execute(sql, params, many, context)
+ except Exception as e:
+ errors.append(e)
+ raise
+ return result
+
_parse_mail(mail)
+
with self.assertRaises(DuplicateMailError):
- # If we see any database errors from the duplicate insert
- # (typically an IntegrityError), the insert will abort the current
- # transaction. This atomic() ensures that we can recover, and
- # perform subsequent queries.
- with atomic():
- _parse_mail(mail)
+ with connection.execute_wrapper(log_query_errors):
+ # If we see any database errors from the duplicate insert
+ # (typically an IntegrityError), the insert will abort the
+ # current transaction. This atomic() ensures that we can
+ # recover, and perform subsequent queries.
+ with atomic():
+ _parse_mail(mail)
+
+ self.assertEqual(errors, [])
+ @unittest.expectedFailure
def test_duplicate_patch(self):
diff = read_patch('0001-add-line.patch')
m = create_email(diff, listid=self.listid, msgid='1@example.com')