1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
/* This file is part of the Zebra server.
Copyright (C) Index Data
Zebra is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#if HAVE_SYS_UTSNAME_H
#include <sys/utsname.h>
#endif
#include <string.h>
#include "testlib.h"
static void update_process(ZebraService zs, int iter)
{
int i;
for (i = 0; i<iter; i++)
{
const char *rec = "<gils><title>some</title></gils>";
ZebraHandle zh = zebra_open(zs, 0);
zebra_add_record(zh, rec, strlen(rec));
if ((i % 30) == 0 || i == iter-1)
zebra_commit(zh);
zebra_close(zh);
}
}
static void search_process(ZebraService zs, int iter)
{
zint hits_max = 0;
int i;
for (i = 0; i<iter; i++)
{
ZebraHandle zh = zebra_open(zs, 0);
zint hits;
ZEBRA_RES res = zebra_search_PQF(zh, "@attr 1=4 some", "default",
&hits);
YAZ_CHECK(res == ZEBRA_OK);
YAZ_CHECK(hits >= hits_max);
if (hits < hits_max)
printf("i=%d hits=%lld hits_max=%lld\n", i, hits, hits_max);
hits_max = hits;
zebra_close(zh);
}
}
static pid_t fork_service(ZebraService zs, int iter,
void (*f)(ZebraService zs, int iter))
{
pid_t pid = fork();
YAZ_CHECK(pid != -1);
if (pid)
return pid;
(*f)(zs, iter);
YAZ_CHECK_TERM;
}
static void tst(int argc, char **argv)
{
ZebraService zs;
ZebraHandle zh;
mkdir("register", 0775);
mkdir("shadow", 0775);
zs = tl_start_up("test_zebra_fork.cfg", argc, argv);
YAZ_CHECK(zs);
zh = zebra_open(zs, 0);
YAZ_CHECK(zh);
YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK);
zebra_init(zh);
YAZ_CHECK(zebra_create_database (zh, "Default") == ZEBRA_OK);
YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK);
zebra_close(zh);
update_process(zs, 1);
#if HAVE_SYS_WAIT_H
#if HAVE_UNISTD_H
#if HAVE_SYS_UTSNAME_H
if (1)
{
int tst_with_fork = 1;
int status[3];
pid_t pids[3];
struct utsname s;
uname(&s);
if (!strcmp(s.sysname, "FreeBSD"))
tst_with_fork = 0;
yaz_log(YLOG_LOG, "s.sysname=%s tst_with_fork=%d", s.sysname,
tst_with_fork);
if (tst_with_fork)
{
pids[0] = fork_service(zs, 200, search_process);
pids[1] = fork_service(zs, 20, update_process);
pids[2] = fork_service(zs, 20, update_process);
waitpid(pids[0], &status[0], 0);
YAZ_CHECK(status[0] == 0);
waitpid(pids[1], &status[1], 0);
YAZ_CHECK(status[1] == 0);
waitpid(pids[2], &status[2], 0);
YAZ_CHECK(status[2] == 0);
}
}
#endif
#endif
#endif
YAZ_CHECK(tl_close_down(0, zs));
}
TL_MAIN
/*
* Local variables:
* c-basic-offset: 4
* c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab
*/
|