2 test_description='atomicity'
3 . ./test-lib.sh || exit 1
5 # This script tests the effects of killing and restarting "notmuch
6 # new" at arbitrary points. If notmuch new is properly atomic, the
7 # final database contents should be the same regardless of when (or
8 # if) it is killed and restarted.
10 if test_require_external_prereq gdb; then
12 # Create a maildir structure to also stress flag synchronization
16 mkdir $MAIL_DIR/.remove-dir
18 # Prepare the initial database
19 generate_message [subject]='Duplicate' [filename]='duplicate:2,' [dir]=cur
20 generate_message [subject]='Remove' [filename]='remove:2,' [dir]=cur
21 generate_message [subject]='"Remove duplicate"' [filename]='remove-duplicate:2,' [dir]=cur
22 cp $MAIL_DIR/cur/remove-duplicate:2, $MAIL_DIR/cur/remove-duplicate-copy:2,
23 generate_message [subject]='Rename' [filename]='rename:2,' [dir]=cur
24 generate_message [subject]='"Rename duplicate"' [filename]='rename-duplicate:2,' [dir]=cur
25 generate_message [subject]='"Move 1"' [filename]='move1:2,' [dir]=cur
26 generate_message [subject]='"Move 2"' [filename]='move2:2,' [dir]=new
27 generate_message [subject]='Flag' [filename]='flag:2,' [dir]=cur
28 generate_message [subject]='"Flag duplicate"' [filename]='flag-duplicate:2,' [dir]=cur
29 cp $MAIL_DIR/cur/flag-duplicate:2, $MAIL_DIR/cur/flag-duplicate-copy:2,F
30 generate_message [subject]='"Remove directory"' [filename]='remove-directory:2,' [dir]=.remove-dir
31 generate_message [subject]='"Remove directory duplicate"' [filename]='remove-directory-duplicate:2,' [dir]=.remove-dir
32 cp $MAIL_DIR/.remove-dir/remove-directory-duplicate:2, $MAIL_DIR/cur/
33 notmuch new > /dev/null
35 # Make all maildir changes, but *don't* update the database
36 generate_message [subject]='Added' [filename]='added:2,' [dir]=cur
37 cp $MAIL_DIR/cur/duplicate:2, $MAIL_DIR/cur/duplicate-copy:2,
38 generate_message [subject]='"Add duplicate"' [filename]='add-duplicate:2,' [dir]=cur
39 generate_message [subject]='"Add duplicate copy"' [filename]='add-duplicate-copy:2,' [dir]=cur
40 rm $MAIL_DIR/cur/remove:2,
41 rm $MAIL_DIR/cur/remove-duplicate-copy:2,
42 mv $MAIL_DIR/cur/rename:2, $MAIL_DIR/cur/renamed:2,
43 mv $MAIL_DIR/cur/rename-duplicate:2, $MAIL_DIR/cur/renamed-duplicate:2,
44 mv $MAIL_DIR/cur/move1:2, $MAIL_DIR/new/move1:2,
45 mv $MAIL_DIR/new/move2:2, $MAIL_DIR/cur/move2:2,
46 mv $MAIL_DIR/cur/flag:2, $MAIL_DIR/cur/flag:2,F
47 rm $MAIL_DIR/cur/flag-duplicate-copy:2,F
48 rm $MAIL_DIR/.remove-dir/remove-directory:2,
49 rm $MAIL_DIR/.remove-dir/remove-directory-duplicate:2,
50 rmdir $MAIL_DIR/.remove-dir
52 # Prepare a snapshot of the updated maildir. The gdb script will
53 # update the database in this snapshot as it goes.
54 cp -a $MAIL_DIR $MAIL_DIR.snap
55 cp ${NOTMUCH_CONFIG} ${NOTMUCH_CONFIG}.snap
56 NOTMUCH_CONFIG=${NOTMUCH_CONFIG}.snap notmuch config set database.path $MAIL_DIR.snap
60 # Execute notmuch new and, at every call to rename, snapshot the
61 # database, run notmuch new again on the snapshot, and capture the
64 # -tty /dev/null works around a conflict between the 'timeout' wrapper
65 # and gdb's attempt to control the TTY.
67 gdb -tty /dev/null -batch -x $TEST_DIRECTORY/atomicity.py notmuch 1>gdb.out 2>&1
69 # Get the final, golden output
70 notmuch search '*' > expected
72 # Check output against golden output
73 outcount=$(cat outcount)
76 for ((i = 0; i < $outcount; i++)); do
77 if ! cmp -s search.$i expected; then
78 # Find the range of interruptions that match this output
79 for ((end = $i + 1 ; end < $outcount; end++)); do
80 if ! cmp -s search.$i search.$end; then
84 echo "When interrupted after $test/backtrace.$(expr $i - 1) (abort points $i-$(expr $end - 1))" >> searchall
85 cat search.$i >> searchall
86 cat expected >> expectall
95 test_begin_subtest '"notmuch new" is idempotent under arbitrary aborts'
96 test_expect_equal_file searchall expectall
98 test_expect_success "detected $outcount>10 abort points" "test $outcount -gt 10"