diff mbox series

[1/2] tests: Run FuzzTest within a transaction

Message ID 1503920358-26652-1-git-send-email-jk@ozlabs.org
State Accepted
Headers show
Series [1/2] tests: Run FuzzTest within a transaction | expand

Commit Message

Jeremy Kerr Aug. 28, 2017, 11:39 a.m. UTC
Currently, the FuzzTests fail for me with:

/backends/base/base.py", line 428, in validate_no_broken_transaction
    "An error occurred in the current transaction. You can't "
TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.

- because the SQL inserts can fail, during an active transaction (the
first failure I see is attempting to insert \0 chars in
codec-null.mbox); this causes the setup for the next test case to fail.

Instead, run each test in its own transaction.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
---
 patchwork/tests/test_parser.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Stephen Finucane Aug. 28, 2017, 1:08 p.m. UTC | #1
On Mon, 2017-08-28 at 19:39 +0800, Jeremy Kerr wrote:
> Currently, the FuzzTests fail for me with:
> 
> /backends/base/base.py", line 428, in validate_no_broken_transaction
>     "An error occurred in the current transaction. You can't "
> TransactionManagementError: An error occurred in the current transaction. You
> can't execute queries until the end of the 'atomic' block.
> 
> - because the SQL inserts can fail, during an active transaction (the
> first failure I see is attempting to insert \0 chars in
> codec-null.mbox); this causes the setup for the next test case to fail.
> 
> Instead, run each test in its own transaction.
> 
> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>

Looks good to me, with one nit below (can be fixed at merge time).

Reviewed-by: Stephen Finucane <stephen@that.guru>

> ---
>  patchwork/tests/test_parser.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/patchwork/tests/test_parser.py b/patchwork/tests/test_parser.py
> index 583dfcc..9389f28 100644
> --- a/patchwork/tests/test_parser.py
> +++ b/patchwork/tests/test_parser.py
> @@ -25,7 +25,7 @@ from email.utils import make_msgid
>  import os
>  import unittest
>  
> -from django.test import TestCase
> +from django.test import TestCase, TransactionTestCase

We should break these onto two different lines. It's a pet peeve of mine :)

>  from django.utils import six
>  
>  from patchwork.models import Comment
> @@ -865,7 +865,7 @@ class SubjectTest(TestCase):
>          self.assertEqual(parse_version('Hello, world (V6)', []), 6)
>  
>  
> -class FuzzTest(TestCase):
> +class FuzzTest(TransactionTestCase):
>      """Test fuzzed patches."""
>      def setUp(self):
>          create_project(listid='patchwork.ozlabs.org')
Stephen Finucane Aug. 31, 2017, 8:43 a.m. UTC | #2
On Mon, 2017-08-28 at 14:08 +0100, Stephen Finucane wrote:
> On Mon, 2017-08-28 at 19:39 +0800, Jeremy Kerr wrote:
> > Currently, the FuzzTests fail for me with:
> > 
> > /backends/base/base.py", line 428, in validate_no_broken_transaction
> >     "An error occurred in the current transaction. You can't "
> > TransactionManagementError: An error occurred in the current transaction.
> > You
> > can't execute queries until the end of the 'atomic' block.
> > 
> > - because the SQL inserts can fail, during an active transaction (the
> > first failure I see is attempting to insert \0 chars in
> > codec-null.mbox); this causes the setup for the next test case to fail.
> > 
> > Instead, run each test in its own transaction.
> > 
> > Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
> 
> Looks good to me, with one nit below (can be fixed at merge time).
> 
> Reviewed-by: Stephen Finucane <stephen@that.guru>

Both of these patches are now applied to 'master' and backported to
'stable/2.0'.

Stephen
diff mbox series

Patch

diff --git a/patchwork/tests/test_parser.py b/patchwork/tests/test_parser.py
index 583dfcc..9389f28 100644
--- a/patchwork/tests/test_parser.py
+++ b/patchwork/tests/test_parser.py
@@ -25,7 +25,7 @@  from email.utils import make_msgid
 import os
 import unittest
 
-from django.test import TestCase
+from django.test import TestCase, TransactionTestCase
 from django.utils import six
 
 from patchwork.models import Comment
@@ -865,7 +865,7 @@  class SubjectTest(TestCase):
         self.assertEqual(parse_version('Hello, world (V6)', []), 6)
 
 
-class FuzzTest(TestCase):
+class FuzzTest(TransactionTestCase):
     """Test fuzzed patches."""
     def setUp(self):
         create_project(listid='patchwork.ozlabs.org')