]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-108550: Speed up sqlite3 tests (#108551) (#108567)
authorErlend E. Aasland <erlend@python.org>
Mon, 28 Aug 2023 13:09:10 +0000 (15:09 +0200)
committerGitHub <noreply@github.com>
Mon, 28 Aug 2023 13:09:10 +0000 (13:09 +0000)
Disable the busy handler for all concurrency tests; we have full
control over the order of the SQLite C API calls, so we can safely
do this.

test_sqlite3.test_transactions now completes ~10 times faster than before.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_sqlite3/test_dbapi.py
Lib/test/test_sqlite3/test_transactions.py

index 899f5cfbd319698cd282fd0c9b6647a3abf3a41c..ff86291bc5702f46f5c656b0c780f66db96d28cb 100644 (file)
@@ -1837,7 +1837,7 @@ class SqliteOnConflictTests(unittest.TestCase):
 
 @requires_subprocess()
 class MultiprocessTests(unittest.TestCase):
-    CONNECTION_TIMEOUT = SHORT_TIMEOUT / 1000.  # Defaults to 30 ms
+    CONNECTION_TIMEOUT = 0  # Disable the busy timeout.
 
     def tearDown(self):
         unlink(TESTFN)
index a67d72709d39abe9c556fc624fb92f122c4b9df5..b8d786bbd710cda888002e9afac5bd923c0eef2a 100644 (file)
 import os, unittest
 import sqlite3 as sqlite
 
-from test.support import LOOPBACK_TIMEOUT
 from test.support.os_helper import TESTFN, unlink
 
 from test.test_sqlite3.test_dbapi import memory_database
 
 
-TIMEOUT = LOOPBACK_TIMEOUT / 10
-
-
 class TransactionTests(unittest.TestCase):
     def setUp(self):
-        self.con1 = sqlite.connect(TESTFN, timeout=TIMEOUT)
+        # We can disable the busy handlers, since we control
+        # the order of SQLite C API operations.
+        self.con1 = sqlite.connect(TESTFN, timeout=0)
         self.cur1 = self.con1.cursor()
 
-        self.con2 = sqlite.connect(TESTFN, timeout=TIMEOUT)
+        self.con2 = sqlite.connect(TESTFN, timeout=0)
         self.cur2 = self.con2.cursor()
 
     def tearDown(self):
@@ -117,10 +115,8 @@ class TransactionTests(unittest.TestCase):
             self.cur2.execute("insert into test(i) values (5)")
 
     def test_locking(self):
-        """
-        This tests the improved concurrency with pysqlite 2.3.4. You needed
-        to roll back con2 before you could commit con1.
-        """
+        # This tests the improved concurrency with pysqlite 2.3.4. You needed
+        # to roll back con2 before you could commit con1.
         self.cur1.execute("create table test(i)")
         self.cur1.execute("insert into test(i) values (5)")
         with self.assertRaises(sqlite.OperationalError):