[3.11] gh-108550: Speed up sqlite3 tests (#108551) (#108567)

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>
This commit is contained in:
Erlend E. Aasland 2023-08-28 15:09:10 +02:00 committed by GitHub
parent c19713d4a1
commit 6f6171b33b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 11 deletions

View file

@ -1837,7 +1837,7 @@ def test_on_conflict_replace(self):
@requires_subprocess() @requires_subprocess()
class MultiprocessTests(unittest.TestCase): class MultiprocessTests(unittest.TestCase):
CONNECTION_TIMEOUT = SHORT_TIMEOUT / 1000. # Defaults to 30 ms CONNECTION_TIMEOUT = 0 # Disable the busy timeout.
def tearDown(self): def tearDown(self):
unlink(TESTFN) unlink(TESTFN)

View file

@ -23,21 +23,19 @@
import os, unittest import os, unittest
import sqlite3 as sqlite import sqlite3 as sqlite
from test.support import LOOPBACK_TIMEOUT
from test.support.os_helper import TESTFN, unlink from test.support.os_helper import TESTFN, unlink
from test.test_sqlite3.test_dbapi import memory_database from test.test_sqlite3.test_dbapi import memory_database
TIMEOUT = LOOPBACK_TIMEOUT / 10
class TransactionTests(unittest.TestCase): class TransactionTests(unittest.TestCase):
def setUp(self): 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.cur1 = self.con1.cursor()
self.con2 = sqlite.connect(TESTFN, timeout=TIMEOUT) self.con2 = sqlite.connect(TESTFN, timeout=0)
self.cur2 = self.con2.cursor() self.cur2 = self.con2.cursor()
def tearDown(self): def tearDown(self):
@ -117,10 +115,8 @@ def test_raise_timeout(self):
self.cur2.execute("insert into test(i) values (5)") self.cur2.execute("insert into test(i) values (5)")
def test_locking(self): def test_locking(self):
""" # This tests the improved concurrency with pysqlite 2.3.4. You needed
This tests the improved concurrency with pysqlite 2.3.4. You needed # to roll back con2 before you could commit con1.
to roll back con2 before you could commit con1.
"""
self.cur1.execute("create table test(i)") self.cur1.execute("create table test(i)")
self.cur1.execute("insert into test(i) values (5)") self.cur1.execute("insert into test(i) values (5)")
with self.assertRaises(sqlite.OperationalError): with self.assertRaises(sqlite.OperationalError):