20 use Test::Class::Load qw ( . ); # run from the t directory
22 create_test_database();
25 start_zebraqueue_daemon();
27 Test::Class->runtests;
29 stop_zebraqueue_daemon();
34 =head3 create_test_database
36 sets up the test database.
40 sub create_test_database {
42 diag 'creating testing database...';
43 my $installer = C4::Installer->new() or die 'unable to create new installer';
44 # warn Data::Dumper->Dump( [ $installer ], [ 'installer' ] );
45 my $all_languages = getAllLanguages();
46 my $error = $installer->load_db_schema();
47 die "unable to load_db_schema: $error" if ( $error );
48 my $list = $installer->sql_file_list('en', 'marc21', { optional => 1,
50 my ($fwk_language, $installed_list) = $installer->load_sql_in_order($all_languages, @$list);
51 $installer->set_version_syspref();
52 $installer->set_marcflavour_syspref('MARC21');
53 $installer->set_indexing_engine(0);
54 diag 'database created.'
60 This method deletes and reinitializes the zebra database directory,
61 and then spans off a zebra server.
68 diag 'cleaning zebrasrv...';
70 foreach my $zebra_server ( qw( biblioserver authorityserver ) ) {
71 my $zebra_config = C4::Context->zebraconfig($zebra_server)->{'config'};
72 my $zebra_db_dir = C4::Context->zebraconfig($zebra_server)->{'directory'};
73 foreach my $zebra_db_name ( qw( biblios authorities ) ) {
74 my $command = "zebraidx -c $zebra_config -d $zebra_db_name init";
75 my $return = system( $command . ' > /dev/null 2>&1' );
77 diag( "command '$command' died with value: " . $? >> 8 );
80 $command = "zebraidx -c $zebra_config -d $zebra_db_name create $zebra_db_name";
82 $return = system( $command . ' > /dev/null 2>&1' );
84 diag( "command '$command' died with value: " . $? >> 8 );
89 diag 'starting zebrasrv...';
91 my $pidfile = File::Spec->catdir( C4::Context->config("logdir"), 'zebra.pid' );
92 my $command = sprintf( 'zebrasrv -f %s -D -l %s -p %s',
94 File::Spec->catdir( C4::Context->config("logdir"), 'zebra.log' ),
98 my $output = qx( $command );
102 if ( -e $pidfile, 'pidfile exists' ) {
103 diag 'zebrasrv started.';
105 die 'unable to start zebrasrv';
112 using the PID file for the zebra server, send it a TERM signal with
113 "kill". We can't tell if the process actually dies or not.
119 my $pidfile = File::Spec->catdir( C4::Context->config("logdir"), 'zebra.pid' );
121 open( my $pidh, '<', $pidfile )
123 if ( defined $pidh ) {
124 my ( $pid ) = <$pidh> or return;
126 my $killed = kill 15, $pid; # 15 is TERM
127 if ( $killed != 1 ) {
128 warn "unable to kill zebrasrv with pid: $pid";
135 =head3 start_zebraqueue_daemon
137 kick off a zebraqueue_daemon.pl process.
141 sub start_zebraqueue_daemon {
143 my $command = q(run/bin/koha-zebraqueue-ctl.sh start);
145 my $started = system( $command );
146 diag "started: $started";
148 # my $command = sprintf( 'KOHA_CONF=%s ../misc/bin/zebraqueue_daemon.pl > %s 2>&1 &',
153 # my $queue = system( $command );
154 # diag "queue: $queue";
158 =head3 stop_zebraqueue_daemon
163 sub stop_zebraqueue_daemon {
165 my $command = q(run/bin/koha-zebraqueue-ctl.sh stop);
167 my $started = system( $command );
168 diag "started: $started";