Code

Ticket #16682: 16682-test.diff

File 16682-test.diff, 1.1 KB (added by claudep, 2 years ago)

Failing test

Line 
1diff --git a/tests/regressiontests/transactions_regress/tests.py b/tests/regressiontests/transactions_regress/tests.py
2index 5972263..615446f 100644
3--- a/tests/regressiontests/transactions_regress/tests.py
4+++ b/tests/regressiontests/transactions_regress/tests.py
5@@ -1,4 +1,5 @@
6 from __future__ import absolute_import
7+import os
8 
9 from django.core.exceptions import ImproperlyConfigured
10 from django.db import connection, transaction
11@@ -174,6 +175,17 @@ class TestTransactionClosing(TransactionTestCase):
12         """
13         self.test_failing_query_transaction_closed()
14 
15+    def test_rollback_on_keyboardinterrupt(self):
16+        try:
17+            with transaction.commit_on_success():
18+                Mod.objects.create(fld=17624)
19+                # Send SIGINT (simulate Ctrl-C) to self, one call seems not enough??
20+                os.kill(os.getpid(), 2)
21+                os.kill(os.getpid(), 2)
22+        except KeyboardInterrupt:
23+            pass
24+        self.assertEqual(Mod.objects.all().count(), 0)
25+
26 
27 class TestManyToManyAddTransaction(TransactionTestCase):
28     def test_manyrelated_add_commit(self):