Add test for hitting max open files

This commit is contained in:
Tor Arne Vestbø
2021-06-30 20:57:06 +02:00
parent 80f5a0dda4
commit fab4ea622e
5 changed files with 77 additions and 29 deletions

25
tests/20_basic_read.tst Normal file
View File

@@ -0,0 +1,25 @@
#!/usr/bin/env testrunner.sh
source "$(dirname "$0")/testhelpers.sh"
mount_options="-o noreadbuf"
function setup() {
read -r mount_dir dmg_file < <(mount_sparsebundle $mount_options)
}
function test_dmg_has_correct_number_of_blocks() {
_test_dmg_has_correct_number_of_blocks
}
function test_dmg_contents_is_same_as_testdata() {
_test_dmg_contents_is_same_as_testdata
}
function test_can_handle_ulimit() {
_test_can_handle_ulimit
}
function teardown() {
umount $mount_dir && rm -Rf $mount_dir
}

View File

@@ -1,22 +0,0 @@
#!/usr/bin/env testrunner.sh
source "$(dirname "$0")/testhelpers.sh"
function setup() {
read -r mount_dir dmg_file < <(mount_sparsebundle -o noreadbuf)
}
function test_dmg_has_correct_number_of_blocks() {
hfsdump $dmg_file | grep "total_blocks: 268435456"
}
function test_dmg_contents_is_same_as_testdata() {
for f in $(ls $HFSFUSE_DIR/src); do
echo "Diffing $HFSFUSE_DIR/src/$f"
diff $HFSFUSE_DIR/src/$f <(hfsdump $dmg_file read "/src/$f")
done
}
function teardown() {
umount $mount_dir && rm -Rf $mount_dir
}

View File

@@ -7,16 +7,17 @@ function setup() {
}
function test_dmg_has_correct_number_of_blocks() {
hfsdump $dmg_file | grep "total_blocks: 268435456"
_test_dmg_has_correct_number_of_blocks
}
function test_dmg_contents_is_same_as_testdata() {
for f in $(ls $HFSFUSE_DIR/src); do
echo "Diffing $HFSFUSE_DIR/src/$f"
diff $HFSFUSE_DIR/src/$f <(hfsdump $dmg_file read "/src/$f")
done
_test_dmg_contents_is_same_as_testdata
}
function test_can_handle_ulimit() {
_test_can_handle_ulimit
}
function teardown() {
umount $mount_dir && rm -Rf $mount_dir
}
}

View File

@@ -1,9 +1,16 @@
sparsebundlefs_ulimit=
function mount_sparsebundle() {
test ! -z "$TEST_BUNDLE"
local mount_dir=$(mktemp -d)
local dmg_file="$mount_dir/sparsebundle.dmg"
sparsebundlefs -s -f -D $* $TEST_BUNDLE $mount_dir &
(
if [[ ! -z "${sparsebundlefs_ulimit}" ]]; then
ulimit -n $sparsebundlefs_ulimit
fi
sparsebundlefs -s -f -D $* $TEST_BUNDLE $mount_dir
) &
local pid=$!
for i in {0..50}; do
kill -0 $pid >/dev/null 2>&1
@@ -12,3 +19,40 @@ function mount_sparsebundle() {
echo $mount_dir "$mount_dir/sparsebundle.dmg"
}
function _test_dmg_has_correct_number_of_blocks() {
hfsdump $dmg_file | grep "total_blocks: 268435456"
}
function _test_dmg_contents_is_same_as_testdata() {
for f in $(ls $HFSFUSE_DIR/src); do
echo "Diffing $HFSFUSE_DIR/src/$f"
diff $HFSFUSE_DIR/src/$f <(hfsdump $dmg_file read "/src/$f")
done
}
function _test_can_handle_ulimit() {
local mount_dir
local dmg_file
sparsebundlefs_ulimit=12
read -r mount_dir dmg_file < <(mount_sparsebundle $mount_options)
sparsebundlefs_ulimit=
hfs_dir=$(mktemp -d)
hfsfuse -f $dmg_file $hfs_dir &
local hfs_pid=$!
for i in {0..50}; do
kill -0 $hfs_pid >/dev/null 2>&1
test -f $hfs_dir/Makefile && break || sleep 0.1
done
for f in $(find $hfs_dir -type f); do
echo "Reading $f"
cat $f > /dev/null
done
umount $hfs_dir && rm -Rf $hfs_dir
umount $mount_dir && rm -Rf $mount_dir
}