Ticket #16682: 16682-atomic.diff

File 16682-atomic.diff, 1.0 KB (added by Tim Graham, 8 years ago)
  • tests/transactions/tests.py

    diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py
    index 5e947de..e8c2f9b 100644
    a b  
    11from __future__ import unicode_literals
    22
     3import os
    34import sys
    45import threading
    56import time
    class AtomicTests(TransactionTestCase):  
    218219            transaction.savepoint_rollback(sid)
    219220        self.assertQuerysetEqual(Reporter.objects.all(), ['<Reporter: Tintin>'])
    220221
     222    def test_rollback_on_keyboardinterrupt(self):
     223        try:
     224            with transaction.atomic():
     225                Reporter.objects.create(first_name='Haddock')
     226                # Send SIGINT (simulate Ctrl-C). One call isn't enough.
     227                os.kill(os.getpid(), 2)
     228                os.kill(os.getpid(), 2)
     229        except KeyboardInterrupt:
     230            pass
     231        self.assertEqual(Reporter.objects.all().count(), 0)
     232
    221233
    222234class AtomicInsideTransactionTests(AtomicTests):
    223235    """All basic tests for atomic should also pass within an existing transaction."""
Back to Top