1 Return-Path: <davrieb@liegesta.at>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 3DAD5429E29
\r
6 for <notmuch@notmuchmail.org>; Sun, 6 Nov 2011 04:23:16 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id wxjSVk2ZQQrN for <notmuch@notmuchmail.org>;
\r
16 Sun, 6 Nov 2011 04:23:13 -0800 (PST)
\r
17 Received: from plum.liegesta.at (plum.liegesta.at [83.169.17.237])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 0560A429E21
\r
19 for <notmuch@notmuchmail.org>; Sun, 6 Nov 2011 04:23:12 -0800 (PST)
\r
20 Received: from ambiguous-mid.liegesta.at (mk046207255168.a1.net
\r
21 [46.207.255.168]) (Authenticated sender: davrieb)
\r
22 by plum.liegesta.at (Postfix) with ESMTPA id AC10A27B825A;
\r
23 Sun, 6 Nov 2011 13:23:09 +0100 (CET)
\r
24 Received: by ambiguous-mid.liegesta.at (Postfix, from userid 1000)
\r
25 id 94ECE1FF30; Sun, 6 Nov 2011 12:23:07 +0100 (CET)
\r
26 From: David Riebenbauer <davrieb@liegesta.at>
\r
27 To: Notmuch Mailing List <notmuch@notmuchmail.org>
\r
28 Subject: [PATCH 2/3] notmuch-deliver: test wait for database to become
\r
30 Date: Sun, 6 Nov 2011 12:23:03 +0100
\r
31 Message-Id: <1320578584-6642-3-git-send-email-davrieb@liegesta.at>
\r
32 X-Mailer: git-send-email 1.7.7.1
\r
33 In-Reply-To: <1320578584-6642-1-git-send-email-davrieb@liegesta.at>
\r
34 References: <1320578584-6642-1-git-send-email-davrieb@liegesta.at>
\r
35 X-BeenThere: notmuch@notmuchmail.org
\r
36 X-Mailman-Version: 2.1.13
\r
38 List-Id: "Use and development of the notmuch mail system."
\r
39 <notmuch.notmuchmail.org>
\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
43 List-Post: <mailto:notmuch@notmuchmail.org>
\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
47 X-List-Received-Date: Sun, 06 Nov 2011 12:23:17 -0000
\r
49 Check if notmuch-deliver really waits for the database to become
\r
52 This is done via a test program that locks the notmuch database, and then
\r
53 spawns the program to be tested. The test can be run with make check.
\r
55 contrib/notmuch-deliver/.gitignore | 2 +
\r
56 contrib/notmuch-deliver/Makefile.am | 2 +-
\r
57 contrib/notmuch-deliver/configure.ac | 1 +
\r
58 contrib/notmuch-deliver/test/Makefile.am | 26 ++++
\r
59 contrib/notmuch-deliver/test/nm-test.sh | 9 ++
\r
60 contrib/notmuch-deliver/test/nm-testconfig | 12 ++
\r
61 contrib/notmuch-deliver/test/notmuch-lock.c | 167 +++++++++++++++++++++++++++
\r
62 contrib/notmuch-deliver/test/testmail | 7 +
\r
63 8 files changed, 225 insertions(+), 1 deletions(-)
\r
64 create mode 100644 contrib/notmuch-deliver/test/Makefile.am
\r
65 create mode 100755 contrib/notmuch-deliver/test/nm-test.sh
\r
66 create mode 100644 contrib/notmuch-deliver/test/nm-testconfig
\r
67 create mode 100644 contrib/notmuch-deliver/test/notmuch-lock.c
\r
68 create mode 100644 contrib/notmuch-deliver/test/testmail
\r
70 diff --git a/contrib/notmuch-deliver/.gitignore b/contrib/notmuch-deliver/.gitignore
\r
71 index 6971ef2..91da18b 100644
\r
72 --- a/contrib/notmuch-deliver/.gitignore
\r
73 +++ b/contrib/notmuch-deliver/.gitignore
\r
74 @@ -40,3 +40,5 @@ m4/lt*.m4
\r
76 maildrop/numlib/config.h
\r
80 diff --git a/contrib/notmuch-deliver/Makefile.am b/contrib/notmuch-deliver/Makefile.am
\r
81 index 365558a..4392771 100644
\r
82 --- a/contrib/notmuch-deliver/Makefile.am
\r
83 +++ b/contrib/notmuch-deliver/Makefile.am
\r
84 @@ -3,6 +3,6 @@ MAINTAINERCLEANFILES= Makefile.in configure aclocal.m4 \
\r
85 config.h config.h.in INSTALL
\r
86 ACLOCAL_AMFLAGS= -I m4
\r
87 AUTOMAKE_OPTIONS= dist-bzip2 no-dist-gzip std-options foreign
\r
88 -SUBDIRS= maildrop/numlib src .
\r
89 +SUBDIRS= maildrop/numlib src test .
\r
91 doc_DATA= README.mkd
\r
92 diff --git a/contrib/notmuch-deliver/configure.ac b/contrib/notmuch-deliver/configure.ac
\r
93 index 4deb658..693923f 100644
\r
94 --- a/contrib/notmuch-deliver/configure.ac
\r
95 +++ b/contrib/notmuch-deliver/configure.ac
\r
96 @@ -152,5 +152,6 @@ AC_OUTPUT(
\r
98 maildrop/numlib/Makefile
\r
103 diff --git a/contrib/notmuch-deliver/test/Makefile.am b/contrib/notmuch-deliver/test/Makefile.am
\r
104 new file mode 100644
\r
105 index 0000000..dfa0b45
\r
107 +++ b/contrib/notmuch-deliver/test/Makefile.am
\r
109 +DEFS+= -DGITHEAD=\"$(GITHEAD)\"
\r
110 +AM_CFLAGS= @NOTMUCH_DELIVER_CFLAGS@ $(glib_CFLAGS)
\r
112 +check_PROGRAMS= notmuch-lock
\r
114 +notmuch_lock_SOURCES= notmuch-lock.c
\r
115 +notmuch_lock_LDADD= $(glib_LIBS)
\r
117 +TESTS = nm-test.sh
\r
119 +nm-test.sh: notmuch-lock \
\r
120 + nm-test-mail/INBOX/cur \
\r
121 + nm-test-mail/INBOX/new \
\r
122 + nm-test-mail/INBOX/tmp
\r
124 +nm-test-mail/INBOX/cur:
\r
127 +nm-test-mail/INBOX/new:
\r
130 +nm-test-mail/INBOX/tmp:
\r
134 + rm -rf nm-test-mail
\r
135 diff --git a/contrib/notmuch-deliver/test/nm-test.sh b/contrib/notmuch-deliver/test/nm-test.sh
\r
136 new file mode 100755
\r
137 index 0000000..6113211
\r
139 +++ b/contrib/notmuch-deliver/test/nm-test.sh
\r
145 +export NOTMUCH_CONFIG=./nm-testconfig
\r
149 +./notmuch-lock -s 1000000 -- ../src/notmuch-deliver -v INBOX < testmail
\r
150 diff --git a/contrib/notmuch-deliver/test/nm-testconfig b/contrib/notmuch-deliver/test/nm-testconfig
\r
151 new file mode 100644
\r
152 index 0000000..b94e8d0
\r
154 +++ b/contrib/notmuch-deliver/test/nm-testconfig
\r
157 +path=./nm-test-mail
\r
161 +primary_email=notmuc@example.com
\r
164 +tags=unread;inbox;
\r
167 +synchronize_flags=true
\r
168 diff --git a/contrib/notmuch-deliver/test/notmuch-lock.c b/contrib/notmuch-deliver/test/notmuch-lock.c
\r
169 new file mode 100644
\r
170 index 0000000..2303843
\r
172 +++ b/contrib/notmuch-deliver/test/notmuch-lock.c
\r
174 +/* vim: set cino=t0 fo=croql sw=4 ts=4 sts=0 noet cin fdm=syntax nolist : */
\r
176 +#include <stdlib.h>
\r
177 +#include <unistd.h>
\r
178 +#include <sys/types.h>
\r
179 +#include <sys/wait.h>
\r
183 +#include <notmuch.h>
\r
186 +#define MIN_UWAIT 1000 // 1 millisecond
\r
187 +#define MAX_UWAIT 600000000 // 10 minutes
\r
191 +static gint sleep_option = -1;
\r
192 +static GOptionEntry entries[] = {
\r
193 + { "sleep", 's', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &sleep_option,
\r
194 + "Sleep for N microseconds, while holding the lock to the database", "N" },
\r
195 + {NULL, 0, 0, 0, NULL, NULL, NULL},
\r
201 +load_keyfile(const gchar *path, gchar **db_path, gchar ***tags)
\r
206 + fd = g_key_file_new();
\r
208 + if (!g_key_file_load_from_file(fd, path, G_KEY_FILE_NONE,
\r
210 + g_printerr("Failed to parse `%s': %s", path,
\r
212 + g_error_free(error);
\r
213 + g_key_file_free(fd);
\r
217 + *db_path = g_key_file_get_string(fd, "database",
\r
219 + if (*db_path == NULL) {
\r
220 + g_critical("Failed to parse database.path from `%s': %s", path,
\r
222 + g_error_free(error);
\r
223 + g_key_file_free(fd);
\r
227 + *tags = g_key_file_get_string_list(fd, "new",
\r
228 + "tags", NULL, NULL);
\r
230 + g_key_file_free(fd);
\r
239 + gchar *conf_path, *db_path;
\r
241 + // Get location of notmuch config
\r
242 + if (g_getenv("NOTMUCH_CONFIG"))
\r
243 + conf_path = g_strdup(g_getenv("NOTMUCH_CONFIG"));
\r
244 + else if (g_getenv("HOME"))
\r
245 + conf_path = g_build_filename(g_getenv("HOME"),
\r
246 + ".notmuch-config", NULL);
\r
248 + g_critical("Neither NOTMUCH_CONFIG nor HOME set");
\r
252 + // Get location of notmuch database
\r
253 + gchar **conf_tags = NULL;
\r
254 + g_print("Parsing configuration from `%s'\n", conf_path);
\r
255 + if (!load_keyfile(conf_path, &db_path, &conf_tags)) {
\r
256 + g_free(conf_path);
\r
260 + g_free(conf_path);
\r
266 +main(int argc, char *argv[])
\r
269 + gint32 sleep_time = 0;
\r
270 + notmuch_database_t *db;
\r
271 + GError *error = NULL;
\r
272 + GOptionContext *context;
\r
274 + // parse command line options
\r
275 + gboolean option_parse_success = FALSE;
\r
276 + context = g_option_context_new( "COMMAND [ARGS...]");
\r
277 + g_option_context_add_main_entries(context, entries, NULL);
\r
278 + g_option_context_set_summary(context,
\r
279 + "Utility to test behaviour of programs while the notmuch database is locked");
\r
280 + option_parse_success = g_option_context_parse(context, &argc, &argv, &error);
\r
281 + g_option_context_free(context);
\r
282 + if (! option_parse_success) {
\r
283 + g_printerr("option parsing failed: %s\n", error->message);
\r
284 + return EXIT_FAILURE;
\r
287 + // Check new program args
\r
288 + if ((argc - 1) <= 0) {
\r
289 + g_printerr("no command supplied\n");
\r
290 + return EXIT_FAILURE;
\r
292 + char **new_argv = argv + 1;
\r
293 + if (g_strcmp0(new_argv[0], "--") == 0)
\r
296 + // Get notmuch database path
\r
297 + db_path = get_db_path();
\r
298 + if (db_path == NULL)
\r
299 + return EXIT_FAILURE;
\r
301 + // Open notmuch database
\r
302 + g_printerr("Opening notmuch database `%s'\n", db_path);
\r
303 + db = notmuch_database_open(db_path, NOTMUCH_DATABASE_MODE_READ_WRITE);
\r
306 + return EXIT_FAILURE;
\r
308 + gboolean spawn_success = FALSE;
\r
309 + GPid child_pid = 0;
\r
310 + spawn_success = g_spawn_async(
\r
311 + g_get_current_dir(),
\r
314 + G_SPAWN_SEARCH_PATH | G_SPAWN_CHILD_INHERITS_STDIN | G_SPAWN_DO_NOT_REAP_CHILD,
\r
320 + if (!spawn_success) {
\r
321 + g_printerr("faild to spawn child\n");
\r
324 + // Sleep for some time
\r
325 + if (sleep_option >= 0) {
\r
326 + sleep_time = sleep_option;
\r
328 + sleep_time = g_random_int_range(MIN_UWAIT, MAX_UWAIT);
\r
330 + g_printerr("Sleeping for %f secs\n", ((double)sleep_time)/(1000*1000));
\r
331 + usleep(sleep_time);
\r
333 + // Close database again
\r
334 + notmuch_database_close(db);
\r
336 + int child_status = 0;
\r
337 + child_pid = waitpid(child_pid, &child_status, 0);
\r
339 + return WEXITSTATUS(child_status);
\r
341 diff --git a/contrib/notmuch-deliver/test/testmail b/contrib/notmuch-deliver/test/testmail
\r
342 new file mode 100644
\r
343 index 0000000..264518d
\r
345 +++ b/contrib/notmuch-deliver/test/testmail
\r
347 +From: test@example.com
\r
348 +To: test@example.com
\r
350 +Message-Id: <20111022050326.653C3201BF@example.com>
\r
351 +Date: Sat, 22 Oct 2011 07:03:26 +0200 (CEST)
\r