From: Adam Dickmeiss Date: Tue, 30 Mar 2010 13:45:15 +0000 (+0200) Subject: yaz-ztest: complete database delay arguments X-Git-Tag: v4.0.3~11 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=f3027244f210c7014b46dc564e868bbdf10560e2;p=yaz-moved-to-github.git yaz-ztest: complete database delay arguments Fixed and random delays for yaz-ztest may be given as database options. Documented in code and man page for yaz-ztest. --- diff --git a/doc/yaz-ztest-man.xml b/doc/yaz-ztest-man.xml index 965c15a..14f743c 100644 --- a/doc/yaz-ztest-man.xml +++ b/doc/yaz-ztest-man.xml @@ -58,6 +58,52 @@ OPTIONS &gfs-options; + + TESTING + + yaz-ztest normally returns a random hit count between + 0 and 24. However, if a query term includes leading digits, then the + integer value of that term is used as hit count. This allows testers + to return any number of hits. yaz-ztest includes + 24 MARC records for testing. Hit counts exceeding 24 will make + yaz-ztest return the same record batch over and over.. + So record at position 1, 25, 49, etc .. are equivalent. + + + The following databases are honored by yaz-ztest: + Default, slow + and db.* (all databases with prefix "db"). Any + other database will make yaz-ztest return diagnostic + 109: "Database unavailable". + + + Options for search may be included in the form or URL get arguments + included as part of the Z39.50 database name. The following + database options are present: search-delay, + present-delay, fetch-delay + and seed. + + + The former, delay type options, specify + a fake delay (sleep) that yaz-ztest will perform + when searching, presenting, fetching records respectively. + The value of the delay may either be a fixed floating point + value which specifies the delay in seconds. + Alternatively the value may be given as two floating point numbers + separated by colon, which wil make yaz-ztest perform + a random sleep between the first and second number. + + + The database parameter seed takes an integer + as value. This will call srand with this integer to + ensure that the random behavior can be re-played. + + + Suppose we want searches to take between 0.1 and 0.5 seconds and + a fetch to take 0.2 second. To access test database Default we'd use: + Default?search-delay=0.1:0.5&fetch-delay=0.2. + + GFS CONFIGURATION AND VIRTUAL HOSTS &gfs-virtual; diff --git a/ztest/ztest.c b/ztest/ztest.c index a860296..6d806b2 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -179,18 +179,28 @@ static void init_delay(struct delay *delayp) static int parse_delay(struct delay *delayp, const char *value) { - delayp->d1 = atof(value); - delayp->d2 = 0.0; + if (sscanf(value, "%lf:%lf", &delayp->d1, &delayp->d2) == 2) + ; + else if (sscanf(value, "%lf", &delayp->d1) == 1) + delayp->d2 = 0.0; + else + return -1; return 0; } static void do_delay(const struct delay *delayp) { - struct timeval tv; + double d = delayp->d1; - tv.tv_sec = floor(delayp->d1); - tv.tv_usec = (delayp->d1 - floor(delayp->d1)) * 1000000; - select(0, 0, 0, 0, &tv); + if (d > 0.0) + { + struct timeval tv; + if (delayp->d2 > d) + d += (rand()) * (delayp->d2 - d) / RAND_MAX; + tv.tv_sec = floor(d); + tv.tv_usec = (d - floor(d)) * 1000000; + select(0, 0, 0, 0, &tv); + } } int ztest_search(void *handle, bend_search_rr *rr) @@ -244,6 +254,7 @@ int ztest_search(void *handle, bend_search_rr *rr) new_set->db = xstrdup(db); init_delay(&new_set->search_delay); init_delay(&new_set->present_delay); + init_delay(&new_set->fetch_delay); db_sep = strchr(db, '?'); if (db_sep) @@ -688,6 +699,16 @@ int ztest_sort(void *handle, bend_sort_rr *rr) /* present request handler */ int ztest_present(void *handle, bend_present_rr *rr) { + struct session_handle *sh = (struct session_handle*) handle; + struct result_set *set = get_set(sh, rr->setname); + + if (!set) + { + rr->errcode = YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST; + rr->errstring = odr_strdup(rr->stream, rr->setname); + return 0; + } + do_delay(&set->present_delay); return 0; } @@ -705,6 +726,7 @@ int ztest_fetch(void *handle, bend_fetch_rr *r) r->errstring = odr_strdup(r->stream, r->setname); return 0; } + do_delay(&set->fetch_delay); r->last_in_set = 0; r->basename = set->db; r->output_format = r->request_format;