diff options
author | David Robertson <davidr@element.io> | 2023-09-01 12:41:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-01 12:41:56 +0100 |
commit | 6525fd65ee52e36929b9c35253c772da16aa2b99 (patch) | |
tree | 54a1f978d6966ba24042eeb9defa93c0d43992ae /tests | |
parent | Ignore redundant casts in latest deps CI job (#16213) (diff) | |
download | synapse-6525fd65ee52e36929b9c35253c772da16aa2b99.tar.xz |
Log the details of background update failures (#16212)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/storage/test_background_update.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/storage/test_background_update.py b/tests/storage/test_background_update.py index 52beb4e89d..abf7d0564d 100644 --- a/tests/storage/test_background_update.py +++ b/tests/storage/test_background_update.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +import logging from unittest.mock import AsyncMock, Mock import yaml @@ -330,6 +330,28 @@ class BackgroundUpdateTestCase(unittest.HomeserverTestCase): self.update_handler.side_effect = update_short self.get_success(self.updates.do_next_background_update(False)) + def test_failed_update_logs_exception_details(self) -> None: + needle = "RUH ROH RAGGY" + + def failing_update(progress: JsonDict, count: int) -> int: + raise Exception(needle) + + self.update_handler.side_effect = failing_update + self.update_handler.reset_mock() + + self.get_success( + self.store.db_pool.simple_insert( + "background_updates", + values={"update_name": "test_update", "progress_json": "{}"}, + ) + ) + + with self.assertLogs(level=logging.ERROR) as logs: + # Expect a back-to-back RuntimeError to be raised + self.get_failure(self.updates.run_background_updates(False), RuntimeError) + + self.assertTrue(any(needle in log for log in logs.output), logs.output) + class BackgroundUpdateControllerTestCase(unittest.HomeserverTestCase): def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None: |