]> git.notmuchmail.org Git - notmuch/blob - test/atomicity
test: Move tests from emacs to emacs-show
[notmuch] / test / atomicity
1 #!/usr/bin/env bash
2 test_description='atomicity'
3 . ./test-lib.sh
4
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.
9
10 if test_require_external_prereq gdb; then
11
12 # Create a maildir structure to also stress flag synchronization
13     mkdir $MAIL_DIR/cur
14     mkdir $MAIL_DIR/new
15     mkdir $MAIL_DIR/tmp
16     mkdir $MAIL_DIR/.remove-dir
17
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
34
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
51
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
57
58
59
60     # Execute notmuch new and, at every call to rename, snapshot the
61     # database, run notmuch new again on the snapshot, and capture the
62     # results of search.
63     #
64     # -tty /dev/null works around a conflict between the 'timeout' wrapper
65     # and gdb's attempt to control the TTY.
66     export MAIL_DIR
67     gdb -tty /dev/null -batch -x $TEST_DIRECTORY/atomicity.gdb notmuch >/dev/null 2>/dev/null
68
69     # Get the final, golden output
70     notmuch search '*' > expected
71
72     # Check output against golden output
73     outcount=$(cat outcount)
74     echo -n > searchall
75     echo -n > expectall
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
81                     break
82                 fi
83             done
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
87             echo >> searchall
88             echo >> expectall
89
90             i=$(expr $end - 1)
91         fi
92     done
93 fi
94
95 test_begin_subtest '"notmuch new" is idempotent under arbitrary aborts'
96 test_expect_equal_file searchall expectall
97
98 test_expect_success "detected $outcount>10 abort points" "test $outcount -gt 10"
99
100 test_done