18 use Test::Class::Load qw ( . ); # run from the t directory
20 create_test_database();
23 start_zebraqueue_daemon();
25 Test::Class->runtests;
27 stop_zebraqueue_daemon();
32 =head3 create_test_database
34 sets up the test database.
38 sub create_test_database {
40 diag 'creating testing database...';
41 my $installer = C4::Installer->new() or die 'unable to create new installer';
42 # warn Data::Dumper->Dump( [ $installer ], [ 'installer' ] );
43 my $all_languages = getAllLanguages();
44 my $error = $installer->load_db_schema();
45 die "unable to load_db_schema: $error" if ( $error );
46 my $list = $installer->sql_file_list('en', 'marc21', { optional => 1,
48 my ($fwk_language, $installed_list) = $installer->load_sql_in_order($all_languages, @$list);
49 $installer->set_version_syspref();
50 $installer->set_marcflavour_syspref('MARC21');
51 $installer->set_indexing_engine(0);
52 diag 'database created.'
58 This method deletes and reinitializes the zebra database directory,
59 and then spans off a zebra server.
66 diag 'cleaning zebrasrv...';
68 foreach my $zebra_server ( qw( biblioserver authorityserver ) ) {
69 my $zebra_config = C4::Context->zebraconfig($zebra_server)->{'config'};
70 my $zebra_db_dir = C4::Context->zebraconfig($zebra_server)->{'directory'};
71 foreach my $zebra_db_name ( qw( biblios authorities ) ) {
72 my $command = "zebraidx -c $zebra_config -d $zebra_db_name init";
73 my $return = system( $command . ' > /dev/null 2>&1' );
75 diag( "command '$command' died with value: " . $? >> 8 );
78 $command = "zebraidx -c $zebra_config -d $zebra_db_name create $zebra_db_name";
80 $return = system( $command . ' > /dev/null 2>&1' );
82 diag( "command '$command' died with value: " . $? >> 8 );
87 diag 'starting zebrasrv...';
89 my $pidfile = File::Spec->catdir( C4::Context->config("logdir"), 'zebra.pid' );
90 my $command = sprintf( 'zebrasrv -f %s -D -l %s -p %s',
92 File::Spec->catdir( C4::Context->config("logdir"), 'zebra.log' ),
96 my $output = qx( $command );
100 if ( -e $pidfile, 'pidfile exists' ) {
101 diag 'zebrasrv started.';
103 die 'unable to start zebrasrv';
110 using the PID file for the zebra server, send it a TERM signal with
111 "kill". We can't tell if the process actually dies or not.
117 my $pidfile = File::Spec->catdir( C4::Context->config("logdir"), 'zebra.pid' );
119 open( my $pidh, '<', $pidfile )
121 if ( defined $pidh ) {
122 my ( $pid ) = <$pidh> or return;
124 my $killed = kill 15, $pid; # 15 is TERM
125 if ( $killed != 1 ) {
126 warn "unable to kill zebrasrv with pid: $pid";
133 =head3 start_zebraqueue_daemon
135 kick off a zebraqueue_daemon.pl process.
139 sub start_zebraqueue_daemon {
141 my $command = q(run/bin/koha-zebraqueue-ctl.sh start);
143 my $started = system( $command );
144 diag "started: $started";
146 # my $command = sprintf( 'KOHA_CONF=%s ../misc/bin/zebraqueue_daemon.pl > %s 2>&1 &',
151 # my $queue = system( $command );
152 # diag "queue: $queue";
156 =head3 stop_zebraqueue_daemon
161 sub stop_zebraqueue_daemon {
163 my $command = q(run/bin/koha-zebraqueue-ctl.sh stop);
165 my $started = system( $command );
166 diag "started: $started";