Sync implementation
This commit is contained in:
parent
c6bd8d8556
commit
74e9091065
3 changed files with 176 additions and 12 deletions
|
|
@ -104,6 +104,28 @@ FEED = feed.Feed(
|
|||
],
|
||||
)
|
||||
|
||||
OTHER_FEED = feed.Feed(
|
||||
meta=feed.FeedMeta(
|
||||
url="http://example.com/test/other",
|
||||
last_fetched_ts=REF_TIME,
|
||||
retry_after_ts=REF_TIME,
|
||||
status=feed.FEED_STATUS_ALIVE,
|
||||
etag=random_slug(),
|
||||
modified=random_slug(),
|
||||
),
|
||||
title="Other Test Feed",
|
||||
link="http://example.com/other",
|
||||
entries=[
|
||||
feed.Entry(
|
||||
id=random_slug(),
|
||||
inserted_at=(REF_TIME * 1000) + index,
|
||||
title=f"Entry {index}",
|
||||
link=f"http://example.com/other/a{index}",
|
||||
)
|
||||
for index in range(100, 0, -1)
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def test_database_load_store_meta():
|
||||
db = database.Database(":memory:", random_slug())
|
||||
|
|
@ -274,6 +296,7 @@ def test_database_store_with_older_entries():
|
|||
db.store_feed(FEED)
|
||||
|
||||
old_entry = FEED.entries[0]
|
||||
assert old_entry.link is not None
|
||||
|
||||
older_entry = dataclasses.replace(
|
||||
old_entry,
|
||||
|
|
@ -314,7 +337,7 @@ def test_database_store_update_meta():
|
|||
assert db.load_all_meta()[0] == new_meta
|
||||
|
||||
|
||||
def test_database_store_update_meta():
|
||||
def test_database_store_update_meta_clock():
|
||||
db = database.Database(":memory:", random_slug())
|
||||
db.ensure_database_schema()
|
||||
|
||||
|
|
@ -413,3 +436,51 @@ def test_database_redirect_clock():
|
|||
db.redirect_feed(FEED.meta.url, new_url)
|
||||
|
||||
assert db.get_clock() != old_clock
|
||||
|
||||
|
||||
def test_database_sync_clocks():
|
||||
db = database.Database(":memory:", random_slug())
|
||||
db.ensure_database_schema()
|
||||
|
||||
other_origin = f"other_{random_slug()}"
|
||||
|
||||
other_clock = db.get_sync_clock(other_origin)
|
||||
assert other_clock is None
|
||||
|
||||
db.set_sync_clock(other_origin, 1234)
|
||||
|
||||
other_clock = db.get_sync_clock(other_origin)
|
||||
assert other_clock == 1234
|
||||
|
||||
|
||||
def test_database_do_sync():
|
||||
db = database.Database(":memory:", random_slug())
|
||||
db.ensure_database_schema()
|
||||
|
||||
other = database.Database(":memory:", random_slug())
|
||||
other.ensure_database_schema()
|
||||
|
||||
other.store_feed(FEED)
|
||||
other.store_feed(OTHER_FEED)
|
||||
|
||||
db.sync_from(other)
|
||||
|
||||
others = db.load_all(feed_limit=99999)
|
||||
assert others == [FEED, OTHER_FEED]
|
||||
|
||||
|
||||
def test_database_do_sync_conflict():
|
||||
db = database.Database(":memory:", random_slug())
|
||||
db.ensure_database_schema()
|
||||
|
||||
other = database.Database(":memory:", random_slug())
|
||||
other.ensure_database_schema()
|
||||
|
||||
db.store_feed(FEED)
|
||||
other.store_feed(FEED)
|
||||
other.store_feed(OTHER_FEED)
|
||||
|
||||
db.sync_from(other)
|
||||
|
||||
feeds = db.load_all(feed_limit=99999)
|
||||
assert feeds == [FEED, OTHER_FEED]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue