]> git.notmuchmail.org Git - notmuch/blob - test/T620-lock.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / T620-lock.sh
1 #!/usr/bin/env bash
2 test_description="locking"
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 add_email_corpus
6
7 test_begin_subtest "blocking open"
8 if [ $NOTMUCH_HAVE_XAPIAN_DB_RETRY_LOCK -ne 1 ]; then
9     test_subtest_known_broken
10 fi
11 test_C ${MAIL_DIR} <<'EOF'
12 #include <notmuch-test.h>
13
14 void
15 taggit (notmuch_database_t *db, const char *tag)
16 {
17     notmuch_message_t *message;
18
19     EXPECT0 (notmuch_database_find_message (db, "4EFC743A.3060609@april.org", &message));
20     if (message == NULL) {
21         fprintf (stderr, "unable to find message");
22         exit (1);
23     }
24
25     EXPECT0 (notmuch_message_add_tag (message, tag));
26     notmuch_message_destroy (message);
27 }
28
29 int
30 main (int argc, char **argv)
31 {
32     pid_t child;
33     const char *path = argv[1];
34
35     child = fork ();
36     if (child == -1) {
37         fprintf (stderr, "fork failed\n");
38         exit (1);
39     }
40
41     if (child == 0) {
42         notmuch_database_t *db2;
43         char* msg = NULL;
44
45         sleep (1);
46
47         EXPECT0(notmuch_database_open_with_config (argv[1],
48                                                    NOTMUCH_DATABASE_MODE_READ_WRITE,
49                                                    "", NULL, &db2, &msg));
50         if (msg) fputs (msg, stderr);
51
52         taggit (db2, "child");
53         EXPECT0 (notmuch_database_close (db2));
54     } else {
55         notmuch_database_t *db;
56         char* msg = NULL;
57
58         EXPECT0(notmuch_database_open_with_config (argv[1],
59                                                    NOTMUCH_DATABASE_MODE_READ_WRITE,
60                                                    "", NULL, &db, &msg));
61         if (msg) fputs (msg, stderr);
62         taggit (db, "parent");
63         sleep (2);
64         EXPECT0 (notmuch_database_close (db));
65         wait (NULL);
66     }
67 }
68
69 EOF
70 notmuch search --output=tags id:4EFC743A.3060609@april.org >> OUTPUT
71 cat <<'EOF' >EXPECTED
72 == stdout ==
73 == stderr ==
74 child
75 inbox
76 parent
77 unread
78 EOF
79 if [ $NOTMUCH_HAVE_XAPIAN_DB_RETRY_LOCK -ne 1 ]; then
80     test_subtest_known_broken
81 fi
82 test_expect_equal_file EXPECTED OUTPUT
83
84 test_done