Skip to content

Commit 4398326

Browse files
committed
Add a test for correctly flushing data to disk
1 parent 5ef868b commit 4398326

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

tests/test_igzip_threaded.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import subprocess
1313
import sys
1414
import tempfile
15+
import zlib
1516
from pathlib import Path
1617

1718
from isal import igzip_threaded
@@ -243,15 +244,28 @@ def test_threaded_program_can_exit_on_error(tmp_path, mode, threads):
243244

244245
@pytest.mark.parametrize("threads", [1, 2])
245246
def test_flush(tmp_path, threads):
247+
empty_block_end = b"\x00\x00\xff\xff"
248+
deflate_last_block = zlib.compress(b"", wbits=-15)
246249
test_file = tmp_path / "output.gz"
247250
with igzip_threaded.open(test_file, "wb", threads=threads) as f:
248251
f.write(b"1")
249252
f.flush()
250-
assert gzip.decompress(test_file.read_bytes()) == b"1"
253+
data = test_file.read_bytes()
254+
assert data[-4:] == empty_block_end
255+
# Cut off gzip header and end data with an explicit last block to
256+
# test if the data was compressed correctly.
257+
deflate_block = data[10:] + deflate_last_block
258+
assert zlib.decompress(deflate_block, wbits=-15) == b"1"
251259
f.write(b"2")
252260
f.flush()
253-
assert gzip.decompress(test_file.read_bytes()) == b"12"
261+
data = test_file.read_bytes()
262+
assert data[-4:] == empty_block_end
263+
deflate_block = data[10:] + deflate_last_block
264+
assert zlib.decompress(deflate_block, wbits=-15) == b"12"
254265
f.write(b"3")
255266
f.flush()
256-
assert gzip.decompress(test_file.read_bytes()) == b"123"
267+
data = test_file.read_bytes()
268+
assert data[-4:] == empty_block_end
269+
deflate_block = data[10:] + deflate_last_block
270+
assert zlib.decompress(deflate_block, wbits=-15) == b"123"
257271
assert gzip.decompress(test_file.read_bytes()) == b"123"

0 commit comments

Comments
 (0)