diff options
author | Andrew Tridgell <tridge@samba.org> | 2007-04-18 12:39:12 +1000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2007-04-18 12:39:12 +1000 |
commit | f57793077f538fa659807ad4bad4c1927ca9c5c0 (patch) | |
tree | 342074595e5815840604ac4af8efdca0cbd3a60c | |
parent | 7a02b09b01363fdf7e12f10eb46f18492823a2a9 (diff) | |
parent | 1739dbd31760d906e89326d700f108e0c7669721 (diff) | |
download | samba-f57793077f538fa659807ad4bad4c1927ca9c5c0.tar.gz samba-f57793077f538fa659807ad4bad4c1927ca9c5c0.tar.xz samba-f57793077f538fa659807ad4bad4c1927ca9c5c0.zip |
merge fetch1 changes from ronnie
(This used to be ctdb commit 906419acf121ea93661f91bde65cdcd890f70e63)
-rw-r--r-- | ctdb/tests/ctdb_fetch1.c | 58 |
1 files changed, 49 insertions, 9 deletions
diff --git a/ctdb/tests/ctdb_fetch1.c b/ctdb/tests/ctdb_fetch1.c index b362eb1510..b92e7fcda3 100644 --- a/ctdb/tests/ctdb_fetch1.c +++ b/ctdb/tests/ctdb_fetch1.c @@ -25,6 +25,7 @@ #include "ctdb.h" #include "ctdb_private.h" #include "cmdline.h" +#include <sys/time.h> #define PARENT_SRVID 0 #define CHILD1_SRVID 1 @@ -32,6 +33,20 @@ int num_msg=0; +static struct timeval tp1,tp2; + +static void start_timer(void) +{ + gettimeofday(&tp1,NULL); +} + +static double end_timer(void) +{ + gettimeofday(&tp2,NULL); + return (tp2.tv_sec + (tp2.tv_usec*1.0e-6)) - + (tp1.tv_sec + (tp1.tv_usec*1.0e-6)); +} + static void message_handler(struct ctdb_context *ctdb, uint32_t srvid, TDB_DATA data, void *private_data) { @@ -113,17 +128,23 @@ void child(int srvid, struct event_context *ev, struct ctdb_context *ctdb, struc /* fetch and lock the record */ key.dptr = discard_const("Record"); key.dsize = strlen((const char *)key.dptr)+1; + printf("client:%d fetching the record\n",srvid); h = ctdb_fetch_lock(ctdb_db, ctdb_db, key, &data2); + printf("client:%d the record is fetched and locked\n",srvid); if (h == NULL) { printf("client: ctdb_fetch_lock() failed\n"); exit(1); } ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), PARENT_SRVID, data); - talloc_free(h); - while (1) { + /* wait until parent tells us to release the lock */ + while (num_msg==1) { event_loop_once(ev); } + + printf("child %d terminating\n",srvid); + exit(10); + } /* @@ -227,29 +248,48 @@ int main(int argc, const char *argv[]) */ data.dptr=discard_const("dummy message"); data.dsize=strlen((const char *)data.dptr)+1; - printf("Send message to child 1 to fetch_lock the record\n"); ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD1_SRVID, data); /* wait for child 1 to complete fetching and locking the record */ while (num_msg!=3) { event_loop_once(ev); } - printf("Child 1 has fetched and locked the record\n"); /* now tell child 2 to fetch and lock the same record */ - printf("Send message to child 2 to fetch_lock the record\n"); ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD2_SRVID, data); - /* wait for child 2 to complete fetching and locking the record */ - while (num_msg!=4) { + /* wait a while for child 2 to complete fetching and locking the + record, this should fail since the record is already locked + by the first child */ + start_timer(); + while ( (end_timer() < 1.0) && (num_msg!=4) ) { event_loop_once(ev); } - printf("Child 2 has fetched and locked the record\n"); + if (num_msg!=4) { + printf("Child 2 did not get the lock since it is held by client 1:SUCCESS\n"); + } else { + printf("Child 2 did get the lock:FAILURE\n"); + exit(10); + } + + /* send message to child 1 to terminate, which should let child 2 + get the lock. + */ + ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD1_SRVID, data); - while (1) { + /* wait for a final message from child 2 it has received the lock + which indicates success */ + while (num_msg!=4) { event_loop_once(ev); } + printf("child 2 aquired the lock after child 1 terminated:SUCCESS\n"); + + /* send a message to child 2 to tell it to terminate too */ + ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD2_SRVID, data); + + + printf("Test was SUCCESSFUL\n"); /* shut it down */ talloc_free(ctdb); |