Skip to content
Snippets Groups Projects
Verified Commit 7225c537 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

tests: Refactor scenario about visits on repository with changes

For this, switch to using a pg storage to share the state amongst visit.

Related to T2462
parent 58bb1e46
No related branches found
No related tags found
1 merge request!175tests: Refactor scenario about visits on repository with changes
pytest
pytest-mock
pytest-postgresql
swh.core[http] >= 0.0.61
......@@ -10,10 +10,12 @@ import yaml
from typing import Any, Dict
from swh.scheduler.tests.conftest import swh_app # noqa
from swh.storage.tests.conftest import * # noqa
@pytest.fixture
def swh_loader_config() -> Dict[str, Any]:
def swh_loader_config(swh_storage_backend_config) -> Dict[str, Any]:
swh_storage_backend_config["journal_writer"] = {}
return {
"storage": {
"cls": "pipeline",
......@@ -29,7 +31,7 @@ def swh_loader_config() -> Dict[str, Any]:
"release": 100,
},
},
{"cls": "memory"},
swh_storage_backend_config,
],
},
"check_revision": {"limit": 100, "status": False},
......
......@@ -320,56 +320,73 @@ class SvnLoaderTest3(BaseSvnLoaderTest):
assert visit_status.snapshot is None
class SvnLoaderTest4(BaseSvnLoaderTest):
def test_loader_svn_visit_with_changes(swh_config, datadir, tmp_path):
"""In this scenario, the repository has been updated with new changes.
The loading visit should result in new objects stored and 1 new
snapshot.
"""
archive_name = "pkg-gourmet"
archive_path = os.path.join(datadir, f"{archive_name}.tgz")
repo_initial_url = prepare_repository_from_archive(
archive_path, archive_name, tmp_path
)
def setUp(self):
# the svn repository pkg-gourmet has been updated with changes
super().setUp(
archive_name="pkg-gourmet-with-updates.tgz", snapshot=_LAST_SNP_REV
)
# repo_initial_url becomes the origin_url we want to visit some more below
loader = SvnLoader(repo_initial_url)
def test_process_repository(self):
"""Process updated repository should yield new objects
assert loader.load() == {"status": "eventful"}
visit_status1 = assert_last_visit_matches(
loader.storage,
repo_initial_url,
status="full",
type="svn",
snapshot=GOURMET_SNAPSHOT,
)
"""
# when
assert self.loader.load() == {"status": "eventful"}
archive_path = os.path.join(datadir, "pkg-gourmet-with-updates.tgz")
repo_updated_url = prepare_repository_from_archive(
archive_path, "pkg-gourmet", tmp_path
)
# then
# we got the previous run's last revision (rev 6)
# so 2 new
self.assertCountRevisions(5)
self.assertCountReleases(0)
loader = SvnLoader(repo_updated_url, origin_url=repo_initial_url,)
last_revision = "171dc35522bfd17dda4e90a542a0377fb2fc707a"
# cf. test_loader.org for explaining from where those hashes
# come from
expected_revisions = {
# revision hash | directory hash
"7f5bc909c29d4e93d8ccfdda516e51ed44930ee1": "752c52134dcbf2fff13c7be1ce4e9e5dbf428a59", # noqa
"38d81702cb28db4f1a6821e64321e5825d1f7fd6": "39c813fb4717a4864bacefbd90b51a3241ae4140", # noqa
"99c27ebbd43feca179ac0e895af131d8314cafe1": "3397ca7f709639cbd36b18a0d1b70bce80018c45", # noqa
"902f29b4323a9b9de3af6d28e72dd581e76d9397": "c4e12483f0a13e6851459295a4ae735eb4e4b5c4", # noqa
last_revision: "fd24a76c87a3207428e06612b49860fc78e9f6dc", # noqa
}
assert loader.load() == {"status": "eventful"}
visit_status2 = assert_last_visit_matches(
loader.storage,
repo_updated_url,
status="full",
type="svn",
snapshot=GOURMET_UPDATES_SNAPSHOT,
)
self.assertRevisionsContain(expected_revisions)
assert visit_status1.date < visit_status2.date
assert visit_status1.snapshot != visit_status2.snapshot
self.assertCountSnapshots(1)
self.assertEqual(self.loader.visit_status(), "full")
stats = get_stats(loader.storage)
assert stats == {
"content": 22,
"directory": 28,
"origin": 1,
"origin_visit": 2,
"person": 2,
"release": 0,
"revision": 11,
"skipped_content": 0,
"snapshot": 2,
}
assert_last_visit_matches(
self.storage,
self.repo_url,
status="full",
type="svn",
snapshot=GOURMET_UPDATES_SNAPSHOT,
)
expected_snapshot = {
"id": GOURMET_UPDATES_SNAPSHOT,
"branches": {
"HEAD": {
"target": "171dc35522bfd17dda4e90a542a0377fb2fc707a",
"target_type": "revision",
}
},
}
check_snapshot(expected_snapshot, loader.storage)
class SvnLoaderTest5(BaseSvnLoaderTest):
......@@ -430,81 +447,6 @@ class SvnLoaderTest5(BaseSvnLoaderTest):
)
class SvnLoaderTest6(BaseSvnLoaderTest):
"""Context:
- repository already visited with load successful
- Changes on existing repository
- New Visit done with successful new data
"""
def setUp(self):
last_snp_rev = {
"snapshot": None,
"revision": {
"id": hashutil.hash_to_bytes(
"4876cb10aec6f708f7466dddf547567b65f6c39c"
),
"parents": (
hashutil.hash_to_bytes("a3a577948fdbda9d1061913b77a1588695eadb41"),
),
"directory": hashutil.hash_to_bytes(
"0deab3023ac59398ae467fc4bff5583008af1ee2"
),
"target_type": "revision",
"metadata": {
"extra_headers": [
[
"svn_repo_uuid",
"3187e211-bb14-4c82-9596-0b59d67cd7f4",
], # noqa
["svn_revision", "6"],
]
},
},
}
super().setUp(
archive_name="pkg-gourmet-with-updates.tgz", snapshot=last_snp_rev
)
def test_load(self):
"""Load from partial previous visit result in new changes
"""
# when
assert self.loader.load() == {"status": "eventful"}
# then
# we got the previous run's last revision (rev 6)
# so 2 new
self.assertCountRevisions(5)
self.assertCountReleases(0)
last_revision = "171dc35522bfd17dda4e90a542a0377fb2fc707a"
# cf. test_loader.org for explaining from where those hashes
# come from
expected_revisions = {
# revision hash | directory hash
"7f5bc909c29d4e93d8ccfdda516e51ed44930ee1": "752c52134dcbf2fff13c7be1ce4e9e5dbf428a59", # noqa
"38d81702cb28db4f1a6821e64321e5825d1f7fd6": "39c813fb4717a4864bacefbd90b51a3241ae4140", # noqa
"99c27ebbd43feca179ac0e895af131d8314cafe1": "3397ca7f709639cbd36b18a0d1b70bce80018c45", # noqa
"902f29b4323a9b9de3af6d28e72dd581e76d9397": "c4e12483f0a13e6851459295a4ae735eb4e4b5c4", # noqa
last_revision: "fd24a76c87a3207428e06612b49860fc78e9f6dc", # noqa
}
self.assertRevisionsContain(expected_revisions)
self.assertCountSnapshots(1)
self.assertEqual(self.loader.visit_status(), "full")
assert_last_visit_matches(
self.storage,
self.repo_url,
status="full",
type="svn",
snapshot=GOURMET_UPDATES_SNAPSHOT,
)
class SvnLoaderTest7(BaseSvnLoaderTest):
"""Context:
- repository already visited with load successful
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment