aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/atomicity.gdb
diff options
context:
space:
mode:
authorGravatar Austin Clements <amdragon@mit.edu>2011-01-28 13:03:24 -0500
committerGravatar David Bremner <bremner@debian.org>2011-09-12 23:36:00 -0300
commit9ade8160a6a3f6f55996d7a58dc2cd81a6df8395 (patch)
treedf917939f1a2e4a0bd68659e88246b9a84db8d67 /test/atomicity.gdb
parent62445dd0231c4f9e49f0be293e9f539d63bfdc99 (diff)
test: Test atomicity of notmuch new.
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.
Diffstat (limited to 'test/atomicity.gdb')
-rw-r--r--test/atomicity.gdb50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/atomicity.gdb b/test/atomicity.gdb
new file mode 100644
index 00000000..fd675257
--- /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