summaryrefslogtreecommitdiff
path: root/tests/unit/browser/test_history.py
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-02-03 18:23:31 +0100
committerFlorian Bruhin <me@the-compiler.org>2021-02-03 18:30:50 +0100
commit2b47bd01dbc15a02911989a190e2ef956aeedf27 (patch)
tree5c004dfba892c752273ab0bfb6e1b6124e9ffd36 /tests/unit/browser/test_history.py
parentc8601f1c1da7167cf71cd5af5fc1069a2b9bf7f0 (diff)
downloadqutebrowser-2b47bd01dbc15a02911989a190e2ef956aeedf27.tar.gz
qutebrowser-2b47bd01dbc15a02911989a190e2ef956aeedf27.zip
Improve rebuilding of history database
- Re-add the force_rebuild key which we need internally again. This partially reverts changes from: * cd0000f728459f208c4cf69f29b603fbcab6ffb4 * 1a9b59fcfa73d1505834d8461ee166f07fb201cd * 93ecd8f72f108743948f0d1881055ff2337058ec - Instead of checking self.completion to figure out whether we need to rebuild anything, check 'self' (i.e. the History table, not the CompletionHistory table). If something went wrong during the last rebuild, the CompletionHistory might still be empty, but History is what actually matters to figure out whether to rebuild. - Set force_rebuild while rebuilding the history, so that a possible interruption of the process (e.g. by a killed process or crash) results in another rebuild from scratch. - Bump up the user version again, so that we re-add force_rebuild to the database. This also forces another rebuild which helps with possible inconsistent data when someone interrupted the earlier rebuild for v2.0.0. Fixes #6111
Diffstat (limited to 'tests/unit/browser/test_history.py')
-rw-r--r--tests/unit/browser/test_history.py42
1 files changed, 36 insertions, 6 deletions
diff --git a/tests/unit/browser/test_history.py b/tests/unit/browser/test_history.py
index 9e3bd0519..c032f6265 100644
--- a/tests/unit/browser/test_history.py
+++ b/tests/unit/browser/test_history.py
@@ -392,6 +392,25 @@ class TestRebuild:
('example.com/1', '', 1),
('example.com/2', '', 2),
]
+ assert not hist3.metainfo['force_rebuild']
+
+ def test_force_rebuild(self, web_history, stubs):
+ """Ensure that completion is regenerated if we force a rebuild."""
+ web_history.add_url(QUrl('example.com/1'), redirect=False, atime=1)
+ web_history.add_url(QUrl('example.com/2'), redirect=False, atime=2)
+ web_history.completion.delete('url', 'example.com/2')
+
+ hist2 = history.WebHistory(progress=stubs.FakeHistoryProgress())
+ # User version always changes, so this won't work
+ # assert list(hist2.completion) == [('example.com/1', '', 1)]
+ hist2.metainfo['force_rebuild'] = True
+
+ hist3 = history.WebHistory(progress=stubs.FakeHistoryProgress())
+ assert list(hist3.completion) == [
+ ('example.com/1', '', 1),
+ ('example.com/2', '', 2),
+ ]
+ assert not hist3.metainfo['force_rebuild']
def test_exclude(self, config_stub, web_history, stubs):
"""Ensure that patterns in completion.web_history.exclude are ignored.
@@ -443,6 +462,23 @@ class TestRebuild:
assert progress._started
assert progress._finished
+ def test_interrupted(self, stubs, web_history, monkeypatch):
+ """If we interrupt the rebuilding process, force_rebuild should still be set."""
+ web_history.add_url(QUrl('example.com/1'), redirect=False, atime=1)
+ progress = stubs.FakeHistoryProgress(raise_on_tick=True)
+
+ # Trigger a completion rebuild
+ monkeypatch.setattr(sql, 'user_version_changed', lambda: True)
+
+ with pytest.raises(Exception, match='tick-tock'):
+ history.WebHistory(progress=progress)
+
+ assert web_history.metainfo['force_rebuild']
+
+ # If we now try again, we should get another rebuild. But due to user_version
+ # always changing, we can't test this at the moment (see the FIXME in the
+ # docstring for details)
+
class TestCompletionMetaInfo:
@@ -466,12 +502,6 @@ class TestCompletionMetaInfo:
def test_contains(self, metainfo):
assert 'excluded_patterns' in metainfo
- def test_delete_old_key(self, monkeypatch, metainfo):
- metainfo.insert({'key': 'force_rebuild', 'value': False})
- info2 = history.CompletionMetaInfo()
- monkeypatch.setitem(info2.KEYS, 'force_rebuild', False)
- assert 'force_rebuild' not in info2
-
def test_modify(self, metainfo):
assert not metainfo['excluded_patterns']
value = 'https://example.com/'