Skip to content

Commit 3de3ab2

Browse files
committed
fdlimit: improve fdlimit autoraising tests
License: MIT Signed-off-by: Jeromy <[email protected]>
1 parent 050985c commit 3de3ab2

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

cmd/ipfs/ulimit_unix.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,25 @@ func checkAndSetUlimit() error {
3030
return fmt.Errorf("error getting rlimit: %s", err)
3131
}
3232

33+
var setting bool
3334
if rLimit.Cur < ipfsFileDescNum {
3435
if rLimit.Max < ipfsFileDescNum {
36+
log.Error("adjusting max")
3537
rLimit.Max = ipfsFileDescNum
3638
}
37-
fmt.Printf("Adjusting current ulimit to %d.\n", ipfsFileDescNum)
39+
fmt.Printf("Adjusting current ulimit to %d...\n", ipfsFileDescNum)
3840
rLimit.Cur = ipfsFileDescNum
41+
setting = true
3942
}
4043

4144
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
4245
if err != nil {
4346
return fmt.Errorf("error setting ulimit: %s", err)
4447
}
4548

49+
if setting {
50+
fmt.Printf("Successfully raised file descriptor limit to %d.\n", ipfsFileDescNum)
51+
}
52+
4653
return nil
4754
}

test/sharness/t0060-daemon.sh

+18-2
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,30 @@ test_expect_success "daemon with pipe eventually becomes live" '
121121
test_fsh cat stdin_daemon_out || test_fsh cat stdin_daemon_err || test_fsh cat stdin_poll_apiout || test_fsh cat stdin_poll_apierr
122122
'
123123

124-
ulimit -n 512
124+
ulimit -S -n 512
125125
TEST_ULIMIT_PRESET=1
126126
test_launch_ipfs_daemon
127127

128128
test_expect_success "daemon raised its fd limit" '
129-
grep "ulimit" actual_daemon > /dev/null
129+
grep "raised file descriptor limit to 1024." actual_daemon > /dev/null
130130
'
131131

132+
get_col_four() {
133+
awk '{ print $4 }' $1
134+
}
135+
136+
if [ `uname` == "Linux" ]; then
137+
test_expect_success "get fd limit through /proc" '
138+
cat /proc/$IPFS_PID/limits > limits &&
139+
grep "Max open files" limits > fd_limits_line &&
140+
limit=$(get_col_four fd_limits_line)
141+
'
142+
143+
test_expect_success "limit from system looks good" '
144+
test "$limit" -eq 1024
145+
'
146+
fi
147+
132148
test_kill_ipfs_daemon
133149

134150
test_done

0 commit comments

Comments
 (0)