From: Austin Clements <amdragon@MIT.EDU>
To: notmuch@notmuchmail.org
Cc: amdragon@mit.edu
Subject: [PATCH 01/10] test: Test atomicity of notmuch new.
Date: Fri, 18 Feb 2011 02:58:51 -0500 [thread overview]
Message-ID: <1298015940-31986-2-git-send-email-amdragon@mit.edu> (raw)
In-Reply-To: <1298015940-31986-1-git-send-email-amdragon@mit.edu>
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 | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++
test/atomicity.gdb | 38 ++++++++++++++++++++++
test/basic | 4 ++-
test/notmuch-test | 1 +
4 files changed, 132 insertions(+), 1 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..e242802
--- /dev/null
+++ b/test/atomicity
@@ -0,0 +1,90 @@
+#!/bin/bash
+test_description='atomicity'
+. ./test-lib.sh
+
+# 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 database changes
+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 the database snapshot
+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.
+export MAIL_DIR
+gdb -batch -x ../atomicity.gdb notmuch > /dev/null 2>&1
+
+# 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 "$(cat searchall)" "$(cat expectall)"
+
+test_expect_success "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..a20d977
--- /dev/null
+++ b/test/atomicity.gdb
@@ -0,0 +1,38 @@
+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
+# 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 3b43ad9..f9d5fc3 100755
--- a/test/basic
+++ b/test/basic
@@ -57,7 +57,9 @@ available=$(ls -1 ../ | \
sed -r -e "/^(aggregate-results.sh|Makefile|Makefile.local|notmuch-test)/d" \
-e "/^(README|test-lib.sh|test-results|tmp.*|valgrind|corpus*)/d" \
-e "/^(emacs.expected-output|smtp-dummy|smtp-dummy.c|test-verbose)/d" \
- -e "/^(test.expected-output|.*~)/d" | sort)
+ -e "/^(test.expected-output|.*~)/d" \
+ -e "/^(atomicity.gdb)/d" \
+ | sort)
test_expect_equal "$tests_in_suite" "$available"
EXPECTED=../test.expected-output
diff --git a/test/notmuch-test b/test/notmuch-test
index 9d77c0f..c506705 100755
--- a/test/notmuch-test
+++ b/test/notmuch-test
@@ -36,6 +36,7 @@ TESTS="
encoding
emacs
maildir-sync
+ atomicity
"
# Clean up any results from a previous run
--
1.7.2.3
next prev parent reply other threads:[~2011-02-18 7:59 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-18 7:58 [PATCH 00/10] Fix 'notmuch new' atomicity issues Austin Clements
2011-02-18 7:58 ` Austin Clements [this message]
2011-05-04 20:32 ` [PATCH 01/10 v2] test: Test atomicity of notmuch new Austin Clements
2011-02-18 7:58 ` [PATCH 02/10] new: Don't loose messages on SIGINT Austin Clements
2011-02-18 7:58 ` [PATCH 03/10] new: Defer updating directory mtimes until the end Austin Clements
2011-02-18 7:58 ` [PATCH 04/10] lib: Make _notmuch_message_sync capable of deleting a message Austin Clements
2011-02-18 7:58 ` [PATCH 05/10] lib: Indicate if there are more filenames after removal Austin Clements
2011-02-18 7:58 ` [PATCH 06/10] lib: Add API's to find by filename and remove a filename from a message Austin Clements
2011-02-18 7:58 ` [PATCH 07/10] new: Use the new filename removal API Austin Clements
2011-02-18 7:58 ` [PATCH 08/10] new: Synchronize maildir flags eagerly Austin Clements
2011-02-18 7:58 ` [PATCH 09/10] lib: Add notmuch_database_{begin,end}_atomic Austin Clements
2011-02-18 7:59 ` [PATCH 10/10] new: Wrap adding a message in an atomic section Austin Clements
2011-04-26 4:13 ` [PATCH 00/10] Fix 'notmuch new' atomicity issues Austin Clements
2011-05-04 20:30 ` Austin Clements
2011-05-29 2:51 ` Austin Clements
2011-06-08 22:05 ` Carl Worth
2011-06-10 21:11 ` Austin Clements
2011-06-10 22:02 ` Carl Worth
2011-06-10 22:27 ` Austin Clements
2011-06-11 20:04 ` [PATCH v6 00/17] " Austin Clements
2011-06-11 20:04 ` [PATCH 02/17] test: Report test failures from test_expect_* Austin Clements
2011-06-11 20:04 ` [PATCH 03/17] lib: Add missing status check in _notmuch_message_remove_filename Austin Clements
2011-06-11 20:04 ` [PATCH 04/17] test: Test atomicity of notmuch new Austin Clements
2011-06-11 20:04 ` [PATCH 05/17] new: Don't lose messages on SIGINT Austin Clements
2011-06-11 20:04 ` [PATCH 06/17] new: Defer updating directory mtimes until the end Austin Clements
2011-06-11 20:04 ` [PATCH 07/17] lib: Add notmuch_database_{begin,end}_atomic Austin Clements
2011-06-11 20:04 ` [PATCH 08/17] lib: Add support for nested atomic sections Austin Clements
2011-06-11 20:04 ` [PATCH 09/17] lib: Indicate if there are more filenames after removal Austin Clements
2011-06-11 20:04 ` [PATCH 10/17] lib: Remove message document directly after removing the last file name Austin Clements
2011-06-11 20:04 ` [PATCH 11/17] lib: Add an API to find a message by filename Austin Clements
2011-06-11 20:04 ` [PATCH 12/17] lib: Wrap notmuch_database_add_message in an atomic section Austin Clements
2011-06-11 20:04 ` [PATCH 13/17] new: Cleanup. Put removed/renamed message count in add_files_state_t Austin Clements
2011-06-11 20:04 ` [PATCH 14/17] new: Cleanup. De-duplicate file name removal code Austin Clements
2011-06-11 20:04 ` [PATCH 15/17] new: Synchronize maildir flags eagerly Austin Clements
2011-06-11 20:04 ` [PATCH 16/17] new: Wrap adding and removing messages in atomic sections Austin Clements
2011-06-11 20:04 ` [PATCH 17/17] lib: Improve notmuch_database_{add, remove}_message documentation Austin Clements
2011-06-11 20:49 ` [PATCH 01/17] test: Fix message when skipping test_expect_equal* tests Austin Clements
2011-06-11 20:53 ` [PATCH v6 00/17] Fix 'notmuch new' atomicity issues Austin Clements
2011-06-22 19:39 ` Austin Clements
2011-06-29 6:37 ` Austin Clements
2011-07-08 18:09 ` Austin Clements
2011-09-13 12:39 ` David Bremner
2011-09-24 3:14 ` David Bremner
2011-09-24 4:03 ` Austin Clements
2011-09-25 2:36 ` David Bremner
2011-09-26 22:07 ` Austin Clements
2011-09-26 23:32 ` NEWS for 0.9 David Bremner
2011-09-27 13:08 ` Ali Polatel
2011-09-28 16:36 ` [PATCH v6 00/17] Fix 'notmuch new' atomicity issues Sebastian Spaeth
2011-09-29 15:01 ` Austin Clements
2011-09-30 9:21 ` Sebastian Spaeth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1298015940-31986-2-git-send-email-amdragon@mit.edu \
--to=amdragon@mit.edu \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).