2017-02-25 03:57:40 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
test_description="DatabaseModifiedError handling"
|
2017-09-25 22:38:19 +02:00
|
|
|
. $(dirname "$0")/test-lib.sh || exit 1
|
2017-02-25 03:57:40 +01:00
|
|
|
|
|
|
|
# add enough messages to trigger the exception
|
|
|
|
add_email_corpus
|
|
|
|
|
|
|
|
test_begin_subtest "catching DatabaseModifiedError in _notmuch_message_ensure_metadata"
|
|
|
|
# it seems to need to be an early document to trigger the exception
|
|
|
|
first_id=$(notmuch search --output=messages '*'| head -1 | sed s/^id://)
|
|
|
|
|
|
|
|
test_C ${MAIL_DIR} <<EOF
|
|
|
|
#include <notmuch-test.h>
|
2021-10-28 14:32:34 +02:00
|
|
|
|
2017-02-25 03:57:40 +01:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
const char *path = argv[1];
|
|
|
|
|
|
|
|
notmuch_database_t *rw_db, *ro_db;
|
|
|
|
notmuch_messages_t *messages;
|
|
|
|
notmuch_message_t *message, *ro_message;
|
|
|
|
notmuch_query_t *query;
|
|
|
|
notmuch_tags_t *tags;
|
2017-02-26 13:16:45 +01:00
|
|
|
int i;
|
2017-02-25 03:57:40 +01:00
|
|
|
|
|
|
|
EXPECT0 (notmuch_database_open (path, NOTMUCH_DATABASE_MODE_READ_ONLY, &ro_db));
|
|
|
|
assert(ro_db);
|
|
|
|
|
|
|
|
EXPECT0 (notmuch_database_find_message (ro_db, "${first_id}", &ro_message));
|
|
|
|
assert(ro_message);
|
|
|
|
|
|
|
|
EXPECT0 (notmuch_database_open (path, NOTMUCH_DATABASE_MODE_READ_WRITE, &rw_db));
|
|
|
|
query = notmuch_query_create(rw_db, "");
|
2017-02-26 22:21:32 +01:00
|
|
|
EXPECT0 (notmuch_query_search_messages (query, &messages));
|
2017-02-25 03:57:40 +01:00
|
|
|
|
2017-02-26 13:16:45 +01:00
|
|
|
for (;
|
2017-02-25 03:57:40 +01:00
|
|
|
notmuch_messages_valid (messages);
|
2017-02-26 13:16:45 +01:00
|
|
|
notmuch_messages_move_to_next (messages)) {
|
2017-02-25 03:57:40 +01:00
|
|
|
message = notmuch_messages_get (messages);
|
2017-02-26 13:16:45 +01:00
|
|
|
for (i=0; i<200; i++) {
|
2017-02-25 03:57:40 +01:00
|
|
|
char *tag_str = talloc_asprintf(rw_db, "%d", i);
|
|
|
|
EXPECT0 (notmuch_message_add_tag (message, tag_str));
|
|
|
|
talloc_free (tag_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
notmuch_database_close (rw_db);
|
|
|
|
|
|
|
|
tags = notmuch_message_get_tags (ro_message);
|
|
|
|
if (tags)
|
|
|
|
printf("SUCCESS\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat <<'EOF' >EXPECTED
|
|
|
|
== stdout ==
|
|
|
|
SUCCESS
|
|
|
|
== stderr ==
|
|
|
|
EOF
|
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
|
|
|
|
|
|
|
test_done
|