diff options
| author | Anton Khirnov <anton@khirnov.net> | 2025-08-28 11:00:59 +0200 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2025-09-14 13:32:45 -0300 |
| commit | c55953e9de408674d71db78ea4fff941972b2f0a (patch) | |
| tree | 3c343b3d0644d51b596e2cbf16fe586d86d57dae /bindings/python-cffi/tests/test_database.py | |
| parent | abdff73a3333b295a599135ad2777e852189e188 (diff) | |
bindings/python-cffi: handle NOTMUCH_STATUS_OPERATION_INVALIDATED
Raise it as a newly added OperationInvalidatedError exception.
Diffstat (limited to 'bindings/python-cffi/tests/test_database.py')
| -rw-r--r-- | bindings/python-cffi/tests/test_database.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/bindings/python-cffi/tests/test_database.py b/bindings/python-cffi/tests/test_database.py index 1143cf33..ece838ee 100644 --- a/bindings/python-cffi/tests/test_database.py +++ b/bindings/python-cffi/tests/test_database.py @@ -322,6 +322,41 @@ class TestQuery: with dbmod.Database(maildir.path, 'rw', config=notmuch2.Database.CONFIG.EMPTY) as db: yield db + def _db_modified(self, maildir, notmuch, ret_prepare=None): + # populate the database for the initial query + with dbmod.Database.create(maildir.path, config=notmuch2.Database.CONFIG.EMPTY) as db: + for i in range(32): + pathname = maildir.deliver(body = str(i))[1] + msg = db.add(str(pathname))[0] + msg.tags.add(str(i)) + + with dbmod.Database(maildir.path, 'ro', config=notmuch2.Database.CONFIG.EMPTY) as db: + # prepare value to be returned to caller + ret = ret_prepare(db) if ret_prepare else db + + # modify the database sufficiently to trigger DatabaseModifiedException + for i in range(16): + with dbmod.Database(maildir.path, 'rw', config=notmuch2.Database.CONFIG.EMPTY) as db_rw: + pathname = maildir.deliver(body = str(i))[1] + db_rw.add(str(pathname)) + + yield ret + + @pytest.fixture + def db_modified(self, maildir, notmuch): + "A db triggering DatabaseModifiedException." + yield from self._db_modified(maildir, notmuch) + + @pytest.fixture + def db_modified_messages(self, maildir, notmuch): + "A tuple of (db, messages) triggering DatabaseModifiedException." + yield from self._db_modified(maildir, notmuch, lambda db: (db, db.messages('*'))) + + @pytest.fixture + def db_modified_threads(self, maildir, notmuch): + "A tuple of (db, threads) triggering DatabaseModifiedException." + yield from self._db_modified(maildir, notmuch, lambda db: (db, db.threads('*'))) + def test_count_messages(self, db): assert db.count_messages('*') == 3 @@ -397,3 +432,52 @@ class TestQuery: assert isinstance(msg, notmuch2.Message) assert msg.alive del msg + + def test_operation_invalidated_query(self, db_modified): + # Test OperationInvalidatedError raised by instantiating the query. + for attempt in 1, 2: + try: + for msg in db_modified.messages('*'): + pass + break + except notmuch2.OperationInvalidatedError: + if attempt == 1: + db_modified.reopen() + continue + + raise + + def test_operation_invalidated_messages(self, db_modified_messages): + # Test OperationInvalidatedError raised by iterating over query results; + # the query itself is created while the database is still usable. + db, messages = db_modified_messages + + for attempt in 1, 2: + try: + for msg in messages: + pass + break + except notmuch2.OperationInvalidatedError: + if attempt == 1: + db.reopen() + messages = db.messages('*') + continue + + raise + + def test_operation_invalidated_threads(self, db_modified_threads): + db, threads = db_modified_threads + + for attempt in 1, 2: + try: + for t in threads: + for msg in t: + pass + break + except notmuch2.OperationInvalidatedError: + if attempt == 1: + db.reopen() + threads = db.threads('*') + continue + + raise |
