--- /dev/null
+Return-Path: <m.walters@qmul.ac.uk>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 12E4A431FBF\r
+ for <notmuch@notmuchmail.org>; Tue, 22 Apr 2014 14:31:37 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.502\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.502 tagged_above=-999 required=5\r
+ tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+ NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id lHBFgiZAz2me for <notmuch@notmuchmail.org>;\r
+ Tue, 22 Apr 2014 14:31:29 -0700 (PDT)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id D816C431FBD\r
+ for <notmuch@notmuchmail.org>; Tue, 22 Apr 2014 14:31:28 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+ by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1WciHf-0004dP-5D; Tue, 22 Apr 2014 22:31:23 +0100\r
+Received: from 5751dfa2.skybroadband.com ([87.81.223.162] helo=localhost)\r
+ by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1WciHe-000071-LC; Tue, 22 Apr 2014 22:31:18 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v2] test: Test thread linking in all possible delivery\r
+ orders\r
+In-Reply-To: <1398110291-15832-1-git-send-email-amdragon@mit.edu>\r
+References: <87y4zhfmrn.fsf@maritornes.cs.unb.ca>\r
+ <1398110291-15832-1-git-send-email-amdragon@mit.edu>\r
+User-Agent: Notmuch/0.15.2+615~g78e3a93 (http://notmuchmail.org) Emacs/23.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Tue, 22 Apr 2014 22:31:10 +0100\r
+Message-ID: <87wqehaw69.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 87.81.223.162\r
+X-QM-Geographic: According to ripencc,\r
+ this message was delivered by a machine in Britain (UK) (GB).\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: 5eb0dfbe17deb5b67783cb2efcf93ff8 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -0.1\r
+X-SpamAssassin-SpamBar: /\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+ determine if it is\r
+ spam. We require at least 5.0 points to mark a message as spam.\r
+ This message scored -0.1 points.\r
+ Summary of the scoring: \r
+ * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+ provider * (markwalters1009[at]gmail.com)\r
+ * -0.1 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 22 Apr 2014 21:31:37 -0000\r
+\r
+\r
+Hi\r
+\r
+Broadly this looks good but I am somewhat confused by the python\r
+part. Is it intended to produce the same tree multiple times? It does\r
+seem to produce all the possible trees (*) so it doesn't matter but\r
+might be worth a comment.\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+(*) I think there should be 64 rooted trees (16 trees and 4 possible\r
+roots) and the python generates 144 lines. Piping the output to sort and\r
+uniq gives 64 lines.\r
+\r
+\r
+ \r
+On Mon, 21 Apr 2014, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> These tests deliver all possible (single-root) four-message threads in\r
+> all possible orders and check that notmuch successfully links them\r
+> into threads.\r
+>\r
+> There are two variants of the test: one delivers messages that\r
+> reference only their immediate parent and the other delivers messages\r
+> that reference all of their parents. The latter test is currently\r
+> known-broken.\r
+>\r
+> This is introduced as a new test (rather than just adding it to\r
+> T050-new) because it's much easier for this to start with an empty\r
+> database.\r
+> ---\r
+>\r
+> This version hopefully addresses David's comments in\r
+> id:87y4zhfmrn.fsf@maritornes.cs.unb.ca and adds a second test that\r
+> demonstrates the bug Mark in figured out in\r
+> id:8738h7kv2q.fsf@qmul.ac.uk.\r
+>\r
+> test/T051-new-linking.sh | 91 ++++++++++++++++++++++++++++++++++++++++++++++++\r
+> 1 file changed, 91 insertions(+)\r
+> create mode 100755 test/T051-new-linking.sh\r
+>\r
+> diff --git a/test/T051-new-linking.sh b/test/T051-new-linking.sh\r
+> new file mode 100755\r
+> index 0000000..9ccbc52\r
+> --- /dev/null\r
+> +++ b/test/T051-new-linking.sh\r
+> @@ -0,0 +1,91 @@\r
+> +#!/usr/bin/env bash\r
+> +test_description='"notmuch new" thread linking'\r
+> +\r
+> +. ./test-lib.sh\r
+> +\r
+> +# Generate all possible single-root four message thread structures.\r
+> +# Each line in THREADS is a thread structure, where the n'th field is\r
+> +# the parent of message n. We'll use this for multiple tests below.\r
+> +THREADS=$(python -c '\r
+> +def mkTrees(free, tree={}):\r
+> + if free == set():\r
+> + print(" ".join(map(str, [msg[1] for msg in sorted(tree.items())])))\r
+> + return\r
+> + # Attach each free message to each message in the tree (if there is\r
+> + # no tree, make the free message the root), backtracking after each\r
+> + for msg in sorted(free):\r
+> + parents = sorted(tree.keys()) if tree else ["none"]\r
+> + for parent in parents:\r
+> + ntree = tree.copy()\r
+> + ntree[msg] = parent\r
+> + mkTrees(free - set([msg]), ntree)\r
+> +mkTrees(set(range(4)))')\r
+> +nthreads=$(wc -l <<< "$THREADS")\r
+> +\r
+> +test_begin_subtest "All four-message threads get linked in all delivery orders (one parent)"\r
+> +# In the first variant, this delivers messages that reference only\r
+> +# their immediate parent. Hence, we should only expect threads to be\r
+> +# fully joined at the end.\r
+> +for ((n = 0; n < 4; n++)); do\r
+> + # Deliver the n'th message of every thread\r
+> + thread=0\r
+> + while read -a parents; do\r
+> + parent=${parents[$n]}\r
+> + generate_message \\r
+> + [id]=m$n@t$thread [in-reply-to]="\<m$parent@t$thread\>" \\r
+> + [subject]=p$thread [from]=m$n\r
+> + thread=$((thread + 1))\r
+> + done <<< "$THREADS"\r
+> + notmuch new > /dev/null\r
+> +done\r
+> +output=$(notmuch search --sort=newest-first '*' | notmuch_search_sanitize)\r
+> +expected=$(for ((i = 0; i < $nthreads; i++)); do\r
+> + echo "thread:XXX 2001-01-05 [4/4] m3, m2, m1, m0; p$i (inbox unread)"\r
+> + done)\r
+> +test_expect_equal "$output" "$expected"\r
+> +\r
+> +test_begin_subtest "The same (full parent linkage)"\r
+> +test_subtest_known_broken\r
+> +# Here we do the same thing as the previous test, but each message\r
+> +# references all of its parents. Since every message references the\r
+> +# root of the thread, each thread should always be fully joined. This\r
+> +# is currently broken because of the bug detailed in\r
+> +# id:8738h7kv2q.fsf@qmul.ac.uk.\r
+> +rm ${MAIL_DIR}/*\r
+> +notmuch new\r
+> +output=""\r
+> +expected=""\r
+> +for ((n = 0; n < 4; n++)); do\r
+> + # Deliver the n'th message of every thread\r
+> + thread=0\r
+> + while read -a parents; do\r
+> + references=""\r
+> + parent=${parents[$n]}\r
+> + while [[ $parent != none ]]; do\r
+> + references="<m$parent@t$thread> $references"\r
+> + parent=${parents[$parent]}\r
+> + done\r
+> +\r
+> + generate_message \\r
+> + [id]=m$n@t$thread [references]="'$references'" \\r
+> + [subject]=p$thread [from]=m$n\r
+> + thread=$((thread + 1))\r
+> + done <<< "$THREADS"\r
+> + notmuch new > /dev/null\r
+> +\r
+> + output="$output\r
+> +$(notmuch search --sort=newest-first '*' | notmuch_search_sanitize)"\r
+> +\r
+> + # Construct expected output\r
+> + template="thread:XXX 2001-01-05 [$((n+1))/$((n+1))]"\r
+> + for ((m = n; m > 0; m--)); do\r
+> + template="$template m$m,"\r
+> + done\r
+> + expected="$expected\r
+> +$(for ((i = 0; i < $nthreads; i++)); do\r
+> + echo "$template m0; p$i (inbox unread)"\r
+> + done)"\r
+> +done\r
+> +test_expect_equal "$output" "$expected"\r
+> +\r
+> +test_done\r
+> -- \r
+> 1.9.1\r