]> git.notmuchmail.org Git - notmuch/blobdiff - test/notmuch-test
notmuch-test: Eliminate sleeps to speed up test suite run
[notmuch] / test / notmuch-test
index a06b5f059b32ea949afed56306a35f4f68bcfd86..961c8fd7b9a2541aa3419684b4760e6e1d93f7ac 100755 (executable)
@@ -20,6 +20,15 @@ find_notmuch_binary ()
     echo notmuch
 }
 
+increment_mtime_amount=0
+increment_mtime ()
+{
+    dir=$1
+
+    increment_mtime_amount=$((increment_mtime_amount + 1))
+    touch -d "+${increment_mtime_amount} seconds" $dir
+}
+
 # Generate a new message in the mail directory, with
 # a unique message ID and subject.
 #
@@ -34,12 +43,31 @@ find_notmuch_binary ()
 #
 #      Generate the message in directory 'directory/of/choice' within
 #      the mail store. The directory will be created if necessary.
+#
+#  [body]=text
+#
+#      Text to use as the body of the email message
+#
+#  '[from]="Some User <user@example.com>"'
+#  '[to]="Some User <user@example.com>"'
+#  '[subject]="Subject of email message"'
+#
+#      Values for email headers. If not provided, default values will
+#      be generated instead.
+#
+#  '[cc]="Some User <user@example.com>"'
+#  [in-reply-to]=<message-id>
+#
+#      Additional values for email headers. If these are not provided
+#      then the relevant headers will simply not appear in the
+#      message.
 gen_msg_cnt=0
 gen_msg_filename=""
 generate_message ()
 {
     # This is our (bash-specific) magic for doing named parameters
     local -A template="($@)"
+    local additional_headers
 
     gen_msg_cnt=$((gen_msg_cnt + 1))
     gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)
@@ -51,20 +79,46 @@ generate_message ()
        mkdir -p $(dirname $gen_msg_filename)
     fi
 
+    if [ -z "${template[body]}" ]; then
+       template[body]="This is just a test message at ${gen_msg_filename}"
+    fi
+
+    if [ -z "${template[from]}" ]; then
+       template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"
+    fi
+
+    if [ -z "${template[to]}" ]; then
+       template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"
+    fi
+
+    if [ -z "${template[subject]}" ]; then
+       template[subject]="Test message ${gen_msg_filename}"
+    fi
+
+    additional_headers=""
+    if [ ! -z "${template[cc]}" ]; then
+       additional_headers="Cc: ${template[cc]}
+${additional_headers}"
+    fi
+
+    if [ ! -z "${template[in-reply-to]}" ]; then
+       additional_headers="In-Reply-To: ${template[in-reply-to]}
+${additional_headers}"
+    fi
+
 cat <<EOF >$gen_msg_filename
-From: Notmuch Test Suite <test_suite@notmuchmail.org>
-To: Notmuch Test Suite <test_suite@notmuchmail.org>
+From: ${template[from]}
+To: ${template[to]}
 Message-Id: <msg-${gen_msg_cnt}@notmuch-test-suite>
-Subject: Test message ${gen_msg_filename}
+Subject: ${template[subject]}
 Date: Tue, 05 Jan 2010 15:43:57 -0800
-
-This is just a test message at ${gen_msg_filename}
+${additional_headers}
+${template[body]}
 EOF
 }
 
-do_sleep ()
-{
-    sleep 1
+    # Ensure that the mtime of the containing directory is updated
+    increment_mtime $(dirname ${gen_msg_filename})
 }
 
 NOTMUCH_IGNORED_OUTPUT_REGEXP='^Processed [0-9]*( total)? file|Found [0-9]* total file'
@@ -109,12 +163,10 @@ printf " No new messages...\t\t"
 execute_expecting new "No new mail."
 
 printf " Single new message...\t\t"
-do_sleep
 generate_message
 execute_expecting new "Added 1 new message to the database."
 
 printf " Multiple new messages...\t"
-do_sleep
 generate_message
 generate_message
 execute_expecting new "Added 2 new messages to the database."
@@ -145,51 +197,48 @@ generate_message
 tmp_msg_filename=tmp/$gen_msg_filename
 mkdir -p $(dirname $tmp_msg_filename)
 mv $gen_msg_filename $tmp_msg_filename
-do_sleep
+increment_mtime ${MAIL_DIR}
 $NOTMUCH new > /dev/null
-do_sleep
 mv $tmp_msg_filename $gen_msg_filename
+increment_mtime ${MAIL_DIR}
 execute_expecting new "Added 1 new message to the database."
 
 printf " Renamed message...\t\t"
 
-do_sleep
 generate_message
 $NOTMUCH new > /dev/null
-do_sleep
 mv $gen_msg_filename ${gen_msg_filename}-renamed
+increment_mtime ${MAIL_DIR}
 execute_expecting new "No new mail. Detected 1 file rename."
 
 printf " Deleted message...\t\t"
 
-do_sleep
 rm ${gen_msg_filename}-renamed
+increment_mtime ${MAIL_DIR}
 execute_expecting new "No new mail. Removed 1 message."
 
 printf " Renamed directory...\t\t"
 
-do_sleep
 generate_message [dir]=dir
 generate_message [dir]=dir
 generate_message [dir]=dir
 
 $NOTMUCH new > /dev/null
 
-do_sleep
 mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed
+increment_mtime ${MAIL_DIR}
 
 execute_expecting new "No new mail. Detected 3 file renames."
 
 printf " Deleted directory...\t\t"
 
-do_sleep
 rm -rf ${MAIL_DIR}/dir-renamed
+increment_mtime ${MAIL_DIR}
 
 execute_expecting new "No new mail. Removed 3 messages."
 
 printf " New directory (at end of list)... "
 
-do_sleep
 generate_message [dir]=zzz
 generate_message [dir]=zzz
 generate_message [dir]=zzz
@@ -198,8 +247,8 @@ execute_expecting new "Added 3 new messages to the database."
 
 printf " Deleted directory (end of list)... "
 
-do_sleep
 rm -rf ${MAIL_DIR}/zzz
+increment_mtime ${MAIL_DIR}
 
 execute_expecting new "No new mail. Removed 3 messages."
 
@@ -214,18 +263,16 @@ ln -s ${TEST_DIR}/actual_maildir ${MAIL_DIR}/symlink
 execute_expecting new "Added 1 new message to the database."
 
 printf " New symlink to a file...\t"
-do_sleep
 generate_message
 external_msg_filename=${TEST_DIR}/external/$(basename $gen_msg_filename)
 mkdir -p $(dirname $external_msg_filename)
 mv $gen_msg_filename $external_msg_filename
 ln -s $external_msg_filename $gen_msg_filename
-
+increment_mtime ${MAIL_DIR}
 execute_expecting new "Added 1 new message to the database."
 
 printf " New two-level directory...\t"
 
-do_sleep
 generate_message [dir]=two/levels
 generate_message [dir]=two/levels
 generate_message [dir]=two/levels
@@ -234,8 +281,8 @@ execute_expecting new "Added 3 new messages to the database."
 
 printf " Deleted two-level directory... "
 
-do_sleep
 rm -rf ${MAIL_DIR}/two
+increment_mtime ${MAIL_DIR}
 
 execute_expecting new "No new mail. Removed 3 messages."