]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/run-missing-entries.c
tdb2: fix intermittent test fail.
[ccan] / ccan / tdb2 / test / run-missing-entries.c
1 /* Another test revealed that we lost an entry.  This reproduces it. */
2 #include <ccan/tdb2/tdb.c>
3 #include <ccan/tdb2/free.c>
4 #include <ccan/tdb2/lock.c>
5 #include <ccan/tdb2/io.c>
6 #include <ccan/tdb2/hash.c>
7 #include <ccan/tdb2/check.c>
8 #include <ccan/tdb2/traverse.c>
9 #include <ccan/tap/tap.h>
10 #include "logging.h"
11
12 #define NUM_RECORDS 1189
13
14 /* We use the same seed which we saw this failure on. */
15 static uint64_t failhash(const void *key, size_t len, uint64_t seed, void *p)
16 {
17         seed = 699537674708983027ULL;
18         return hash64_stable((const unsigned char *)key, len, seed);
19 }
20
21 int main(int argc, char *argv[])
22 {
23         int i;
24         struct tdb_context *tdb;
25         struct tdb_data key = { (unsigned char *)&i, sizeof(i) };
26         struct tdb_data data = { (unsigned char *)&i, sizeof(i) };
27         union tdb_attribute hattr = { .hash = { .base = { TDB_ATTRIBUTE_HASH },
28                                                 .hash_fn = failhash } };
29
30         hattr.base.next = &tap_log_attr;
31         plan_tests(1 + 2 * NUM_RECORDS + 1);
32
33         tdb = tdb_open("run-missing-entries.tdb", TDB_INTERNAL,
34                        O_RDWR|O_CREAT|O_TRUNC, 0600, &hattr);
35         ok1(tdb);
36         if (tdb) {
37                 for (i = 0; i < NUM_RECORDS; i++) {
38                         ok1(tdb_store(tdb, key, data, TDB_REPLACE) == 0);
39                         ok1(tdb_check(tdb, NULL, NULL) == 0);
40                 }
41                 tdb_close(tdb);
42         }
43
44         ok1(tap_log_messages == 0);
45         return exit_status();
46 }