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 0F4CF431FD0 for ; Sat, 11 Jun 2011 13:05:42 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[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 lPMwPssIEF4z for ; Sat, 11 Jun 2011 13:05:40 -0700 (PDT) Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU [18.7.68.37]) by olra.theworths.org (Postfix) with ESMTP id BD76F429E25 for ; Sat, 11 Jun 2011 13:05:40 -0700 (PDT) X-AuditID: 12074425-b7b82ae000000a2a-d7-4df3ca7c903d Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP id AB.65.02602.C7AC3FD4; Sat, 11 Jun 2011 16:05:16 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id p5BK5eRg014991; Sat, 11 Jun 2011 16:05:40 -0400 Received: from drake.mit.edu (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p5BK5cMl005859 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 11 Jun 2011 16:05:39 -0400 (EDT) Received: from amthrax by drake.mit.edu with local (Exim 4.76) (envelope-from ) id 1QVUR8-0000Hq-Sx; Sat, 11 Jun 2011 16:05:38 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 04/17] test: Test atomicity of notmuch new. Date: Sat, 11 Jun 2011 16:04:30 -0400 Message-Id: <1307822683-848-5-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.5.1 In-Reply-To: <1307822683-848-1-git-send-email-amdragon@mit.edu> References: <87ei34rnc5.fsf@yoom.home.cworth.org> <1307822683-848-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFIsWRmVeSWpSXmKPExsUixCmqrFtz6rOvwdlJshbXb85kdmD0eLbq FnMAYxSXTUpqTmZZapG+XQJXRv+bs2wF5+0qdm+9zt7AuNaki5GDQ0LAROLuQesuRk4gU0zi wr31bF2MXBxCAvsYJRp+LmCGcDYwSmy8soYVwrnPJHF351R2CGc+o8S+6Y/ZQPrZBDQktu1f zghiiwhIS+y8O5sVZAWzgJrEny4VkLCwgLXElKWnWUFsFgFViZ9/u8BsXgE7iYZ3W1kgzlCQ uHJlHpjNKWAvMe/gVTBbSCBNYsmt3ewTGPkXMDKsYpRNya3SzU3MzClOTdYtTk7My0st0rXQ y80s0UtNKd3ECAoadhfVHYwTDikdYhTgYFTi4VVc+9lXiDWxrLgy9xCjJAeTkiivzgmgEF9S fkplRmJxRnxRaU5q8SFGCQ5mJRHe9e2ffIV4UxIrq1KL8mFS0hwsSuK88yXVfYUE0hNLUrNT UwtSi2CyMhwcShK8m08CDRUsSk1PrUjLzClBSDNxcIIM5wEafhSkhre4IDG3ODMdIn+K0ZJj 9tr1hxg5dq3YBCQfbwCSQix5+XmpUuK8qSANAiANGaV5cDNhSeAVozjQi8K8u0CqeIAJBG7q K6CFTEALBUrBFpYkIqSkGhj5vYSTSidf9q74FBnMbfgp9kZ0mvFmU9fE0q5XsxdP3PDUJV5i wWqZT6Gh9oJ2X1UbzpZpZ3t8VrN6xLJYzl1MaXup94Urny/sOGvZzSt6e2bLLcO1T04+F/Ln NJCalcrqVcOepCjvW1y+4fYDm5w4HcFtc2RdXfVnhK4KfvnJubbM/BxPpxJLcUaioRZzUXEi ANp4SjndAgAA Cc: Austin Clements 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: Sat, 11 Jun 2011 20:05:42 -0000 This tests notmuch new's ability to recover from arbitrary stopping failures. It interrupts notmuch new after every database commit and, on every resulting database snapshot, re-runs notmuch new to completion and checks that the final database state is invariant. --- test/atomicity | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test/atomicity.gdb | 50 +++++++++++++++++++++++++ test/basic | 1 + test/notmuch-test | 1 + 4 files changed, 155 insertions(+), 0 deletions(-) create mode 100755 test/atomicity create mode 100644 test/atomicity.gdb diff --git a/test/atomicity b/test/atomicity new file mode 100755 index 0000000..817819a --- /dev/null +++ b/test/atomicity @@ -0,0 +1,103 @@ +#!/bin/bash +test_description='atomicity' +. ./test-lib.sh + +# This script tests the effects of killing and restarting "notmuch +# new" at arbitrary points. If notmuch new is properly atomic, the +# final database contents should be the same regardless of when (or +# if) it is killed and restarted. + +if test_expect_success "prereq: GDB is present" "which gdb"; then + test_set_prereq GDB +fi + +# Create a maildir structure to also stress flag synchronization +mkdir $MAIL_DIR/cur +mkdir $MAIL_DIR/new +mkdir $MAIL_DIR/tmp +mkdir $MAIL_DIR/.remove-dir + +# Prepare the initial database +generate_message [subject]='Duplicate' [filename]='duplicate:2,' [dir]=cur +generate_message [subject]='Remove' [filename]='remove:2,' [dir]=cur +generate_message [subject]='"Remove duplicate"' [filename]='remove-duplicate:2,' [dir]=cur +cp $MAIL_DIR/cur/remove-duplicate:2, $MAIL_DIR/cur/remove-duplicate-copy:2, +generate_message [subject]='Rename' [filename]='rename:2,' [dir]=cur +generate_message [subject]='"Rename duplicate"' [filename]='rename-duplicate:2,' [dir]=cur +generate_message [subject]='"Move 1"' [filename]='move1:2,' [dir]=cur +generate_message [subject]='"Move 2"' [filename]='move2:2,' [dir]=new +generate_message [subject]='Flag' [filename]='flag:2,' [dir]=cur +generate_message [subject]='"Flag duplicate"' [filename]='flag-duplicate:2,' [dir]=cur +cp $MAIL_DIR/cur/flag-duplicate:2, $MAIL_DIR/cur/flag-duplicate-copy:2,F +generate_message [subject]='"Remove directory"' [filename]='remove-directory:2,' [dir]=.remove-dir +generate_message [subject]='"Remove directory duplicate"' [filename]='remove-directory-duplicate:2,' [dir]=.remove-dir +cp $MAIL_DIR/.remove-dir/remove-directory-duplicate:2, $MAIL_DIR/cur/ +notmuch new > /dev/null + +# Make all maildir changes, but *don't* update the database +generate_message [subject]='Added' [filename]='added:2,' [dir]=cur +cp $MAIL_DIR/cur/duplicate:2, $MAIL_DIR/cur/duplicate-copy:2, +generate_message [subject]='"Add duplicate"' [filename]='add-duplicate:2,' [dir]=cur +generate_message [subject]='"Add duplicate copy"' [filename]='add-duplicate-copy:2,' [dir]=cur +rm $MAIL_DIR/cur/remove:2, +rm $MAIL_DIR/cur/remove-duplicate-copy:2, +mv $MAIL_DIR/cur/rename:2, $MAIL_DIR/cur/renamed:2, +mv $MAIL_DIR/cur/rename-duplicate:2, $MAIL_DIR/cur/renamed-duplicate:2, +mv $MAIL_DIR/cur/move1:2, $MAIL_DIR/new/move1:2, +mv $MAIL_DIR/new/move2:2, $MAIL_DIR/cur/move2:2, +mv $MAIL_DIR/cur/flag:2, $MAIL_DIR/cur/flag:2,F +rm $MAIL_DIR/cur/flag-duplicate-copy:2,F +rm $MAIL_DIR/.remove-dir/remove-directory:2, +rm $MAIL_DIR/.remove-dir/remove-directory-duplicate:2, +rmdir $MAIL_DIR/.remove-dir +increment_mtime $MAIL_DIR/cur +increment_mtime $MAIL_DIR/new +increment_mtime $MAIL_DIR + +# Prepare a snapshot of the updated maildir. The gdb script will +# update the database in this snapshot as it goes. +cp -ra $MAIL_DIR $MAIL_DIR.snap +cp ${NOTMUCH_CONFIG} ${NOTMUCH_CONFIG}.snap +NOTMUCH_CONFIG=${NOTMUCH_CONFIG}.snap notmuch config set database.path $MAIL_DIR.snap + + +test_begin_subtest '"notmuch new" is idempotent under arbitrary aborts' + +# Execute notmuch new and, at every call to rename, snapshot the +# database, run notmuch new again on the snapshot, and capture the +# results of search. +# +# -tty /dev/null works around a conflict between the 'timeout' wrapper +# and gdb's attempt to control the TTY. +export MAIL_DIR +gdb -tty /dev/null -batch -x $TEST_DIRECTORY/atomicity.gdb notmuch >/dev/null 2>/dev/null + +# Get the final, golden output +notmuch search '*' > expected + +# Check output against golden output +outcount=$(cat outcount) +echo -n > searchall +echo -n > expectall +for ((i = 0; i < $outcount; i++)); do + if ! cmp -s search.$i expected; then + # Find the range of interruptions that match this output + for ((end = $i + 1 ; end < $outcount; end++)); do + if ! cmp -s search.$i search.$end; then + break + fi + done + echo "When interrupted after $test/backtrace.$(expr $i - 1) (abort points $i-$(expr $end - 1))" >> searchall + cat search.$i >> searchall + cat expected >> expectall + echo >> searchall + echo >> expectall + + i=$(expr $end - 1) + fi +done +test_expect_equal_failure GDB "$(cat searchall)" "$(cat expectall)" + +test_expect_success GDB "detected $outcount>10 abort points" "test $outcount -gt 10" + +test_done diff --git a/test/atomicity.gdb b/test/atomicity.gdb new file mode 100644 index 0000000..fd67525 --- /dev/null +++ b/test/atomicity.gdb @@ -0,0 +1,50 @@ +# This gdb script runs notmuch new and simulates killing and +# restarting notmuch new after every Xapian commit. To simulate this +# more efficiently, this script runs notmuch new and, immediately +# after every Xapian commit, it *pauses* the running notmuch new, +# copies the entire database and maildir to a snapshot directory, and +# executes a full notmuch new on that snapshot, comparing the final +# results with the expected output. It can then resume the paused +# notmuch new, which is still running on the original maildir, and +# repeat this process. + +set args new + +# Make Xapian commit after every operation instead of batching +set environment XAPIAN_FLUSH_THRESHOLD = 1 + +# gdb can't keep track of a simple integer. This is me weeping. +shell echo 0 > outcount + +shell touch inodes + +break rename +commands +# As an optimization, only consider snapshots after a Xapian commit. +# Xapian overwrites record.base? as the last step in the commit. +shell echo > gdbcmd +shell stat -c %i $MAIL_DIR/.notmuch/xapian/record.base* > inodes.new +shell if cmp inodes inodes.new; then echo cont > gdbcmd; fi +shell mv inodes.new inodes +source gdbcmd + +# Save a backtrace in case the test does fail +set logging file backtrace +set logging on +backtrace +set logging off +shell mv backtrace backtrace.`cat outcount` + +# Snapshot the database +shell rm -r $MAIL_DIR.snap/.notmuch +shell cp -r $MAIL_DIR/.notmuch $MAIL_DIR.snap/.notmuch +# Restore the mtime of $MAIL_DIR.snap, which we just changed +shell touch -r $MAIL_DIR $MAIL_DIR.snap +# Run notmuch new to completion on the snapshot +shell NOTMUCH_CONFIG=${NOTMUCH_CONFIG}.snap XAPIAN_FLUSH_THRESHOLD=1000 notmuch new > /dev/null +shell NOTMUCH_CONFIG=${NOTMUCH_CONFIG}.snap notmuch search '*' > search.`cat outcount` 2>&1 +shell echo $(expr $(cat outcount) + 1) > outcount +cont +end + +run diff --git a/test/basic b/test/basic index 808c968..5e0adf0 100755 --- a/test/basic +++ b/test/basic @@ -60,6 +60,7 @@ available=$(ls -1 ../ | \ -e "/^(test.expected-output|.*~)/d" \ -e "/^(gnupg-secret-key.asc)/d" \ -e "/^(gnupg-secret-key.NOTE)/d" \ + -e "/^(atomicity.gdb)/d" \ | sort) test_expect_equal "$tests_in_suite" "$available" diff --git a/test/notmuch-test b/test/notmuch-test index 9f58c12..c540228 100755 --- a/test/notmuch-test +++ b/test/notmuch-test @@ -40,6 +40,7 @@ TESTS=" emacs-large-search-buffer maildir-sync crypto + atomicity " TESTS=${NOTMUCH_TESTS:=$TESTS} -- 1.7.5.1