Skip to content

Commit f638476

Browse files
committed
test: Add negative cache system test
Signed-off-by: Anton Jastsuk <antonjastsuk66@gmail.com>
1 parent bcfc3a7 commit f638476

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
timeout_set 40 seconds
2+
MOUNT_EXTRA_CONFIG="sfsnegativecachesize=4,sfsnegativecachetimeout=9000" \
3+
USE_RAMDISK=YES \
4+
setup_local_empty_saunafs info
5+
6+
cd ${info[mount0]}
7+
8+
# Tweaks test
9+
expect_equals "9000" "$(cat ${info[mount0]}/.saunafs_tweaks | awk 'BEGIN{IGNORECASE=1} /negativecachetimeout/ {print $2}')"
10+
expect_equals "4" "$(cat ${info[mount0]}/.saunafs_tweaks | awk 'BEGIN{IGNORECASE=1} /negativecachemaxsize/ {print $2}')"
11+
12+
echo "NegativeCacheTimeout=9001" | sudo tee ${info[mount0]}/.saunafs_tweaks
13+
echo "NegativeCacheMaxSize=5" | sudo tee ${info[mount0]}/.saunafs_tweaks
14+
15+
expect_equals "9001" "$(cat ${info[mount0]}/.saunafs_tweaks | awk 'BEGIN{IGNORECASE=1} /negativecachetimeout/ {print $2}')"
16+
expect_equals "5" "$(cat ${info[mount0]}/.saunafs_tweaks | awk 'BEGIN{IGNORECASE=1} /negativecachemaxsize/ {print $2}')"
17+
18+
# Timeout test
19+
test_file=nonexistent_file
20+
assert_failure ls ${test_file}
21+
22+
touch ${test_file}
23+
assert_failure ls ${test_file}
24+
25+
assert_eventually "ls ${test_file}" "20 seconds"
26+
27+
# LRU eviction test, remove oldest when exceeds max size
28+
files1=({a..f}) # 6 files
29+
30+
# When file f is added, a is removed because it is oldest
31+
for file in ${files1[@]}; do assert_failure ls ${file}; done
32+
touch ${files1[0]}
33+
assert_success ls ${files1[0]}
34+
35+
# Tweaks change clears whole cache
36+
files2=({A..C})
37+
for file in ${files2[@]}; do assert_failure ls ${file}; done
38+
echo "NegativeCacheTimeout=9000" | sudo tee ${info[mount0]}/.saunafs_tweaks
39+
assert_failure ls D # clears caches
40+
touch ${files2[@]}
41+
for file in ${files2[@]}; do assert_success ls ${file}; done
42+
rm ${files2[@]}
43+
44+
for file in ${files2[@]}; do assert_failure ls ${file}; done
45+
echo "NegativeCacheMaxSize=4" | sudo tee ${info[mount0]}/.saunafs_tweaks
46+
assert_failure ls E # clears caches
47+
touch ${files2[@]}
48+
for file in ${files2[@]}; do assert_success ls ${file}; done

0 commit comments

Comments
 (0)