@cryptotaxi247 / kubo / commits / 6c340563d

fdlimit: improve fdlimit autoraising tests

License: MIT Signed-off-by: Jeromy <why@ipfs.io>

Jeromy committed Aug 29, 2016 at 22:42 UTC 6c340563d41bd6e5ede03db7e1b48892a8753087
2 files changed +26 -3
cmd/ipfs/ulimit_unix.go
+8 -1
@@ -30,12 +30,15 @@ func checkAndSetUlimit() error {
30 return fmt.Errorf("error getting rlimit: %s", err)
31 }
32
33 + var setting bool
34 if rLimit.Cur < ipfsFileDescNum {
35 if rLimit.Max < ipfsFileDescNum {
36 + log.Error("adjusting max")
37 rLimit.Max = ipfsFileDescNum
38 }
37 - fmt.Printf("Adjusting current ulimit to %d.\n", ipfsFileDescNum)
39 + fmt.Printf("Adjusting current ulimit to %d...\n", ipfsFileDescNum)
40 rLimit.Cur = ipfsFileDescNum
41 + setting = true
42 }
43
44 err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
@@ -43,5 +46,9 @@ func checkAndSetUlimit() error {
46 return fmt.Errorf("error setting ulimit: %s", err)
47 }
48
49 + if setting {
50 + fmt.Printf("Successfully raised file descriptor limit to %d.\n", ipfsFileDescNum)
51 + }
52 +
53 return nil
54 }
test/sharness/t0060-daemon.sh
+18 -2
@@ -121,14 +121,30 @@ test_expect_success "daemon with pipe eventually becomes live" '
121 test_fsh cat stdin_daemon_out || test_fsh cat stdin_daemon_err || test_fsh cat stdin_poll_apiout || test_fsh cat stdin_poll_apierr
122 '
123
124 -ulimit -n 512
124 +ulimit -S -n 512
125 TEST_ULIMIT_PRESET=1
126 test_launch_ipfs_daemon
127
128 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
130 '
131
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 +
148 test_kill_ipfs_daemon
149
150 test_done