Skip to content

Instantly share code, notes, and snippets.

@colonelpanic8
Created February 23, 2024 08:46
Show Gist options
  • Save colonelpanic8/318222edd3bd66382d6fc4735982786c to your computer and use it in GitHub Desktop.
Save colonelpanic8/318222edd3bd66382d6fc4735982786c to your computer and use it in GitHub Desktop.
@pytest.mark.asyncio
async def test_merge_behavior(async_sessionmaker, stream_factory):
stream = stream_factory()
async with async_sessionmaker() as session:
for i in range(11):
stream.get_segment(i)
stream.record_exhaustion(i, (i + 1) * 100)
stream.get_segment(11)
stream.get_segment(12)
session.add(stream)
await session.commit()
session.expunge(stream)
async with async_sessionmaker() as session:
stream2 = await models.UploadStreamModel.async_get_by_id(session, stream.id)
stream2.record_exhaustion(11, 99999999)
stream2.get_segment(12).links_requested = 888
stream2.is_completed = True
await session.commit()
stream.get_segment(11).links_requested = 999
stream.segment_processing_cursor = 500
async with async_sessionmaker() as session:
session.add(stream)
await session.commit()
assert stream.is_completed
assert (
stream.get_segment(12).links_requested
== stream2.get_segment(12).links_requested
)
assert stream.get_segment(11).links_requested == 999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment