notmuch-test: Eliminate sleeps to speed up test suite run

We were sleeping merely to ensure that our updates to the mail store
would result in the mtime of the appropriate directories being
updated. We make the test suite run faster by not sleeping, but
instead explicitly updating the mtime of the directory to a future
time with touch.

We're careful to ensure that the time is not merely in the future
compared to the current time, but also later than any previous update
to the same directory mtime.
This commit is contained in:
Carl Worth 2010-02-04 11:31:01 -08:00
parent a821ba5737
commit 5a4532860c

View file

@ -20,6 +20,15 @@ find_notmuch_binary ()
echo notmuch 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 # Generate a new message in the mail directory, with
# a unique message ID and subject. # a unique message ID and subject.
# #
@ -108,9 +117,8 @@ ${template[body]}
EOF EOF
} }
do_sleep () # Ensure that the mtime of the containing directory is updated
{ increment_mtime $(dirname ${gen_msg_filename})
sleep 1
} }
NOTMUCH_IGNORED_OUTPUT_REGEXP='^Processed [0-9]*( total)? file|Found [0-9]* total file' NOTMUCH_IGNORED_OUTPUT_REGEXP='^Processed [0-9]*( total)? file|Found [0-9]* total file'
@ -155,12 +163,10 @@ printf " No new messages...\t\t"
execute_expecting new "No new mail." execute_expecting new "No new mail."
printf " Single new message...\t\t" printf " Single new message...\t\t"
do_sleep
generate_message generate_message
execute_expecting new "Added 1 new message to the database." execute_expecting new "Added 1 new message to the database."
printf " Multiple new messages...\t" printf " Multiple new messages...\t"
do_sleep
generate_message generate_message
generate_message generate_message
execute_expecting new "Added 2 new messages to the database." execute_expecting new "Added 2 new messages to the database."
@ -191,51 +197,48 @@ generate_message
tmp_msg_filename=tmp/$gen_msg_filename tmp_msg_filename=tmp/$gen_msg_filename
mkdir -p $(dirname $tmp_msg_filename) mkdir -p $(dirname $tmp_msg_filename)
mv $gen_msg_filename $tmp_msg_filename mv $gen_msg_filename $tmp_msg_filename
do_sleep increment_mtime ${MAIL_DIR}
$NOTMUCH new > /dev/null $NOTMUCH new > /dev/null
do_sleep
mv $tmp_msg_filename $gen_msg_filename mv $tmp_msg_filename $gen_msg_filename
increment_mtime ${MAIL_DIR}
execute_expecting new "Added 1 new message to the database." execute_expecting new "Added 1 new message to the database."
printf " Renamed message...\t\t" printf " Renamed message...\t\t"
do_sleep
generate_message generate_message
$NOTMUCH new > /dev/null $NOTMUCH new > /dev/null
do_sleep
mv $gen_msg_filename ${gen_msg_filename}-renamed mv $gen_msg_filename ${gen_msg_filename}-renamed
increment_mtime ${MAIL_DIR}
execute_expecting new "No new mail. Detected 1 file rename." execute_expecting new "No new mail. Detected 1 file rename."
printf " Deleted message...\t\t" printf " Deleted message...\t\t"
do_sleep
rm ${gen_msg_filename}-renamed rm ${gen_msg_filename}-renamed
increment_mtime ${MAIL_DIR}
execute_expecting new "No new mail. Removed 1 message." execute_expecting new "No new mail. Removed 1 message."
printf " Renamed directory...\t\t" printf " Renamed directory...\t\t"
do_sleep
generate_message [dir]=dir generate_message [dir]=dir
generate_message [dir]=dir generate_message [dir]=dir
generate_message [dir]=dir generate_message [dir]=dir
$NOTMUCH new > /dev/null $NOTMUCH new > /dev/null
do_sleep
mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed
increment_mtime ${MAIL_DIR}
execute_expecting new "No new mail. Detected 3 file renames." execute_expecting new "No new mail. Detected 3 file renames."
printf " Deleted directory...\t\t" printf " Deleted directory...\t\t"
do_sleep
rm -rf ${MAIL_DIR}/dir-renamed rm -rf ${MAIL_DIR}/dir-renamed
increment_mtime ${MAIL_DIR}
execute_expecting new "No new mail. Removed 3 messages." execute_expecting new "No new mail. Removed 3 messages."
printf " New directory (at end of list)... " printf " New directory (at end of list)... "
do_sleep
generate_message [dir]=zzz generate_message [dir]=zzz
generate_message [dir]=zzz generate_message [dir]=zzz
generate_message [dir]=zzz generate_message [dir]=zzz
@ -244,8 +247,8 @@ execute_expecting new "Added 3 new messages to the database."
printf " Deleted directory (end of list)... " printf " Deleted directory (end of list)... "
do_sleep
rm -rf ${MAIL_DIR}/zzz rm -rf ${MAIL_DIR}/zzz
increment_mtime ${MAIL_DIR}
execute_expecting new "No new mail. Removed 3 messages." execute_expecting new "No new mail. Removed 3 messages."
@ -260,18 +263,16 @@ ln -s ${TEST_DIR}/actual_maildir ${MAIL_DIR}/symlink
execute_expecting new "Added 1 new message to the database." execute_expecting new "Added 1 new message to the database."
printf " New symlink to a file...\t" printf " New symlink to a file...\t"
do_sleep
generate_message generate_message
external_msg_filename=${TEST_DIR}/external/$(basename $gen_msg_filename) external_msg_filename=${TEST_DIR}/external/$(basename $gen_msg_filename)
mkdir -p $(dirname $external_msg_filename) mkdir -p $(dirname $external_msg_filename)
mv $gen_msg_filename $external_msg_filename mv $gen_msg_filename $external_msg_filename
ln -s $external_msg_filename $gen_msg_filename ln -s $external_msg_filename $gen_msg_filename
increment_mtime ${MAIL_DIR}
execute_expecting new "Added 1 new message to the database." execute_expecting new "Added 1 new message to the database."
printf " New two-level directory...\t" printf " New two-level directory...\t"
do_sleep
generate_message [dir]=two/levels generate_message [dir]=two/levels
generate_message [dir]=two/levels generate_message [dir]=two/levels
generate_message [dir]=two/levels generate_message [dir]=two/levels
@ -280,8 +281,8 @@ execute_expecting new "Added 3 new messages to the database."
printf " Deleted two-level directory... " printf " Deleted two-level directory... "
do_sleep
rm -rf ${MAIL_DIR}/two rm -rf ${MAIL_DIR}/two
increment_mtime ${MAIL_DIR}
execute_expecting new "No new mail. Removed 3 messages." execute_expecting new "No new mail. Removed 3 messages."