Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
tests/test-cache-block-size.sh | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/tests/test-cache-block-size.sh b/tests/test-cache-block-size.sh
index d20cc94002b6..5e83ebc1cfaa 100755
--- a/tests/test-cache-block-size.sh
+++ b/tests/test-cache-block-size.sh
@@ -47,24 +47,35 @@ truncate -s 128K cache-block-size.img
# Run nbdkit with the caching filter.
start_nbdkit -P cache-block-size.pid -U $sock --filter=cache \
- file cache-block-size.img cache-min-block-size=4K
+ file cache-block-size.img cache-min-block-size=64K \
+ cache-on-read=true
nbdsh --connect "nbd+unix://?socket=$sock" \
-c '
-# Write some pattern data to the overlay and check it reads back OK.
-buf = b"abcd" * 16384
-h.pwrite(buf, 32768)
+# Read half of cache-min-block-size
+
zero = h.pread(32768, 0)
assert zero == bytearray(32768)
-buf2 = h.pread(65536, 32768)
-assert buf == buf2
-# Flushing should write through to the underlying file.
-h.flush()
+buf = b"abcd" * 8192
+# Write past the first read
+with open("cache-block-size.img", "wb") as file:
+ file.seek(32768)
+ file.write(buf * 2)
+ file.truncate(131072)
+
+# Check that it got written
with open("cache-block-size.img", "rb") as file:
- zero = file.read(32768)
- assert zero == bytearray(32768)
+ file.seek(32768)
buf2 = file.read(65536)
- assert buf == buf2
+ assert (buf * 2) == buf2
+
+# Now read the rest of the cache-min-block-size, it should stay empty
+zero = h.pread(32768, 32768)
+assert zero == bytearray(32768)
+
+# Read past that, the pattern should be visible there
+buf2 = h.pread(32768, 65536)
+assert buf == buf2
'
--
2.32.0