Skip to content

Commit

Permalink
explicit flush
Browse files Browse the repository at this point in the history
  • Loading branch information
gdassori committed Jun 12, 2021
1 parent b3e706b commit dd73eb6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions aiodiskdb/aiodiskdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ def _is_file_header(self, data: bytes) -> bool:
return False
return True

@ensure_async_lock(LockType.TRANSACTION)
async def flush(self):
if not self._buffers[-1].data:
return
return await self._flush_buffer_no_transaction_lock()

@ensure_async_lock(LockType.TRANSACTION)
async def _flush_buffer(self):
"""
Expand Down
14 changes: 14 additions & 0 deletions test/test_read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
from test import AioDiskDBTestCase, run_test_db


class TestFlush(AioDiskDBTestCase):
@run_test_db
async def test(self):
item_location = await self.sut.add(b'test_1')
self.assertEqual(
ItemLocation(0, 0, 6),
item_location
)
await self.sut.flush()
self.assertEqual(self.sut._buffers[-1].data, b'')
read1 = await self.sut.read(item_location)
self.assertEqual(b'test_1', read1)


class TestReadWriteCached(AioDiskDBTestCase):
@run_test_db
async def test(self):
Expand Down

0 comments on commit dd73eb6

Please sign in to comment.