Skip to content

Commit

Permalink
Test to show closing is ok while reading
Browse files Browse the repository at this point in the history
  • Loading branch information
nsmith- committed Mar 7, 2024
1 parent 22a981c commit 0873cf4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/test_basicio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import asyncio
import os
import shutil
import socket
Expand Down Expand Up @@ -471,3 +472,34 @@ def test_cache_directory(localserver, clear_server, tmp_path):
with open(cache_directory / os.listdir(cache_directory)[0], "rb") as f:
contents = f.read()
assert contents == TESTDATA1.encode("utf-8")


def test_close_while_reading(localserver, clear_server):
remoteurl, localpath = localserver
data = TESTDATA1 * int(1e8 / len(TESTDATA1))
with open(localpath + "/testfile.txt", "w") as fout:
fout.write(data)

fs, _, (path,) = fsspec.get_fs_token_paths(remoteurl + "/testfile.txt")

async def reader():
tic = time.monotonic()
await fs._cat_file(path, start=0, end=None)
toc = time.monotonic()
return tic, toc

async def closer():
await asyncio.sleep(0.001)
tic = time.monotonic()
await fs._readonly_filehandle_cache._close(path, 1)
toc = time.monotonic()
return tic, toc

async def run():
(read_start, read_stop), (close_start, close_stop) = await asyncio.gather(
reader(), closer()
)
assert read_start < close_start < read_stop
assert read_start < close_stop < read_stop

asyncio.run(run())

0 comments on commit 0873cf4

Please sign in to comment.