From f955e81043b1d04fe7c54c03eaec405c99968ae1 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Tue, 20 Jun 2023 16:36:59 -0700 Subject: [PATCH] CI: test under py311 Jammy only offers a py311 RC, so include the __slots__ hack to avoid the segfault from https://github.com/python/cpython/issues/99886. Fix up a test to work with the slotted connection. Change-Id: I0e928bcb3810e391297300f4949024db3cf87d05 --- .zuul.yaml | 19 +++++++++++++++++++ swift/common/db.py | 6 ++++++ test/unit/account/test_backend.py | 28 +++++++++++++++++++++------- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/.zuul.yaml b/.zuul.yaml index 16e5fd2e2d..ed446fee4d 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -136,6 +136,22 @@ python_version: '3.10' post-run: tools/playbooks/common/cover-post.yaml +- job: + name: swift-tox-py311 + parent: swift-tox-base + nodeset: ubuntu-jammy + description: | + Run unit-tests for swift under cPython version 3.11. + + Uses tox with the ``py311`` environment. + It sets TMPDIR to an XFS mount point created via + tools/test-setup.sh. + vars: + tox_envlist: py311 + bindep_profile: test py311 + python_version: '3.11' + post-run: tools/playbooks/common/cover-post.yaml + - job: name: swift-tox-func-py27 parent: swift-tox-base @@ -700,6 +716,8 @@ irrelevant-files: *unittest-irrelevant-files - swift-tox-py310: irrelevant-files: *unittest-irrelevant-files + - swift-tox-py311: + irrelevant-files: *unittest-irrelevant-files # Functional tests - swift-tox-func-py27: @@ -788,6 +806,7 @@ - swift-tox-py36 - swift-tox-py39 - swift-tox-py310 + - swift-tox-py311 - swift-tox-func-py27 - swift-tox-func-encryption-py27 - swift-tox-func-ec-py27 diff --git a/swift/common/db.py b/swift/common/db.py index 252a4d85d1..e539f09d97 100644 --- a/swift/common/db.py +++ b/swift/common/db.py @@ -129,6 +129,9 @@ class DatabaseAlreadyExists(sqlite3.DatabaseError): class GreenDBConnection(sqlite3.Connection): """SQLite DB Connection handler that plays well with eventlet.""" + # slots are needed for python 3.11.0 (there's an issue fixed in 3.11.1, + # see https://github.com/python/cpython/issues/99886) + __slots__ = ('timeout', 'db_file') def __init__(self, database, timeout=None, *args, **kwargs): if timeout is None: @@ -157,6 +160,9 @@ class GreenDBConnection(sqlite3.Connection): class GreenDBCursor(sqlite3.Cursor): """SQLite Cursor handler that plays well with eventlet.""" + # slots are needed for python 3.11.0 (there's an issue fixed in 3.11.1, + # see https://github.com/python/cpython/issues/99886) + __slots__ = ('timeout', 'db_file') def __init__(self, *args, **kwargs): self.timeout = args[0].timeout diff --git a/test/unit/account/test_backend.py b/test/unit/account/test_backend.py index ca8ef30e61..000a45417f 100644 --- a/test/unit/account/test_backend.py +++ b/test/unit/account/test_backend.py @@ -1521,23 +1521,37 @@ class TestAccountBrokerBeforeSPI(TestAccountBroker): real_get = broker.get called = [] + class ExpectedError(Exception): + '''Expected error to be raised during the test''' + @contextmanager def mock_get(): with real_get() as conn: - def mock_executescript(script): - if called: - raise Exception('kaboom!') - called.append(script) + class MockConn(object): + def __init__(self, real_conn): + self.real_conn = real_conn - conn.executescript = mock_executescript - yield conn + @property + def cursor(self): + return self.real_conn.cursor + + @property + def execute(self): + return self.real_conn.execute + + def executescript(self, script): + if called: + raise ExpectedError('kaboom!') + called.append(script) + + yield MockConn(conn) broker.get = mock_get try: broker._commit_puts() - except Exception: + except ExpectedError: pass else: self.fail('mock exception was not raised')