From patchwork Wed Mar 13 12:24:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 10851057 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93EFA139A for ; Wed, 13 Mar 2019 12:24:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 821C8286AC for ; Wed, 13 Mar 2019 12:24:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8053229B28; Wed, 13 Mar 2019 12:24:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94DA529AB0 for ; Wed, 13 Mar 2019 12:24:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726264AbfCMMYn (ORCPT ); Wed, 13 Mar 2019 08:24:43 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39730 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725868AbfCMMYn (ORCPT ); Wed, 13 Mar 2019 08:24:43 -0400 Received: by mail-wr1-f66.google.com with SMTP id p8so1767701wrq.6 for ; Wed, 13 Mar 2019 05:24:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uUjWSk4Jd1J4luLr16M//tgKX9cw+tUuZTIZ90t/hlQ=; b=JIf8lbxUB0cIdr5RcOE9ICa+Dv2ntFkK/w1UNM+ej8pBk4v4M7GuIhOTOI0f0c3T9a TkrMKjejyBGzy6vxcc4b/3JWQhrjB2r2mdoqmQNyAWGNxrHXHCARfDUKla7h55ymuZN0 6/qNjvtu1pV29VWgHY3jcP6ajeFa3StNiHP+TN8hkW+oqgmsJU0mnHavUqXQ513FYgPK yQ5n4ilX/hWR9HpckD9ZFQKLzA5K1jbkDenR4WVWB6CdlWwXj0jJpgA1ITADlpi/aXjp 8s58DBj68Cn7cupIefGgL0RG782rahUxU33qtwckbCfUYDl64CX4wZxI4D5JPkTBjeqS yb/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uUjWSk4Jd1J4luLr16M//tgKX9cw+tUuZTIZ90t/hlQ=; b=Lujm6gg5iSFcgxq0KQRLO9Kxx3zXE0A0DlBH62W+cIcrrpyhS/c9ssVdarjg9wjQ1j X6F8IOkLTaWI17THtZJRm4neR0UgLDYmPea62WbGT2ANB+oQy3NP4l1QuXj1mO1Lf+nR jLxAF4+5z/qPnZFTHlS2hWHmjAPUbFX5jqDx36BP4rI2LKHcsW+mw3Hj2V7CrgaNER83 wC6a3tPemAy6WQLTz6KnaRd7r63nXfyVuEQdbW/8RebsxAvJsuJh7ukY8fKRLnoWJlIc AP3HHixt3mkMMQzRkPqBNmhLsj4MUAYqabKo7r09nePdjO0/SmzO4xbvftSIEcZnHN5w x3rA== X-Gm-Message-State: APjAAAUWeVgnXNeVBPcseLn0oCJKLCv790cC8squagDLyOCVs76jciAp YrdiaCMYwryDoAXtksGPPvK/tZhA X-Google-Smtp-Source: APXvYqzlH1e6/g6WspXsV/mWAf3EQEtDaTuEMiEsPLDt5URxXTMY7Pk98QtLWPQ5plof/vx0i3gIwg== X-Received: by 2002:a5d:4d4e:: with SMTP id a14mr17492475wru.324.1552479880412; Wed, 13 Mar 2019 05:24:40 -0700 (PDT) Received: from localhost.localdomain (x4d0c2b66.dyn.telefonica.de. [77.12.43.102]) by smtp.gmail.com with ESMTPSA id t2sm8348287wra.9.2019.03.13.05.24.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Mar 2019 05:24:39 -0700 (PDT) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: git@vger.kernel.org Cc: Johannes Schindelin , Jeff King , Junio C Hamano , Luke Diamand , Lars Schneider , =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH 01/11] test-lib: fix interrupt handling with 'dash' and '--verbose-log -x' Date: Wed, 13 Mar 2019 13:24:09 +0100 Message-Id: <20190313122419.2210-2-szeder.dev@gmail.com> X-Mailer: git-send-email 2.21.0.499.g4d310c7a8e.dirty In-Reply-To: <20190313122419.2210-1-szeder.dev@gmail.com> References: <20190313122419.2210-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When a test script run with 'dash' and '--verbose-log -x' is interrupted by ctrl-C, SIGTERM, or closing the terminal window, then most of the time the registered EXIT trap actions are not executed. This is an annoying issue with tests involving daemons, because they should run cleanup commands to kill those daemon processes in the trap on EXIT, but since these cleanup commands are not executed, the daemons are left alive and keep their port open, thus interfering with subsequent execution of the same test script. The cause of this issue is the subtle combination of several factors (bear with me, or skip over the indented part): - Even when the test script is interrupted, the cleanup commands are not run in the trap on INT, TERM, or HUP, but in the trap on EXIT after the trap on the signals invokes 'exit' [1]. - According to POSIX [2]: "The environment in which the shell executes a trap on EXIT shall be identical to the environment immediately after the last command executed before the trap on EXIT was taken." Pertinent to the issue at hand is that all open file descriptors and the state of '-x' tracing should be preserved. All shells I've tried [3] preserve '-x'. Unfortunately, however: - 'dash' doesn't conform to this when it comes to open file descriptors: even when standard output and/or error are redirected somewhere when 'exit' is invoked, anything written to them in the trap on EXIT goes to the script's original stdout and stderr [4]. We can't dismiss this with a simple "it doesn't conform to POSIX, so we don't care", because 'dash' is the default /bin/sh in some of the more popular Linux distros. - As far as I can tell, POSIX doesn't explicitly say anything about the environment of trap actions for various signals. In practice it seems that most shells behave sensibly and preserve both open file descriptors and the state of '-x' tracing for the traps on INT, TERM, and HUP, including even 'dash'. The exceptions are 'mksh' and 'lksh': they do preserve '-x', but not the open file descriptors. - When a test script run with '-x' tracing enabled is interrupted, then it's very likely that the signal arrives mid-test, i.e.: - while '-x' tracing is enabled, and, consequently, our trap actions on INT, TERM, HUP, and EXIT will produce trace output as well. - while standard output and error are redirected to a log file, to the test script's original standard output and error, or to /dev/null, depending on whether the test script was run with '--verbose-log', '-v', or neither. According to the above, we can't rely on these redirections still be in effect when running the traps on INT, TERM, HUP, and/or EXIT. - When a test script is run with '--verbose-log', then the test script is re-executed with its standard output and error piped into 'tee', in order to send the "regular" non-verbose test's output both to the terminal and to the log file. When the test is interrupted, then the signal interrupts the downstream 'tee' as well. Putting these together, when a test script run with 'dash' and '--verbose-log -x' is interrupted, then 'dash' tries to write the trace output from the EXIT trap to the script's original standard error, but it very likely can't, because the 'tee' downstream of the pipe is interrupted as well. This causes the shell running the test script to die because of SIGPIPE, without running any of the commands in the EXIT trap. Disable '-x' tracing in the trap on INT, TERM, and HUP to avoid this issue, as it disables tracing in the chained trap on EXIT as well. Wrap it in a '{ ... } 2>/dev/null' block, so the trace of the command disabling the tracing doesn't go to standard error either [5]. Note that it's not only '-x' tracing that can be problematic, but any shell builtin, e.g. 'echo', that writes to standard output or error in the trap on EXIT, while a test running with 'dash' and '--verbose-log' (even without '-x') is interrupted. As far as I can tell, this is not an issue at the moment: - The cleanup commands to stop the credential-helper, Apache, or 'p4d' don't use any such shell builtins. - stop_git_daemon() does use 'say' and 'error', both wrappers around 'echo', but it redirects 'say' to fd 3, i.e. to the log file, and while 'error' does write to standard output, it comes only after the daemon was killed. - The non-builtin commands that actually stop the daemons ('kill', 'apache2 -k stop', 'git credential-cache exit') are silent, so they won't get SIGPIPE before finishing their job. [1] The trap on EXIT must run cleanup commands, because we want to stop any daemons when a test script run with '--immediate' fails and exits early with error. By chaining up the trap on signals to the trap on EXIT we can deal with cleanup commands a bit simpler, because the tests involving daemons only have to set a single trap. [2] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#trap [3] The shells I tried: dash, Bash, ksh, ksh93, mksh, lksh, yash, BusyBox sh, FreeBSD /bin/sh, NetBSD /bin/sh. [4] $ cat trap-output.sh #!/bin/sh trap "echo output; echo error >&2" EXIT { exit; } >OUT 2>ERR $ dash ./trap-output.sh output error $ wc -c OUT ERR 0 OUT 0 ERR On a related note, 'ksh', 'ksh93', and BusyBox sh don't conform to the specs in this respect, either. [5] This '{ set +x; } 2>/dev/null' trick won't help those shells that show trace output for any redirections and don't preserve open file descriptors for the trap on INT, TERM and HUP. The only such shells I'm aware of are 'mksh' and 'lksh'. Signed-off-by: SZEDER Gábor --- t/test-lib.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index 8665b0a9b6..db3875d1e4 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -631,7 +631,10 @@ die () { GIT_EXIT_OK= trap 'die' EXIT -trap 'exit $?' INT TERM HUP +# Disable '-x' tracing, because with some shells, notably dash, it +# prevents running the cleanup commands when a test script run with +# '--verbose-log -x' is interrupted. +trap '{ code=$?; set +x; } 2>/dev/null; exit $code' INT TERM HUP # The user-facing functions are loaded from a separate file so that # test_perf subshells can have them too From patchwork Wed Mar 13 12:24:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 10851059 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AE6F7139A for ; Wed, 13 Mar 2019 12:24:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BCD9286C5 for ; Wed, 13 Mar 2019 12:24:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A36C29AC6; Wed, 13 Mar 2019 12:24:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22F91298FF for ; Wed, 13 Mar 2019 12:24:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726339AbfCMMYp (ORCPT ); Wed, 13 Mar 2019 08:24:45 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:52293 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725836AbfCMMYn (ORCPT ); Wed, 13 Mar 2019 08:24:43 -0400 Received: by mail-wm1-f68.google.com with SMTP id f65so1788923wma.2 for ; Wed, 13 Mar 2019 05:24:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dwBy+CvhEtS19+ruMBS+Xz9lSt8nyOil1SKC09gJAZM=; b=seYCFhsnViJOVBU5pxI2+TglyW4/f86IvXCu2UucwIFfecuR1cVBd15vDNWIBv3WyA 5npgnd4LFwwGAbXVYz+fCzF1PSSqgCGs/MXa/pAG0QleRLUclrVbNCSIyNaPB0x2jke6 5+AnIin8E5mO50FxavPhkKuwr4eYvfTJlZfOgTnOPutu88t9uCfogvdx5dXYKzwiJQE/ /noAJ/fDR2NjhZBwF6TTpgRqlT2q03Emo6UcgqtAwn1AadqFuxq8L1ufBc0+emq98mqj XLBCP5MBPTcVdka18gjMC7/Bi6RwUQqhjDd6Oyd2QozCwi5l6UObEpjm5+pWOHkpINtr GUZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dwBy+CvhEtS19+ruMBS+Xz9lSt8nyOil1SKC09gJAZM=; b=qYySpMdYe3cCtTWSEIVFfVRL41R5DBr9Lw+XD00cQ7JimV/MZkW1JGrRfv5rXncYWl 92Yag13KDWJg2SwvMH2DtQWgEfhUnRCoGdyEZYhgf53wWnvvB3VIiqLWWjzbxhtKRDSZ s2roy/0hYS2Mz7EO5WGDr8uhvjEo7QE16xIyrKCwCUB2nfyCkyektvOPGDRB2nn704JZ So8MZxyaUBy2uz9UzKdmz1jAtuD0+0eE1bhxUN6xYMCllLRKqWV2+erotfwhvR38COi6 FwYmfwZ/CmnCplVMiS/p3WRnKKAkhSBnDD0nrA/fmSvXorXDZUEq2+BSKMFl1/dDOxvj VLRA== X-Gm-Message-State: APjAAAUGTHVLiRvjHrUCXOPopXpPrm/wB0WyMiNu+IJNPKG0bUuW619S RY7GiMLCERd7yCqCxm8+KuyLtfqN X-Google-Smtp-Source: APXvYqz+QCdo4NIqU78e0bbmwo5h5Ea1BQJnDnRRHpwNCbPVP9i0FKyIkqwfxhaQ0iIgu62Wm7XqBg== X-Received: by 2002:a1c:cc1a:: with SMTP id h26mr2065053wmb.34.1552479881867; Wed, 13 Mar 2019 05:24:41 -0700 (PDT) Received: from localhost.localdomain (x4d0c2b66.dyn.telefonica.de. [77.12.43.102]) by smtp.gmail.com with ESMTPSA id t2sm8348287wra.9.2019.03.13.05.24.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Mar 2019 05:24:41 -0700 (PDT) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: git@vger.kernel.org Cc: Johannes Schindelin , Jeff King , Junio C Hamano , Luke Diamand , Lars Schneider , =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH 02/11] t/lib-git-daemon: make sure to kill the 'git-daemon' process Date: Wed, 13 Mar 2019 13:24:10 +0100 Message-Id: <20190313122419.2210-3-szeder.dev@gmail.com> X-Mailer: git-send-email 2.21.0.499.g4d310c7a8e.dirty In-Reply-To: <20190313122419.2210-1-szeder.dev@gmail.com> References: <20190313122419.2210-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After 'start_git_daemon' starts 'git daemon' (note the space in the middle) in the background, it saves the background process' PID, so the daemon can be stopped at the end of the test script. However, 'git-daemon' is not a builtin but a dashed external command, which means that the dashless 'git daemon' executes the dashed 'git-daemon' command, and, consequently, the PID recorded is not the PID of the "real" daemon process, but that of the main 'git' wrapper. Now, if a test script involving 'git daemon' is interrupted by ctrl-C, then only the main 'git' process is stopped, but the real daemon process tends to survive somehow, and keeps on running in the background indefinitely, keeping the daemon's port to itself, and thus preventing subsequent runs of the same test script. Work this around by running 'git daemon' with the '--pidfile=...' option to save the PID of the real daemon process, and kill that process in 'stop_git_daemon' as well. Signed-off-by: SZEDER Gábor --- t/lib-git-daemon.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/lib-git-daemon.sh b/t/lib-git-daemon.sh index 79db3b7ae5..6dab8766e7 100644 --- a/t/lib-git-daemon.sh +++ b/t/lib-git-daemon.sh @@ -31,6 +31,7 @@ fi test_set_port LIB_GIT_DAEMON_PORT GIT_DAEMON_PID= +GIT_DAEMON_PIDFILE="$PWD"/daemon.pid GIT_DAEMON_DOCUMENT_ROOT_PATH="$PWD"/repo GIT_DAEMON_HOST_PORT=127.0.0.1:$LIB_GIT_DAEMON_PORT GIT_DAEMON_URL=git://$GIT_DAEMON_HOST_PORT @@ -49,7 +50,7 @@ start_git_daemon() { mkfifo git_daemon_output ${LIB_GIT_DAEMON_COMMAND:-git daemon} \ --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \ - --reuseaddr --verbose \ + --reuseaddr --verbose --pid-file="$GIT_DAEMON_PIDFILE" \ --base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \ "$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \ >&3 2>git_daemon_output & @@ -88,8 +89,9 @@ stop_git_daemon() { then error "git daemon exited with status: $ret" fi + kill "$(cat "$GIT_DAEMON_PIDFILE")" 2>/dev/null GIT_DAEMON_PID= - rm -f git_daemon_output + rm -f git_daemon_output "$GIT_DAEMON_PIDFILE" } # A stripped-down version of a netcat client, that connects to a "host:port" From patchwork Wed Mar 13 12:24:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 10851063 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B63761669 for ; Wed, 13 Mar 2019 12:24:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D0F22963A for ; Wed, 13 Mar 2019 12:24:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B23B29ADA; Wed, 13 Mar 2019 12:24:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E54B62963A for ; Wed, 13 Mar 2019 12:24:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726396AbfCMMYr (ORCPT ); Wed, 13 Mar 2019 08:24:47 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:35027 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725868AbfCMMYq (ORCPT ); Wed, 13 Mar 2019 08:24:46 -0400 Received: by mail-wr1-f65.google.com with SMTP id t18so1779922wrx.2 for ; Wed, 13 Mar 2019 05:24:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mN1kCxbgqQogjd9IfmawffGmAZe7+Vpw47mgnA8JA/8=; b=SMFtmo2hn5XWp4K6E4y0nayBXT6+qzMKhzq5eeQEWArdPBfIUH8RegolN/g1B97I27 EKpC1vjuJv6unGyGGP6GQ9F15OS97zx4DMlfVHCX1SMMAPcVmuluV0dX9x0AGS01YC7d DNABhpIG4lAZdQ37OH/1cPS8V2+ooCnSiKTx1bRwEpQn6EgYdUMcbp4K5MKa7lqIFBEh Xo0o1gjct+fQfmFjLcm4NbWoxI/cHewf5EPkg4SdeKCqcudzGem4mhXNdymTwfuEwm4T 26l2o+EbxRRzH18RCK6oCpYAmo+RhnbEy6x0ssPJPFQoEwkbxHFnt33qgWvWJR2KYDUz a7Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mN1kCxbgqQogjd9IfmawffGmAZe7+Vpw47mgnA8JA/8=; b=sK0duM2W7nuj2QtcbtAPIjIiJRxrio7GxYb5m+0p9rDAmNKpgvV8I2J9zdE8RAM6Sn WPslwNoUiDZuV8YjRqo/NT5j1gPb0kqxoWgBorggu5A2265m3C7+G05/rnZBx/o9tOmk p5nCCM7edqXk72G8gRS4bQv9SiyvOMwrHjFA1KOeCh0r+hJsQeE27tbYZMuOWV7VdqMj VO0j0xAJylwnAkELbdl5Y2syL3J9UnV674cTfWchZJAJnvvaydAjqG+eda/XU+D/7iLN ZfxyJYuvBVQiTM1HkHzpRB6B53TllOV4Cg2VdHKnuwbAnSui5SD0VjaC1kUu4z7H280E jPAA== X-Gm-Message-State: APjAAAX1yvLkVZoo/rokcISRLjes8LGLdV2XN7bkzqBgYXabPsI07dG9 1+G/tNoMYNurxUQRMlC9ikh/E/zo X-Google-Smtp-Source: APXvYqwXnEAAlvpI66JRL5kWVmWGcB+iubJhq+Q4RXF89ml5WIIzNqgMD7JeWFdqE1ILWo732XwWnA== X-Received: by 2002:a5d:6948:: with SMTP id r8mr4660943wrw.255.1552479883109; Wed, 13 Mar 2019 05:24:43 -0700 (PDT) Received: from localhost.localdomain (x4d0c2b66.dyn.telefonica.de. [77.12.43.102]) by smtp.gmail.com with ESMTPSA id t2sm8348287wra.9.2019.03.13.05.24.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Mar 2019 05:24:42 -0700 (PDT) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: git@vger.kernel.org Cc: Johannes Schindelin , Jeff King , Junio C Hamano , Luke Diamand , Lars Schneider , Johannes Schindelin , =?utf-8?q?SZEDER_G=C3=A1b?= =?utf-8?q?or?= Subject: [PATCH 03/11] test-lib: introduce 'test_atexit' Date: Wed, 13 Mar 2019 13:24:11 +0100 Message-Id: <20190313122419.2210-4-szeder.dev@gmail.com> X-Mailer: git-send-email 2.21.0.499.g4d310c7a8e.dirty In-Reply-To: <20190313122419.2210-1-szeder.dev@gmail.com> References: <20190313122419.2210-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Johannes Schindelin When running Apache, 'git daemon', or p4d, we want to kill them at the end of the test script, otherwise a leftover daemon process will keep its port open indefinitely, and thus will interfere with subsequent executions of the same test script. So far, we stop these daemon processes "manually", i.e.: - by registering functions or commands in the trap on EXIT to stop the daemon while preserving the last seen exit code before the trap (to deal with a failure when run with '--immediate' or with interrupts by ctrl-C), - and by invoking these functions/commands last thing before 'test_done' (and sometimes restoring the test framework's default trap on EXIT, to prevent the daemons from being killed twice). On one hand, we do this inconsistently, e.g. 'git p4' tests invoke different functions in the trap on EXIT and in the last test before 'test_done', and they neither restore the test framework's default trap on EXIT nor preserve the last seen exit code. On the other hand, this is error prone, because, as shown in a previous patch in this series, any output from the cleanup commands in the trap on EXIT can prevent a proper cleanup when a test script run with '--verbose-log' and certain shells, notably 'dash', is interrupted. Let's introduce 'test_atexit', which is loosely modeled after 'test_when_finished', but has a broader scope: rather than running the commands after the current test case, run them when the test script finishes, and also run them when the test is interrupted, or exits early in case of a failure while the '--immediate' option is in effect. When running the cleanup commands at the end of a successful test, then they will be run in 'test_done' before it removes the trash directory, i.e. the cleanup commands will still be able to access any pidfiles or socket files in there. When running the cleanup commands after an interrupt or failure with '--immediate', then they will be run in the trap on EXIT. In both cases they will be run in 'test_eval_', i.e. both standard error and output of all cleanup commands will go where they should according to the '-v' or '--verbose-log' options, and thus won't cause any troubles when interrupting a test script run with '--verbose-log'. Signed-off-by: Johannes Schindelin Signed-off-by: SZEDER Gábor --- t/README | 20 ++++++++++++++++++++ t/t0000-basic.sh | 18 ++++++++++++++++++ t/test-lib-functions.sh | 28 ++++++++++++++++++++++++++++ t/test-lib.sh | 23 +++++++++++++++++++++++ 4 files changed, 89 insertions(+) diff --git a/t/README b/t/README index 886bbec5bc..af510d236a 100644 --- a/t/README +++ b/t/README @@ -862,6 +862,26 @@ library for your script to use. ... ' + - test_atexit