Skip to content

Commit 8fbf7dd

Browse files
pythongh-108550: Speed up sqlite3 tests (python#108551)
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 <[email protected]>
1 parent c19713d commit 8fbf7dd

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

Lib/test/test_sqlite3/test_dbapi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ def test_on_conflict_replace(self):
18371837

18381838
@requires_subprocess()
18391839
class MultiprocessTests(unittest.TestCase):
1840-
CONNECTION_TIMEOUT = SHORT_TIMEOUT / 1000. # Defaults to 30 ms
1840+
CONNECTION_TIMEOUT = 0 # Disable the busy timeout.
18411841

18421842
def tearDown(self):
18431843
unlink(TESTFN)

Lib/test/test_sqlite3/test_transactions.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,19 @@
2323
import os, unittest
2424
import sqlite3 as sqlite
2525

26-
from test.support import LOOPBACK_TIMEOUT
2726
from test.support.os_helper import TESTFN, unlink
2827

2928
from test.test_sqlite3.test_dbapi import memory_database
3029

3130

32-
TIMEOUT = LOOPBACK_TIMEOUT / 10
33-
34-
3531
class TransactionTests(unittest.TestCase):
3632
def setUp(self):
37-
self.con1 = sqlite.connect(TESTFN, timeout=TIMEOUT)
33+
# We can disable the busy handlers, since we control
34+
# the order of SQLite C API operations.
35+
self.con1 = sqlite.connect(TESTFN, timeout=0)
3836
self.cur1 = self.con1.cursor()
3937

40-
self.con2 = sqlite.connect(TESTFN, timeout=TIMEOUT)
38+
self.con2 = sqlite.connect(TESTFN, timeout=0)
4139
self.cur2 = self.con2.cursor()
4240

4341
def tearDown(self):
@@ -117,10 +115,8 @@ def test_raise_timeout(self):
117115
self.cur2.execute("insert into test(i) values (5)")
118116

119117
def test_locking(self):
120-
"""
121-
This tests the improved concurrency with pysqlite 2.3.4. You needed
122-
to roll back con2 before you could commit con1.
123-
"""
118+
# This tests the improved concurrency with pysqlite 2.3.4. You needed
119+
# to roll back con2 before you could commit con1.
124120
self.cur1.execute("create table test(i)")
125121
self.cur1.execute("insert into test(i) values (5)")
126122
with self.assertRaises(sqlite.OperationalError):

0 commit comments

Comments
 (0)