diff options
author | Claude Paroz <claude@2xlibre.net> | 2016-09-21 10:26:57 -0400 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2016-09-21 14:28:10 -0400 |
commit | d895fc9ac01db3d3420aa7c943949fe17b3ce028 (patch) | |
tree | 1f70818a503e30c7fa69188174c8da95b681f25d /tests/transactions | |
parent | ddef397b0d0c44f8e45b467a6368b83e1102d0dd (diff) | |
download | django-d895fc9ac01db3d3420aa7c943949fe17b3ce028.tar.gz |
Refs #16682 -- Tested transaction.atomic() with KeyboardInterrupt.
Diffstat (limited to 'tests/transactions')
-rw-r--r-- | tests/transactions/tests.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py index 5e947de65f..dcfd30fcaa 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,18 @@ class AtomicTests(TransactionTestCase): transaction.savepoint_rollback(sid) self.assertQuerysetEqual(Reporter.objects.all(), ['<Reporter: Tintin>']) + @skipIf(sys.platform.startswith('win'), "Windows doesn't have signals.") + def test_rollback_on_keyboardinterrupt(self): + try: + with transaction.atomic(): + Reporter.objects.create(first_name='Tintin') + # 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.""" |