]> git.notmuchmail.org Git - notmuch/blob - test/T620-lock.sh
build: drop support for xapian versions less than 1.4
[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 <unistd.h>
13 #include <stdlib.h>
14 #include <sys/wait.h>
15 #include <notmuch-test.h>
16
17 void
18 taggit (notmuch_database_t *db, const char *tag)
19 {
20     notmuch_message_t *message;
21
22     EXPECT0 (notmuch_database_find_message (db, "4EFC743A.3060609@april.org", &message));
23     if (message == NULL) {
24         fprintf (stderr, "unable to find message");
25         exit (1);
26     }
27
28     EXPECT0 (notmuch_message_add_tag (message, tag));
29     notmuch_message_destroy (message);
30 }
31
32 int
33 main (int argc, char **argv)
34 {
35     pid_t child;
36     const char *path = argv[1];
37
38     child = fork ();
39     if (child == -1) {
40         fprintf (stderr, "fork failed\n");
41         exit (1);
42     }
43
44     if (child == 0) {
45         notmuch_database_t *db2;
46
47         sleep (1);
48         EXPECT0 (notmuch_database_open (path, NOTMUCH_DATABASE_MODE_READ_WRITE, &db2));
49         taggit (db2, "child");
50         EXPECT0 (notmuch_database_close (db2));
51     } else {
52         notmuch_database_t *db;
53
54         EXPECT0 (notmuch_database_open (path, NOTMUCH_DATABASE_MODE_READ_WRITE, &db));
55         taggit (db, "parent");
56         sleep (2);
57         EXPECT0 (notmuch_database_close (db));
58         wait (NULL);
59     }
60 }
61
62 EOF
63 notmuch search --output=tags id:4EFC743A.3060609@april.org >> OUTPUT
64 cat <<'EOF' >EXPECTED
65 == stdout ==
66 == stderr ==
67 child
68 inbox
69 parent
70 unread
71 EOF
72 if [ $NOTMUCH_HAVE_XAPIAN_DB_RETRY_LOCK -ne 1 ]; then
73     test_subtest_known_broken
74 fi
75 test_expect_equal_file EXPECTED OUTPUT
76
77 test_done