]> git.notmuchmail.org Git - notmuch/blob - test/T640-database-modified.sh
smime: Identify encrypted S/MIME parts during indexing
[notmuch] / test / T640-database-modified.sh
1 #!/usr/bin/env bash
2 test_description="DatabaseModifiedError handling"
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 # add enough messages to trigger the exception
6 add_email_corpus
7
8 test_begin_subtest "catching DatabaseModifiedError in _notmuch_message_ensure_metadata"
9 # it seems to need to be an early document to trigger the exception
10 first_id=$(notmuch search --output=messages '*'| head -1 | sed s/^id://)
11
12 test_C ${MAIL_DIR} <<EOF
13 #include <unistd.h>
14 #include <stdlib.h>
15 #include <notmuch-test.h>
16 #include <talloc.h>
17 #include <assert.h>
18 int
19 main (int argc, char **argv)
20 {
21     const char *path = argv[1];
22
23     notmuch_database_t *rw_db, *ro_db;
24     notmuch_messages_t *messages;
25     notmuch_message_t *message, *ro_message;
26     notmuch_query_t *query;
27     notmuch_tags_t *tags;
28     int i;
29
30     EXPECT0 (notmuch_database_open (path, NOTMUCH_DATABASE_MODE_READ_ONLY, &ro_db));
31     assert(ro_db);
32
33     EXPECT0 (notmuch_database_find_message (ro_db, "${first_id}", &ro_message));
34     assert(ro_message);
35
36     EXPECT0 (notmuch_database_open (path, NOTMUCH_DATABASE_MODE_READ_WRITE, &rw_db));
37     query = notmuch_query_create(rw_db, "");
38     EXPECT0 (notmuch_query_search_messages (query, &messages));
39
40     for (;
41          notmuch_messages_valid (messages);
42          notmuch_messages_move_to_next (messages)) {
43         message = notmuch_messages_get (messages);
44         for (i=0; i<200; i++) {
45             char *tag_str = talloc_asprintf(rw_db, "%d", i);
46             EXPECT0 (notmuch_message_add_tag (message, tag_str));
47             talloc_free (tag_str);
48         }
49     }
50
51     notmuch_database_close (rw_db);
52
53     tags = notmuch_message_get_tags (ro_message);
54     if (tags)
55         printf("SUCCESS\n");
56     return 0;
57 }
58 EOF
59
60 cat <<'EOF' >EXPECTED
61 == stdout ==
62 SUCCESS
63 == stderr ==
64 EOF
65 test_expect_equal_file EXPECTED OUTPUT
66
67 test_done