diff --git a/swh/journal/tests/journal_data.py b/swh/journal/tests/journal_data.py --- a/swh/journal/tests/journal_data.py +++ b/swh/journal/tests/journal_data.py @@ -3,7 +3,6 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -import copy import datetime from typing import Any, Dict, List, Type @@ -157,58 +156,83 @@ { "origin": ORIGINS[0]["url"], "date": datetime.datetime(2013, 5, 7, 4, 20, 39, 369271, tzinfo=UTC), - "snapshot": None, - "status": "ongoing", - "metadata": None, - "type": "git", "visit": 1, + "type": "git", }, { "origin": ORIGINS[1]["url"], "date": datetime.datetime(2014, 11, 27, 17, 20, 39, tzinfo=UTC), - "snapshot": None, - "status": "ongoing", - "metadata": None, - "type": "hg", "visit": 1, + "type": "hg", }, { "origin": ORIGINS[0]["url"], "date": datetime.datetime(2018, 11, 27, 17, 20, 39, tzinfo=UTC), + "visit": 2, + "type": "git", + }, + { + "origin": ORIGINS[0]["url"], + "date": datetime.datetime(2018, 11, 27, 17, 20, 39, tzinfo=UTC), + "visit": 3, + "type": "git", + }, + { + "origin": ORIGINS[1]["url"], + "date": datetime.datetime(2015, 11, 27, 17, 20, 39, tzinfo=UTC), + "visit": 2, + "type": "hg", + }, +] + +# The origin-visit-status dates needs to be shifted slightly in the future from their +# visit dates counterpart. Otherwise, we are hitting storage-wise the "on conflict" +# ignore policy (because origin-visit-add creates an origin-visit-status with the same +# parameters from the origin-visit {origin, visit, date}... +ORIGIN_VISIT_STATUSES = [ + { + "origin": ORIGINS[0]["url"], + "date": datetime.datetime(2013, 5, 7, 4, 20, 39, 432222, tzinfo=UTC), + "visit": 1, + "status": "ongoing", "snapshot": None, + "metadata": None, + }, + { + "origin": ORIGINS[1]["url"], + "date": datetime.datetime(2014, 11, 27, 17, 21, 12, tzinfo=UTC), + "visit": 1, "status": "ongoing", + "snapshot": None, "metadata": None, - "type": "git", + }, + { + "origin": ORIGINS[0]["url"], + "date": datetime.datetime(2018, 11, 27, 17, 20, 59, tzinfo=UTC), "visit": 2, + "status": "ongoing", + "snapshot": None, + "metadata": None, }, { "origin": ORIGINS[0]["url"], - "date": datetime.datetime(2018, 11, 27, 17, 20, 39, tzinfo=UTC), - "snapshot": hash_to_bytes("742cdc6be7bf6e895b055227c2300070f056e07b"), + "date": datetime.datetime(2018, 11, 27, 17, 20, 49, tzinfo=UTC), + "visit": 3, "status": "full", + "snapshot": hash_to_bytes("742cdc6be7bf6e895b055227c2300070f056e07b"), "metadata": None, - "type": "git", - "visit": 3, }, { "origin": ORIGINS[1]["url"], - "date": datetime.datetime(2015, 11, 27, 17, 20, 39, tzinfo=UTC), - "snapshot": hash_to_bytes("ecee48397a92b0d034e9752a17459f3691a73ef9"), + "date": datetime.datetime(2015, 11, 27, 17, 22, 18, tzinfo=UTC), + "visit": 2, "status": "partial", + "snapshot": hash_to_bytes("ecee48397a92b0d034e9752a17459f3691a73ef9"), "metadata": None, - "type": "hg", - "visit": 2, }, ] -ORIGIN_VISIT_STATUSES = [] -for visit in ORIGIN_VISITS: - visit_status = copy.deepcopy(visit) - visit_status.pop("type") - ORIGIN_VISIT_STATUSES.append(visit_status) - - DIRECTORIES = [ {"id": hash_to_bytes("4b825dc642cb6eb9a060e54bf8d69288fbee4904"), "entries": ()}, { @@ -270,7 +294,11 @@ "content": CONTENTS, "directory": DIRECTORIES, "origin": ORIGINS, - "origin_visit": ORIGIN_VISITS, + "origin_visit": [ + # temporary adaptation to remove when fields are dropped + {**o, "status": None, "snapshot": None, "metadata": None} + for o in ORIGIN_VISITS + ], "origin_visit_status": ORIGIN_VISIT_STATUSES, "release": RELEASES, "revision": REVISIONS, diff --git a/swh/journal/tests/test_journal_data.py b/swh/journal/tests/test_journal_data.py new file mode 100644 --- /dev/null +++ b/swh/journal/tests/test_journal_data.py @@ -0,0 +1,23 @@ +# Copyright (C) 2020 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + +from swh.journal.tests.journal_data import TEST_OBJECTS + + +def test_ensure_visit_visit_status_date_consistency(): + """ensure origin-visit-status dates are more recent than their visit counterpart + + The origin-visit-status dates needs to be shifted slightly in the future from their + visit dates counterpart. Otherwise, we are hitting storage-wise the "on conflict" + ignore policy (because origin-visit-add creates an origin-visit-status with the same + parameters from the origin-visit {origin, visit, date}... + + """ + visits = TEST_OBJECTS["origin_visit"] + visit_statuses = TEST_OBJECTS["origin_visit_status"] + for visit, visit_status in zip(visits, visit_statuses): + assert visit.origin == visit_status.origin + assert visit.visit == visit_status.visit + assert visit.date < visit_status.date