X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb%2Ftest%2Frun-traverse-in-transaction.c;h=c7079cf6828eb39deb3665950c5913684f6a0b2c;hp=e8d6819a93be99f3c2c52632e6deac8b488e3859;hb=a153d09b979182e8586d4501ea687bcdd466dabc;hpb=f83c45bf4ccd00d81498c30cf7455a9813cf104b diff --git a/ccan/tdb/test/run-traverse-in-transaction.c b/ccan/tdb/test/run-traverse-in-transaction.c index e8d6819a..c7079cf6 100644 --- a/ccan/tdb/test/run-traverse-in-transaction.c +++ b/ccan/tdb/test/run-traverse-in-transaction.c @@ -1,20 +1,24 @@ #define _XOPEN_SOURCE 500 -#include "tdb/tdb.h" -#include "tdb/io.c" -#include "tdb/tdb.c" -#include "tdb/lock.c" -#include "tdb/freelist.c" -#include "tdb/traverse.c" -#include "tdb/transaction.c" -#include "tdb/error.c" -#include "tdb/open.c" -#include "tap/tap.h" +#include "lock-tracking.h" +#define fcntl fcntl_with_lockcheck +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#undef fcntl_with_lockcheck #include #include #include -#include "external-transaction.h" +#include "external-agent.h" -static int agent; +static struct agent *agent; static bool correct_key(TDB_DATA key) { @@ -43,11 +47,11 @@ int main(int argc, char *argv[]) plan_tests(13); agent = prepare_external_agent(); - if (agent < 0) + if (!agent) err(1, "preparing agent"); - tdb = tdb_open("/tmp/test2.tdb", 1024, TDB_CLEAR_IF_FIRST, - O_CREAT|O_TRUNC|O_RDWR, 0600); + tdb = tdb_open("run-traverse-in-transaction.tdb", + 1024, TDB_CLEAR_IF_FIRST, O_CREAT|O_TRUNC|O_RDWR, 0600); ok1(tdb); key.dsize = strlen("hi"); @@ -57,21 +61,25 @@ int main(int argc, char *argv[]) ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0); - ok1(external_agent_transaction(agent, tdb_name(tdb))); + ok1(external_agent_operation(agent, OPEN, tdb_name(tdb)) == SUCCESS); ok1(tdb_transaction_start(tdb) == 0); - ok1(!external_agent_transaction(agent, tdb_name(tdb))); + ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb)) + == WOULD_HAVE_BLOCKED); tdb_traverse(tdb, traverse, NULL); /* That should *not* release the transaction lock! */ - ok1(!external_agent_transaction(agent, tdb_name(tdb))); + ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb)) + == WOULD_HAVE_BLOCKED); tdb_traverse_read(tdb, traverse, NULL); /* That should *not* release the transaction lock! */ - ok1(!external_agent_transaction(agent, tdb_name(tdb))); + ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb)) + == WOULD_HAVE_BLOCKED); ok1(tdb_transaction_commit(tdb) == 0); /* Now we should be fine. */ - ok1(external_agent_transaction(agent, tdb_name(tdb))); + ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb)) + == SUCCESS); tdb_close(tdb);