2 test_description="threading when messages received out of order"
3 . $(dirname "$0")/test-lib.sh || exit 1
5 # Generate all single-root four message thread structures. We'll use
6 # this for multiple tests below.
7 THREADS=$($NOTMUCH_PYTHON ${NOTMUCH_SRCDIR}/test/gen-threads.py 4)
8 nthreads=$(wc -l <<< "$THREADS")
10 test_begin_subtest "Messages with one parent get linked in all delivery orders"
11 # In the first variant, this delivers messages that reference only
12 # their immediate parent. Hence, we should only expect threads to be
13 # fully joined at the end.
14 for ((n = 0; n < 4; n++)); do
15 # Deliver the n'th message of every thread
17 while read -a parents; do
20 [id]=m$n@t$thread [in-reply-to]="\<m$parent@t$thread\>" \
21 [subject]=p$thread [from]=m$n
22 thread=$((thread + 1))
24 notmuch new > /dev/null
26 output=$(notmuch search --sort=newest-first '*' | notmuch_search_sanitize)
27 expected=$(for ((i = 0; i < $nthreads; i++)); do
28 echo "thread:XXX 2001-01-05 [4/4] m3, m2, m1, m0; p$i (inbox unread)"
30 test_expect_equal "$output" "$expected"
32 test_begin_subtest "Messages with all parents get linked in all delivery orders"
33 # Here we do the same thing as the previous test, but each message
34 # references all of its parents. Since every message references the
35 # root of the thread, each thread should always be fully joined. This
36 # is currently broken because of the bug detailed in
37 # id:8738h7kv2q.fsf@qmul.ac.uk.
39 notmuch new > /dev/null
42 for ((n = 0; n < 4; n++)); do
43 # Deliver the n'th message of every thread
45 while read -a parents; do
48 while [[ ${parent:-None} != None ]]; do
49 references="<m$parent@t$thread> $references"
51 parent=${parents[$parent]}
52 # Avoid looping over broken input (if ever)
57 [id]=m$n@t$thread [references]="'$references'" \
58 [subject]=p$thread [from]=m$n
59 thread=$((thread + 1))
61 notmuch new > /dev/null
64 $(notmuch search --sort=newest-first '*' | notmuch_search_sanitize)"
66 # Construct expected output
67 template="thread:XXX 2001-01-05 [$((n+1))/$((n+1))]"
68 for ((m = n; m > 0; m--)); do
69 template="$template m$m,"
72 $(for ((i = 0; i < $nthreads; i++)); do
73 echo "$template m0; p$i (inbox unread)"
76 test_expect_equal "$output" "$expected"