]> git.cworth.org Git - notmuch/blob - test/T620-lock.sh
Merge tag 'debian/0.34.2-1'
[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
44         sleep (1);
45         EXPECT0 (notmuch_database_open (path, NOTMUCH_DATABASE_MODE_READ_WRITE, &db2));
46         taggit (db2, "child");
47         EXPECT0 (notmuch_database_close (db2));
48     } else {
49         notmuch_database_t *db;
50
51         EXPECT0 (notmuch_database_open (path, NOTMUCH_DATABASE_MODE_READ_WRITE, &db));
52         taggit (db, "parent");
53         sleep (2);
54         EXPECT0 (notmuch_database_close (db));
55         wait (NULL);
56     }
57 }
58
59 EOF
60 notmuch search --output=tags id:4EFC743A.3060609@april.org >> OUTPUT
61 cat <<'EOF' >EXPECTED
62 == stdout ==
63 == stderr ==
64 child
65 inbox
66 parent
67 unread
68 EOF
69 if [ $NOTMUCH_HAVE_XAPIAN_DB_RETRY_LOCK -ne 1 ]; then
70     test_subtest_known_broken
71 fi
72 test_expect_equal_file EXPECTED OUTPUT
73
74 test_done