Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 480AC431FB6 for ; Tue, 18 Sep 2012 07:23:13 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WmdgJk1idKOn for ; Tue, 18 Sep 2012 07:23:12 -0700 (PDT) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by olra.theworths.org (Postfix) with ESMTP id 3143E431FAF for ; Tue, 18 Sep 2012 07:23:12 -0700 (PDT) Received: by guru.guru-group.fi (Postfix, from userid 501) id 39C18100387; Tue, 18 Sep 2012 17:23:18 +0300 (EEST) From: Tomi Ollila To: notmuch@notmuchmail.org Subject: [PATCH V3 2/2] test/test-lib.sh: take the --background feature in smtp-dummy into use Date: Tue, 18 Sep 2012 17:23:02 +0300 Message-Id: <1347978182-8771-2-git-send-email-tomi.ollila@iki.fi> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1347978182-8771-1-git-send-email-tomi.ollila@iki.fi> References: <1347978182-8771-1-git-send-email-tomi.ollila@iki.fi> Cc: Tomi Ollila X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Sep 2012 14:23:13 -0000 From: Tomi Ollila The use of --background option (instead of shell '&') ensures that smtp-dummy is listening its server socket until execution of shell script can continue, thus the client will always have socket where to connect. smtp-dummy outputs smtp_dummy_pid variable in shell assignment format; eval'ing that output makes that variable available for the shell. As the smtp-dummy instance is no longer child process of the script the SIGKILL signal sent to it will ensure it is going away in case the mail sender fails to connect to smtp-dummy. --- test/test-lib.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/test-lib.sh b/test/test-lib.sh index f34b1fb..c902b2c 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -403,8 +403,11 @@ emacs_deliver_message () shift 2 # before we can send a message, we have to prepare the FCC maildir mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp} - $TEST_DIRECTORY/smtp-dummy sent_message & - smtp_dummy_pid=$! + # eval'ing smtp-dummy --background will set smtp_dummy_pid + smtp_dummy_pid= + eval `$TEST_DIRECTORY/smtp-dummy --background sent_message` + test -n "$smtp_dummy_pid" || return 1 + test_emacs \ "(let ((message-send-mail-function 'message-smtpmail-send-it) (smtpmail-smtp-server \"localhost\") @@ -419,9 +422,11 @@ emacs_deliver_message () (insert \"${body}\") $@ (message-send-and-exit))" - # opportunistically quit smtp-dummy in case above fails. - { echo QUIT > /dev/tcp/localhost/25025; } 2>/dev/null - wait ${smtp_dummy_pid} + + # In case message was sent properly, client waits for confirmation + # before exiting and resuming control here; therefore making sure + # that server exits by sending (KILL) signal to it is safe. + kill -9 $smtp_dummy_pid notmuch new >/dev/null } -- 1.7.11.4