From 534bc66a435af7899fa4131021648be8749585f8 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 3 Jan 2021 16:42:30 -0800 Subject: [PATCH] Add a test for background procs in cmdsubs This adds a test to ensure that if a long running background process is launched from a command substitution, that process does not cause the cmdsub to hang. That could easily happen if we just wait for the pipe to close; this is verifying that we are also checking for the job to complete. --- tests/checks/cmdsub-limit.fish | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/checks/cmdsub-limit.fish b/tests/checks/cmdsub-limit.fish index 7b0ee047c..bb286d94f 100644 --- a/tests/checks/cmdsub-limit.fish +++ b/tests/checks/cmdsub-limit.fish @@ -1,8 +1,25 @@ # RUN: %fish %s -# This tests various corner cases involving command substitution. Most -# importantly the limits on the amount of data we'll substitute. +# This tests various corner cases involving command substitution. +# Test cmdsubs which spawn background processes - see #7559. +# If this hangs, it means that fish keeps trying to read from the write +# end of the cmdsub pipe (which has escaped). + +# FIXME: we need to mark full job control for sleep to get its own pgid; +# otherwise $last_pid will return fish's pgid! It's always been so! +status job-control full + +echo (command sleep 1000000 & ; set -g sleep_pid $last_pid ; echo local) +# CHECK: local +echo $sleep_pid +# CHECK: {{[1-9]\d*}} +kill $sleep_pid ; echo $status +# CHECK: 0 + +status job-control interactive + +# Test limiting the amount of data we'll substitute. set fish_read_limit 512 function subme @@ -10,7 +27,7 @@ function subme echo $x end -# Command sub just under the limit should succeed +# Command sub just under the limit should succeed. set a (subme 511) set --show a #CHECK: $a: set in global scope, unexported, with 1 elements