diff --git a/tests/inetd.sh b/tests/inetd.sh index 0301b68..894ce98 100644 --- a/tests/inetd.sh +++ b/tests/inetd.sh @@ -77,6 +77,15 @@ cat > "$conf" < + #:provides '(test-inetd-fail) + #:start (make-inetd-constructor '("$(type -P false)") + (list + (endpoint (make-socket-address + AF_INET + INADDR_LOOPBACK + $PORT)))) #:stop (make-inetd-destructor))) (start 'test-inetd) @@ -95,6 +104,11 @@ file_descriptor_count () ls -l /proc/$shepherd_pid/fd/[0-9]* | wc -l } +# Trigger startup of the finalizer thread, which creates a couple of pipes. +# That way, those extra file descriptors won't influence the comparison with +# INITIAL_FD_COUNT done at the end. +$herd eval root '(gc)' + initial_fd_count=$(file_descriptor_count) $herd status test-inetd | grep started @@ -203,3 +217,16 @@ $herd status # At this point, shepherd should have INITIAL_FD_COUNT - 1 file descriptors # opened. test $(file_descriptor_count) -lt $initial_fd_count + +# Now test a service that fails as soon as it's passed an incoming connection. +$herd start test-inetd-fail +for i in $(seq 1 10) +do + $herd status + test $($herd status | grep '\+' | wc -l) -eq 2 + ! converse_with_echo_server \ + "(make-socket-address AF_INET INADDR_LOOPBACK $PORT)" +done + +$herd stop test-inetd-unix +test $(file_descriptor_count) -lt $initial_fd_count