summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-09-21 10:26:57 -0400
committerTim Graham <timograham@gmail.com>2016-09-21 10:26:57 -0400
commit9e41f89b3ba8df2d79241c6960a2fde32cf6a902 (patch)
treea43bfe10214359de13285a765ea597d14cb973fe
parent7eda99f03f6dfbd5a4a3f1e40e6d51842fd3268f (diff)
downloaddjango-16682.tar.gz
Refs #16682 -- Tested transaction.atomic() with KeyboardInterrupt.16682
-rw-r--r--tests/transactions/tests.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py
index 5e947de65f..e8c2f9b8dc 100644
--- a/tests/transactions/tests.py
+++ b/tests/transactions/tests.py
@@ -1,5 +1,6 @@
from __future__ import unicode_literals
+import os
import sys
import threading
import time
@@ -218,6 +219,17 @@ class AtomicTests(TransactionTestCase):
transaction.savepoint_rollback(sid)
self.assertQuerysetEqual(Reporter.objects.all(), ['<Reporter: Tintin>'])
+ def test_rollback_on_keyboardinterrupt(self):
+ try:
+ with transaction.atomic():
+ Reporter.objects.create(first_name='Haddock')
+ # Send SIGINT (simulate Ctrl-C). One call isn't enough.
+ os.kill(os.getpid(), 2)
+ os.kill(os.getpid(), 2)
+ except KeyboardInterrupt:
+ pass
+ self.assertEqual(Reporter.objects.all().count(), 0)
+
class AtomicInsideTransactionTests(AtomicTests):
"""All basic tests for atomic should also pass within an existing transaction."""