Skip to content

Commit

Permalink
Add test cases for stability
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghua committed Sep 24, 2024
1 parent 14c3fa2 commit 45cee34
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tosfs/tests/test_stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,33 @@

def test_write_breakpoint_continuation(tosfs, bucket, temporary_workspace):
file_name = f"{random_str()}.txt"
first_part = random_str(10 * 1024 * 1024)
second_part = random_str(10 * 1024 * 1024)
first_part = random_str(9 * 1024 * 1024)
second_part = random_str(9 * 1024 * 1024)

with tosfs.open(f"{bucket}/{temporary_workspace}/{file_name}", "w") as f:
f.write(first_part)
# mock a very long block(business processing or network issue)
sleep(60)
f.write(second_part)

with tosfs.open(file_name, "r") as f:
with tosfs.open(f"{bucket}/{temporary_workspace}/{file_name}", "r") as f:
assert f.read() == first_part + second_part


def test_read_breakpoint_continuation(tosfs, bucket, temporary_workspace):
file_name = f"{random_str()}.txt"
first_part = random_str(10 * 1024 * 1024)
second_part = random_str(10 * 1024 * 1024)
first_part = random_str(9 * 1024 * 1024)
second_part = random_str(9 * 1024 * 1024)

with tosfs.open(f"{bucket}/{temporary_workspace}/{file_name}", "w") as f:
f.write(first_part)
f.write(second_part)

with tosfs.open(file_name, "r") as f:
read_first_part = f.read(10 * 1024 * 1024)
with tosfs.open(f"{bucket}/{temporary_workspace}/{file_name}", "r") as f:
read_first_part = f.read(9 * 1024 * 1024)
assert read_first_part == first_part
# mock a very long block(business processing or network issue)
sleep(60)
read_second_part = f.read(10 * 1024 * 1024)
read_second_part = f.read(9 * 1024 * 1024)
assert read_second_part == second_part
assert read_first_part + read_second_part == first_part + second_part

0 comments on commit 45cee34

Please sign in to comment.