|
@@ -375,18 +375,17 @@ class AtomicMySQLTests(TransactionTestCase):
|
|
|
@skipIf(threading is None, "Test requires threading")
|
|
|
def test_implicit_savepoint_rollback(self):
|
|
|
"""MySQL implicitly rolls back savepoints when it deadlocks (#22291)."""
|
|
|
+ Reporter.objects.create(id=1)
|
|
|
+ Reporter.objects.create(id=2)
|
|
|
|
|
|
- other_thread_ready = threading.Event()
|
|
|
+ main_thread_ready = threading.Event()
|
|
|
|
|
|
def other_thread():
|
|
|
try:
|
|
|
with transaction.atomic():
|
|
|
- Reporter.objects.create(id=1, first_name="Tintin")
|
|
|
- other_thread_ready.set()
|
|
|
-
|
|
|
-
|
|
|
- time.sleep(1)
|
|
|
-
|
|
|
+ Reporter.objects.select_for_update().get(id=1)
|
|
|
+ main_thread_ready.wait()
|
|
|
+
|
|
|
Reporter.objects.exclude(id=1).update(id=2)
|
|
|
finally:
|
|
|
|
|
@@ -394,14 +393,18 @@ class AtomicMySQLTests(TransactionTestCase):
|
|
|
|
|
|
other_thread = threading.Thread(target=other_thread)
|
|
|
other_thread.start()
|
|
|
- other_thread_ready.wait()
|
|
|
|
|
|
with self.assertRaisesMessage(OperationalError, 'Deadlock found'):
|
|
|
|
|
|
with transaction.atomic():
|
|
|
with transaction.atomic():
|
|
|
-
|
|
|
- Reporter.objects.create(id=1, first_name="Tintin")
|
|
|
+ Reporter.objects.select_for_update().get(id=2)
|
|
|
+ main_thread_ready.set()
|
|
|
+
|
|
|
+
|
|
|
+ time.sleep(1)
|
|
|
+
|
|
|
+ Reporter.objects.exclude(id=2).update(id=1)
|
|
|
|
|
|
other_thread.join()
|
|
|
|