[PATCH V3 2/2] test/test-lib.sh: take the --background feature in smtp-dummy into use
authorTomi Ollila <tomi.ollila@iki.fi>
Tue, 18 Sep 2012 14:23:02 +0000 (17:23 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:49:33 +0000 (09:49 -0800)
10/828c9ea1f101359b65a848c8ff398308a3789c [new file with mode: 0644]

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