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 03965429E4D for ; Mon, 27 Jun 2011 21:56:27 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] 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 LJUPwXYPpuTh for ; Mon, 27 Jun 2011 21:56:26 -0700 (PDT) Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 9D069429E4A for ; Mon, 27 Jun 2011 21:56:25 -0700 (PDT) Received: by bwg12 with SMTP id 12so4894899bwg.26 for ; Mon, 27 Jun 2011 21:56:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=0fYxnIsYosbhVrdaNl28aBtNW187TYjiveyeKCohL/k=; b=sWV61pwdd5hPn4rp9GBpsnQ1F5b1gxBQMJAlaGWS3nKfReYQvQstmmvdNCbRmfRK98 9c38gClUTCj8XeL1jWG/YPVhCP4ndvK0wp259xBpzwQwRzxGV2cPEg1M/iphqZuinLbB gUqM50jxP2WQO4gNsp21aCzHgIeJcOMKYr4O8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=VeeeU9SQlW6hmWwiPhPlTvVQN7/QQvaiWDcqpBCylZHvQMpS7Qlim0WHoshMsoupO1 78bCPLsg5ZF4cZGaCK+Wmir0K6kBK5UwrTJkP2G5VYquoTPDck8r1E8qOifBsa8T1sO7 FQ/g3bwJi2sjsbgCjigXo+VEsRgESsl5WpQws= Received: by 10.204.77.194 with SMTP id h2mr1105966bkk.144.1309236984108; Mon, 27 Jun 2011 21:56:24 -0700 (PDT) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id e6sm51830bka.23.2011.06.27.21.56.22 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 27 Jun 2011 21:56:23 -0700 (PDT) From: Dmitry Kurochkin To: notmuch@notmuchmail.org Subject: [PATCH] test: use emacsclient(1) for Emacs tests Date: Tue, 28 Jun 2011 08:56:17 +0400 Message-Id: <1309236977-7974-1-git-send-email-dmitry.kurochkin@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1309236311-2162-10-git-send-email-dmitry.kurochkin@gmail.com> References: <1309236311-2162-10-git-send-email-dmitry.kurochkin@gmail.com> 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, 28 Jun 2011 04:56:27 -0000 Before the change, every Emacs test ran in a separate Emacs instance. Starting Emacs many times wastes considerable time and it gets worse as the test suite grows. The patch solves this by using a single Emacs server and emacsclient(1) to run multiple tests. Emacs server is started on the first test_emacs call and stopped when test_done is called. We take care not to leave orphan Emacs processes behind when test is terminated by whatever reason: Emacs server runs a watchdog that periodically checks that the test is still running. Some tests need to provide user input. Before the change, this was done using echo(1) to Emacs stdin. This no longer works and instead `standard-input' variable is set accordingly to make `read' return the appropriate string. --- Amended patch with a more appropriate Emacs server name. Sorry, for inconvenience, should go to sleep. Regards, Dmitry test/emacs | 10 +++++----- test/test-lib.el | 13 +++++++++++++ test/test-lib.sh | 24 +++++++++++++----------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/test/emacs b/test/emacs index 3d42645..0f5f99c 100755 --- a/test/emacs +++ b/test/emacs @@ -259,15 +259,15 @@ test_expect_equal_file OUTPUT EXPECTED test_begin_subtest "Save attachment from within emacs using notmuch-show-save-attachments" # save as archive to test that Emacs does not re-compress .gz -echo ./attachment1.gz | -test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com") - (notmuch-show-save-attachments)' > /dev/null 2>&1 +test_emacs '(let ((standard-input "\"attachment1.gz\"")) + (notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com") + (notmuch-show-save-attachments))' > /dev/null 2>&1 test_expect_equal_file attachment1.gz "$EXPECTED/attachment" test_begin_subtest "Save attachment from within emacs using notmuch-show-save-part" # save as archive to test that Emacs does not re-compress .gz -echo ./attachment2.gz | -test_emacs '(notmuch-show-save-part "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com" 5)' > /dev/null 2>&1 +test_emacs '(let ((standard-input "\"attachment2.gz\"")) + (notmuch-show-save-part "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com" 5))' > /dev/null 2>&1 test_expect_equal_file attachment2.gz "$EXPECTED/attachment" test_begin_subtest "View raw message within emacs" diff --git a/test/test-lib.el b/test/test-lib.el index 4e7f5cf..a783936 100644 --- a/test/test-lib.el +++ b/test/test-lib.el @@ -23,6 +23,12 @@ ;; avoid crazy 10-column default of --batch (set-frame-width (window-frame (get-buffer-window)) 80) +;; `read-file-name' by default uses `completing-read' function to read +;; user input. It does not respect `standard-input' variable which we +;; use in tests to provide user input. So replace it with a plain +;; `read' call. +(setq read-file-name-function (lambda (&rest _) (read))) + (defun notmuch-test-wait () "Wait for process completion." (while (get-buffer-process (current-buffer)) @@ -51,3 +57,10 @@ FILENAME is OUTPUT." (setq str (concat str (buffer-substring start next-pos)))) (setq start next-pos))) str)) + +(defun orphan-watchdog (pid) + "Periodically check that the process with id PID is still +running, quit if it terminated." + (if (not (process-attributes pid)) + (kill-emacs) + (run-at-time "1 min" nil 'orphan-watchdog pid))) diff --git a/test/test-lib.sh b/test/test-lib.sh index 48bace2..bcf18ec 100755 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -829,6 +829,8 @@ test_done () { echo + [ -n "$EMACS_SERVER" ] && test_emacs '(kill-emacs)' + if [ "$test_failure" = "0" ]; then if [ "$test_broken" = "0" ]; then rm -rf "$remove_tmp" @@ -848,16 +850,8 @@ emacs_generate_script () { export PATH=$PATH export NOTMUCH_CONFIG=$NOTMUCH_CONFIG -# We assume that the user will give a command-line argument only if -# wanting to run in batch mode. -if [ \$# -gt 0 ]; then - BATCH=--batch -fi - # Here's what we are using here: # -# --batch: Quit after given commands and print all (messages) -# # --no-init-file Don't load users ~/.emacs # # --no-site-file Don't load the site-wide startup stuff @@ -866,16 +860,24 @@ fi # # --load Force loading of notmuch.el and test-lib.el -emacs \$BATCH --no-init-file --no-site-file \ +emacs --no-init-file --no-site-file \ --directory "$TMP_DIRECTORY/../../emacs" --load notmuch.el \ --directory "$TMP_DIRECTORY/.." --load test-lib.el \ - --eval "(progn \$@)" + "\$@" EOF chmod a+x "$TMP_DIRECTORY/run_emacs" } test_emacs () { - "$TMP_DIRECTORY/run_emacs" "$@" + if [ -z "$EMACS_SERVER" ]; then + EMACS_SERVER="notmuch-test-suite-$$" + "$TMP_DIRECTORY/run_emacs" \ + --daemon \ + --eval "(setq server-name \"$EMACS_SERVER\")" \ + --eval "(orphan-watchdog $$)" || return + fi + + emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)" } -- 1.7.5.4