Skip to content

Commit fab4ea6

Browse files
committed
Add test for hitting max open files
1 parent 80f5a0d commit fab4ea6

5 files changed

Lines changed: 77 additions & 29 deletions

File tree

tests/20_basic_read.tst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env testrunner.sh
2+
3+
source "$(dirname "$0")/testhelpers.sh"
4+
5+
mount_options="-o noreadbuf"
6+
7+
function setup() {
8+
read -r mount_dir dmg_file < <(mount_sparsebundle $mount_options)
9+
}
10+
11+
function test_dmg_has_correct_number_of_blocks() {
12+
_test_dmg_has_correct_number_of_blocks
13+
}
14+
15+
function test_dmg_contents_is_same_as_testdata() {
16+
_test_dmg_contents_is_same_as_testdata
17+
}
18+
19+
function test_can_handle_ulimit() {
20+
_test_can_handle_ulimit
21+
}
22+
23+
function teardown() {
24+
umount $mount_dir && rm -Rf $mount_dir
25+
}

tests/30_noreadbuf.tst

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ function setup() {
77
}
88

99
function test_dmg_has_correct_number_of_blocks() {
10-
hfsdump $dmg_file | grep "total_blocks: 268435456"
10+
_test_dmg_has_correct_number_of_blocks
1111
}
1212

1313
function test_dmg_contents_is_same_as_testdata() {
14-
for f in $(ls $HFSFUSE_DIR/src); do
15-
echo "Diffing $HFSFUSE_DIR/src/$f"
16-
diff $HFSFUSE_DIR/src/$f <(hfsdump $dmg_file read "/src/$f")
17-
done
14+
_test_dmg_contents_is_same_as_testdata
15+
}
16+
17+
function test_can_handle_ulimit() {
18+
_test_can_handle_ulimit
1819
}
1920

2021
function teardown() {
2122
umount $mount_dir && rm -Rf $mount_dir
22-
}
23+
}

tests/testhelpers.sh

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11

2+
sparsebundlefs_ulimit=
3+
24
function mount_sparsebundle() {
35
test ! -z "$TEST_BUNDLE"
46
local mount_dir=$(mktemp -d)
57
local dmg_file="$mount_dir/sparsebundle.dmg"
6-
sparsebundlefs -s -f -D $* $TEST_BUNDLE $mount_dir &
8+
(
9+
if [[ ! -z "${sparsebundlefs_ulimit}" ]]; then
10+
ulimit -n $sparsebundlefs_ulimit
11+
fi
12+
sparsebundlefs -s -f -D $* $TEST_BUNDLE $mount_dir
13+
) &
714
local pid=$!
815
for i in {0..50}; do
916
kill -0 $pid >/dev/null 2>&1
@@ -12,3 +19,40 @@ function mount_sparsebundle() {
1219

1320
echo $mount_dir "$mount_dir/sparsebundle.dmg"
1421
}
22+
23+
function _test_dmg_has_correct_number_of_blocks() {
24+
hfsdump $dmg_file | grep "total_blocks: 268435456"
25+
}
26+
27+
function _test_dmg_contents_is_same_as_testdata() {
28+
for f in $(ls $HFSFUSE_DIR/src); do
29+
echo "Diffing $HFSFUSE_DIR/src/$f"
30+
diff $HFSFUSE_DIR/src/$f <(hfsdump $dmg_file read "/src/$f")
31+
done
32+
}
33+
34+
function _test_can_handle_ulimit() {
35+
local mount_dir
36+
local dmg_file
37+
38+
39+
sparsebundlefs_ulimit=12
40+
read -r mount_dir dmg_file < <(mount_sparsebundle $mount_options)
41+
sparsebundlefs_ulimit=
42+
43+
hfs_dir=$(mktemp -d)
44+
hfsfuse -f $dmg_file $hfs_dir &
45+
local hfs_pid=$!
46+
for i in {0..50}; do
47+
kill -0 $hfs_pid >/dev/null 2>&1
48+
test -f $hfs_dir/Makefile && break || sleep 0.1
49+
done
50+
51+
for f in $(find $hfs_dir -type f); do
52+
echo "Reading $f"
53+
cat $f > /dev/null
54+
done
55+
56+
umount $hfs_dir && rm -Rf $hfs_dir
57+
umount $mount_dir && rm -Rf $mount_dir
58+
}

0 commit comments

Comments
 (0)