From patchwork Thu Apr 16 01:29:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1271468 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 492hWh4LqWz9sR4 for ; Thu, 16 Apr 2020 11:31:12 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=Ibqybao2; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 492hWh2nN6zDrBg for ; Thu, 16 Apr 2020 11:31:12 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 492hVd2qJSzDr9P for ; Thu, 16 Apr 2020 11:30:17 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=Ibqybao2; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 492hVd1nGWz9sSl; Thu, 16 Apr 2020 11:30:16 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1587000617; bh=3Dqql2p2iPROjSjs5gaB/MyEd9swD1/7UTQl8VlufCw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ibqybao2smkIk05xmmoTzPxrI6j3K82kHGsKB6ldtUbnku1kCsPOM8PZqypOF/0+R Lcj3I9ExEzzMyB9JutPdSnyNrXbTaYsZCs5EArxEPHvayuufGa4FnFOGlxACGvatyu TLWqN+uiZFqUKwY4e4udHUJmDJVgjGNHmJdwugyEbi/PeMYkXJPVeOpP+Yi1TPAM1b 3NrfXzi5P0zwDvRrZXn5sdKONqtTI9m41SjACljyM+3xKOM72mQIslsl/++iZs9/W6 bEyWHjWGei21pShlhKABuBVk2C+z4og9QuSxW56JukQnDIQ353hKbG1uiRwJ7fyXwu vg0nmiXMgljgQ== From: Jeremy Kerr To: patchwork@lists.ozlabs.org Subject: [PATCH 2/5] tests: ensure we don't see database errors during duplicate insert Date: Thu, 16 Apr 2020 09:29:25 +0800 Message-Id: <20200416012928.23893-3-jk@ozlabs.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200416012928.23893-1-jk@ozlabs.org> References: <20200416012928.23893-1-jk@ozlabs.org> X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" 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 --- patchwork/tests/test_parser.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/patchwork/tests/test_parser.py b/patchwork/tests/test_parser.py index 3a41000..c7c918a 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 @@ -1091,14 +1092,28 @@ 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, []) def test_duplicate_patch(self): diff = read_patch('0001-add-line.patch')