Mercurial > dovecot > core-2.2
annotate src/lib-fs/fs-test-async.c @ 22656:1789bf2a1e01
director: Make sure HOST-RESET-USERS isn't used with max_moving_users=0
The reset command would just hang in that case. doveadm would never have
sent this, so this is just an extra sanity check.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Sun, 05 Nov 2017 23:51:56 +0200 |
parents | 2e2563132d5f |
children | cb108f786fb4 |
rev | line source |
---|---|
21390
2e2563132d5f
Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21389
diff
changeset
|
1 /* Copyright (c) 2016-2017 Dovecot authors, see the included COPYING file */ |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
2 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
4 #include "str.h" |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
5 #include "ostream.h" |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
6 #include "fs-test.h" |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
7 #include "test-common.h" |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
8 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
9 static void test_fs_async_write(const char *test_name, struct fs *fs) |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
10 { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
11 struct fs_file *file; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
12 struct test_fs_file *test_file; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
13 struct ostream *output; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
14 unsigned int i; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
15 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
16 test_begin(t_strdup_printf("%s: async write", test_name)); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
17 for (i = 0; i < 3; i++) { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
18 file = fs_file_init(fs, "foo", FS_OPEN_MODE_REPLACE | |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
19 FS_OPEN_FLAG_ASYNC); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
20 output = fs_write_stream(file); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
21 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
22 o_stream_nsend_str(output, "12345"); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
23 if (i < 2) { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
24 test_assert(fs_write_stream_finish(file, &output) == 0); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
25 test_assert(output == NULL); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
26 test_assert(fs_write_stream_finish_async(file) == 0); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
27 } |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
28 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
29 test_file = test_fs_file_get(fs, "foo"); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
30 test_file->wait_async = FALSE; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
31 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
32 switch (i) { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
33 case 0: |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
34 test_assert(fs_write_stream_finish_async(file) > 0); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
35 test_assert(test_file->contents->used > 0); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
36 break; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
37 case 1: |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
38 test_file->io_failure = TRUE; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
39 test_assert(fs_write_stream_finish_async(file) < 0); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
40 test_assert(test_file->contents->used == 0); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
41 break; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
42 case 2: |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
43 fs_write_stream_abort(file, &output); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
44 test_assert(test_file->contents->used == 0); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
45 break; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
46 } |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
47 fs_file_deinit(&file); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
48 } |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
49 test_end(); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
50 } |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
51 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
52 static void test_fs_async_copy(const char *test_name, struct fs *fs) |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
53 { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
54 struct fs_file *src, *dest; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
55 struct test_fs_file *test_file; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
56 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
57 test_begin(t_strdup_printf("%s: async copy", test_name)); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
58 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
59 src = fs_file_init(fs, "foo", FS_OPEN_MODE_REPLACE); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
60 test_assert(fs_write(src, "source", 6) == 0); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
61 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
62 dest = fs_file_init(fs, "bar", FS_OPEN_MODE_REPLACE | |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
63 FS_OPEN_FLAG_ASYNC); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
64 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
65 test_assert(fs_copy(src, dest) == -1 && errno == EAGAIN); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
66 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
67 test_file = test_fs_file_get(fs, "bar"); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
68 test_file->wait_async = FALSE; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
69 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
70 test_assert(fs_copy_finish_async(dest) == 0); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
71 test_assert(test_file->contents->used > 0); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
72 fs_file_deinit(&dest); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
73 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
74 fs_file_deinit(&src); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
75 test_end(); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
76 } |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
77 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
78 void test_fs_async(const char *test_name, enum fs_properties properties, |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
79 const char *driver, const char *args) |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
80 { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
81 struct fs_settings fs_set; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
82 struct fs *fs; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
83 struct test_fs *test_fs; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
84 const char *error; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
85 |
21389
59437f8764c6
global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
20240
diff
changeset
|
86 i_zero(&fs_set); |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
87 if (fs_init(driver, args, &fs_set, &fs, &error) < 0) |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
88 i_fatal("fs_init() failed: %s", error); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
89 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
90 test_fs = test_fs_get(fs); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
91 test_fs->properties = properties; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
92 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
93 test_fs_async_write(test_name, fs); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
94 test_fs_async_copy(test_name, fs); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
95 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
96 fs_deinit(&fs); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
97 } |