Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id EEFEB6DE091B for ; Sun, 26 Jun 2016 08:30:13 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.005 X-Spam-Level: X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5 tests=[AWL=-0.006, HEADER_FROM_DIFFERENT_DOMAINS=0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id x2C_iX1EMw96 for ; Sun, 26 Jun 2016 08:30:06 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 496476DE0350 for ; Sun, 26 Jun 2016 08:30:02 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84) (envelope-from ) id 1bHC0G-000234-8e; Sun, 26 Jun 2016 11:29:44 -0400 Received: (nullmailer pid 26561 invoked by uid 1000); Sun, 26 Jun 2016 15:29:48 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 2/3] test: initial tests for locking retry Date: Sun, 26 Jun 2016 17:29:44 +0200 Message-Id: <1466954985-25761-3-git-send-email-david@tethera.net> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1466954985-25761-1-git-send-email-david@tethera.net> References: <1466954985-25761-1-git-send-email-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.20 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: Sun, 26 Jun 2016 15:30:14 -0000 Currently there's not much to test, so we simulate contention, and check that the modifications to the database are serialized. --- test/T620-lock.sh | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 test/T620-lock.sh diff --git a/test/T620-lock.sh b/test/T620-lock.sh new file mode 100755 index 0000000..f46475e --- /dev/null +++ b/test/T620-lock.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +test_description="locking" +. ./test-lib.sh || exit 1 + +if [ "${NOTMUCH_HAVE_XAPIAN_DB_RETRY_LOCK}" = "0" ]; then + test_subtest_missing_external_prereq_["lock retry support"]=t +fi + +add_email_corpus + +test_begin_subtest "blocking open" +test_C ${MAIL_DIR} <<'EOF' +#include +#include +#include +#include + +void +taggit (notmuch_database_t *db, const char *tag) +{ + notmuch_message_t *message; + + EXPECT0 (notmuch_database_find_message (db, "4EFC743A.3060609@april.org", &message)); + if (message == NULL) { + fprintf (stderr, "unable to find message"); + exit (1); + } + + EXPECT0 (notmuch_message_add_tag (message, tag)); + notmuch_message_destroy (message); +} + +int +main (int argc, char **argv) +{ + pid_t child; + const char *path = argv[1]; + + child = fork (); + if (child == -1) { + fprintf (stderr, "fork failed\n"); + exit (1); + } + + if (child == 0) { + notmuch_database_t *db2; + + sleep (1); + EXPECT0 (notmuch_database_open (path, NOTMUCH_DATABASE_MODE_READ_WRITE, &db2)); + taggit (db2, "child"); + EXPECT0 (notmuch_database_close (db2)); + } else { + notmuch_database_t *db; + + EXPECT0 (notmuch_database_open (path, NOTMUCH_DATABASE_MODE_READ_WRITE, &db)); + taggit (db, "parent"); + sleep (2); + EXPECT0 (notmuch_database_close (db)); + wait (NULL); + } +} + +EOF +notmuch search --output=tags id:4EFC743A.3060609@april.org >> OUTPUT +cat <<'EOF' >EXPECTED +== stdout == +== stderr == +child +inbox +parent +unread +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_done -- 2.8.1