]> git.notmuchmail.org Git - notmuch/blob - test/T592-thread-breakage.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / T592-thread-breakage.sh
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2016 Daniel Kahn Gillmor
4 #
5
6 test_description='thread breakage during reindexing'
7
8 # notmuch uses ghost documents to track messages we have seen references
9 # to but have never seen.  Regardless of the order of delivery, message
10 # deletion, and reindexing, the list of ghost messages for a given
11 # stored corpus should not vary, so that threads can be reassmebled
12 # cleanly.
13 #
14 # In practice, we accept a small amount of variation (and therefore
15 # traffic pattern metadata leakage to be stored in the index) for the
16 # sake of efficiency.
17 #
18 # This test also embeds some subtests to ensure that indexing actually
19 # works properly and attempted fixes to threading issues do not break
20 # the expected contents of the index.
21
22 . $(dirname "$0")/test-lib.sh || exit 1
23
24 if [ -n "${NOTMUCH_TEST_INSTALLED-}" ]; then
25     test_done
26 fi
27
28 message_a () {
29     mkdir -p ${MAIL_DIR}/cur
30     cat > ${MAIL_DIR}/cur/a <<EOF
31 Subject: First message
32 Message-ID: <a@example.net>
33 From: Alice <alice@example.net>
34 To: Bob <bob@example.net>
35 Date: Thu, 31 Mar 2016 20:10:00 -0400
36
37 This is the first message in the thread.
38 Apple
39 EOF
40 }
41
42 message_b () {
43     mkdir -p ${MAIL_DIR}/cur
44     cat > ${MAIL_DIR}/cur/b <<EOF
45 Subject: Second message
46 Message-ID: <b@example.net>
47 In-Reply-To: <a@example.net>
48 References: <a@example.net>
49 From: Bob <bob@example.net>
50 To: Alice <alice@example.net>
51 Date: Thu, 31 Mar 2016 20:15:00 -0400
52
53 This is the second message in the thread.
54 Banana
55 EOF
56 }
57
58
59 test_content_count () {
60     test_begin_subtest "${3:-looking for $2 instance of '$1'}"
61     count=$(notmuch count --output=threads "$1")
62     test_expect_equal "$count" "$2"
63 }
64
65 test_thread_count () {
66     test_begin_subtest "${2:-Expecting $1 thread(s)}"
67     count=$(notmuch count --output=threads)
68     test_expect_equal "$count" "$1"
69 }
70
71 test_ghost_count () {
72     test_begin_subtest "${2:-Expecting $1 ghosts(s)}"
73     ghosts=$($NOTMUCH_BUILDDIR/test/ghost-report ${MAIL_DIR}/.notmuch/xapian)
74     test_expect_equal "$ghosts" "$1"
75 }
76
77 notmuch new >/dev/null
78
79 test_thread_count 0 'There should be no threads initially'
80 test_ghost_count 0 'There should be no ghosts initially'
81
82 message_a
83 notmuch new >/dev/null
84 test_thread_count 1 'One message in: one thread'
85 test_content_count apple 1
86 test_content_count banana 0
87 test_ghost_count 0
88
89 message_b
90 notmuch new >/dev/null
91 test_thread_count 1 'Second message in the same thread: one thread'
92 test_content_count apple 1
93 test_content_count banana 1
94 test_ghost_count 0
95
96 rm -f ${MAIL_DIR}/cur/a
97 notmuch new >/dev/null
98 test_thread_count 1 'First message removed: still only one thread'
99 test_content_count apple 0
100 test_content_count banana 1
101 test_ghost_count 1 'should be one ghost after first message removed'
102
103 message_a
104 notmuch new >/dev/null
105 test_thread_count 1 'First message reappears: should return to the same thread'
106 test_content_count apple 1
107 test_content_count banana 1
108 test_ghost_count 0
109
110 rm -f ${MAIL_DIR}/cur/b
111 notmuch new >/dev/null
112 test_thread_count 1 'Removing second message: still only one thread'
113 test_content_count apple 1
114 test_content_count banana 0
115 test_begin_subtest 'No ghosts should remain after deletion of second message'
116 # this is known to fail; we are leaking ghost messages deliberately
117 test_subtest_known_broken
118 ghosts=$($NOTMUCH_BUILDDIR/test/ghost-report ${MAIL_DIR}/.notmuch/xapian)
119 test_expect_equal "$ghosts" "0"
120
121 rm -f ${MAIL_DIR}/cur/a
122 notmuch new >/dev/null
123 test_thread_count 0 'All messages gone: no threads'
124 test_content_count apple 0
125 test_content_count banana 0
126 test_ghost_count 0 'No ghosts should remain after full thread deletion'
127
128 test_done