-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvements to automated tests, including a testing database
I'm adding a bunch of additions to the test suite. There is now a test database that is created, and a test instance of the zebra server and daemon that are run before the tests in t/database-dependent.pl are run. This means that you can test things that insert (or destroy) things in the database. To use these tests, after you 'make' your koha installation, you can change to the 't' directory and 'make test' there. There is now an additional question asked during installation. It asks whether you would like to run the data-dependent tests. If so, It asks you for some login information to a test database. I recommend that you do not not use your production database here. It will delete all of the data in it. Things that need improvement: * I suspect that there are large parts that are not very platform independent, so they will need to be improved. * There are some parts of the installer that will probably be refactored to let this work a little bit better, including being run directly from a main-level 'make' target at some point. * Lots more tests to add. Be bold! (see the t/lib directory) * other tests in t/*.t can possibly benefit from being included in here. There are two required perl modules for this part of the test suite. I use: 'Test::Class' => 0.028, 'Test::Class::Load' => 0.02, They are not listed as requirements in the top-level Makefile.PL because they're not actually required to install or use Koha, but if you want to run the test suite, you can install them from CPAN. Signed-off-by: Galen Charlton <galen.charlton@liblime.com> Signed-off-by: Joshua Ferraro <jmf@liblime.com>
- Loading branch information
Showing
4 changed files
with
483 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
SHELL = /bin/sh | ||
NOOP = $(SHELL) -c true | ||
NOECHO = @ | ||
ECHO = echo | ||
MKDIR = /bin/mkdir | ||
CP = cp | ||
SED = /bin/sed | ||
|
||
# some of these are pretty questionable. | ||
PERL = /usr/bin/perl | ||
# TEST_FILES = *.t | ||
TEST_FILES = database_dependent.pl | ||
PROVE = /usr/bin/prove | ||
PROVE_FLAGS = -v | ||
KOHA_CONF_DIR = ../etc | ||
CONF_FILE_TEMPLATE = $(KOHA_CONF_DIR)/koha-conf.xml | ||
TEST_CONF_FILE = etc/koha-conf.xml | ||
MKPATH = $(PERL) "-MExtUtils::Command" -e mkpath | ||
|
||
TEST_REWRITE_SCRIPT = rewrite-config-test.PL | ||
REAL_REWRITE_SCRIPT = ../rewrite-config.PL | ||
|
||
ZEBRA_CONF_DIR = etc/zebradb | ||
ZEBRA_CONF_FILES = $(ZEBRA_CONF_DIR)/etc/passwd $(ZEBRA_CONF_DIR)/zebra-biblios.cfg $(ZEBRA_CONF_DIR)/zebra-authorities.cfg $(ZEBRA_CONF_DIR)/zebra-authorities-dom.cfg $(ZEBRA_CONF_DIR)/explain-authorities.xml $(ZEBRA_CONF_DIR)/explain-biblios.xml $(ZEBRA_CONF_DIR)/retrieval-info-auth-grs1.xml $(ZEBRA_CONF_DIR)/retrieval-info-auth-dom.xml $(ZEBRA_CONF_DIR)/ccl.properties $(ZEBRA_CONF_DIR)/cql.properties $(ZEBRA_CONF_DIR)/pqf.properties | ||
|
||
SCRIPTS = koha-zebra-ctl.sh koha-pazpar2-ctl.sh koha-zebraqueue-ctl.sh zebraqueue_daemon.pl | ||
SRC_SCRIPT_DIR = ../misc/bin | ||
TEST_SCRIPT_DIR = bin | ||
|
||
|
||
all :: | ||
$(NOECHO) $(ECHO) RUNNING THIS MAKEFILE MAY CAUSE LOSS OF DATA | ||
$(NOECHO) $(ECHO) | ||
$(NOECHO) $(ECHO) This makefile is completely beta. | ||
$(NOECHO) $(ECHO) Please read it first and edit the variables at the top. | ||
$(NOECHO) $(ECHO) Then, you can run \'make test\' | ||
|
||
config_file :: $(CONF_FILE_TEMPLATE) test_run_dirs | ||
$(CP) $(CONF_FILE_TEMPLATE) $(TEST_CONF_FILE) | ||
$(PERL) $(TEST_REWRITE_SCRIPT) --file $(TEST_CONF_FILE) | ||
$(PERL) $(REAL_REWRITE_SCRIPT) $(TEST_CONF_FILE) | ||
|
||
zebra_conf_files :: test_run_dirs $(ZEBRA_CONF_FILES) | ||
|
||
|
||
$(ZEBRA_CONF_FILES) :: | ||
$(CP) ../$@ $@ | ||
$(PERL) $(TEST_REWRITE_SCRIPT) --file $@ | ||
$(PERL) $(REAL_REWRITE_SCRIPT) $@ | ||
|
||
$(SCRIPTS) :: | ||
$(SED) s/--user=\$$USER.\$$GROUP// $(SRC_SCRIPT_DIR)/$@ > $(TEST_SCRIPT_DIR)/$@ | ||
$(PERL) $(TEST_REWRITE_SCRIPT) --file $(TEST_SCRIPT_DIR)/$@ | ||
$(PERL) $(REAL_REWRITE_SCRIPT) $(TEST_SCRIPT_DIR)/$@ | ||
|
||
test :: config_file $(ZEBRA_CONF_FILES) $(SCRIPTS) | ||
KOHA_CONF=$(TEST_CONF_FILE) $(PROVE) $(PROVE_FLAGS) $(TEST_FILES) | ||
|
||
test_run_dirs :: | ||
$(CP) -a ../etc/zebradb etc | ||
$(MKPATH) etc/zebradb/etc | ||
$(MKPATH) var/lib/zebradb/biblios/key | ||
$(MKPATH) var/lib/zebradb/biblios/register | ||
$(MKPATH) var/lib/zebradb/biblios/shadow | ||
$(MKPATH) var/lib/zebradb/biblios/tmp | ||
$(MKPATH) var/lib/zebradb/authorities/key | ||
$(MKPATH) var/lib/zebradb/authorities/register | ||
$(MKPATH) var/lib/zebradb/authorities/shadow | ||
$(MKPATH) var/lib/zebradb/authorities/tmp | ||
$(MKPATH) var/lock/zebradb/biblios | ||
$(MKPATH) var/lock/zebradb/authorities | ||
$(MKPATH) var/run/zebradb | ||
$(MKPATH) var/log/zebradb | ||
$(MKPATH) bin | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
#!/usr/bin/perl | ||
|
||
use warnings; | ||
use strict; | ||
|
||
=head2 | ||
=cut | ||
|
||
use C4::Context; | ||
use C4::Installer; | ||
use C4::Languages; | ||
use Data::Dumper; | ||
use Test::More; | ||
|
||
use lib q( . .. ); | ||
|
||
use Test::Class::Load qw ( . ); # run from the t directory | ||
|
||
create_test_database(); | ||
|
||
start_zebrasrv(); | ||
start_zebraqueue_daemon(); | ||
|
||
Test::Class->runtests; | ||
|
||
stop_zebraqueue_daemon(); | ||
stop_zebrasrv(); | ||
|
||
# stop_zebrasrv(); | ||
|
||
=head3 create_test_database | ||
sets up the test database. | ||
=cut | ||
|
||
sub create_test_database { | ||
|
||
diag 'creating testing datbase...'; | ||
my $installer = C4::Installer->new() or die 'unable to create new installer'; | ||
# warn Data::Dumper->Dump( [ $installer ], [ 'installer' ] ); | ||
my $all_languages = getAllLanguages(); | ||
my $error = $installer->load_db_schema(); | ||
die "unable to load_db_schema: $error" if ( $error ); | ||
my $list = $installer->sql_file_list('en', 'marc21', { optional => 1, | ||
mandatory => 1 } ); | ||
my ($fwk_language, $installed_list) = $installer->load_sql_in_order($all_languages, @$list); | ||
$installer->set_version_syspref(); | ||
$installer->set_marcflavour_syspref('MARC21'); | ||
$installer->set_indexing_engine(0); | ||
diag 'database created.' | ||
} | ||
|
||
|
||
=head3 start_zebrasrv | ||
This method deletes and reinitializes the zebra database directory, | ||
and then spans off a zebra server. | ||
=cut | ||
|
||
sub start_zebrasrv { | ||
|
||
stop_zebrasrv(); | ||
diag 'cleaning zebrasrv...'; | ||
|
||
foreach my $zebra_server ( qw( biblioserver authorityserver ) ) { | ||
my $zebra_config = C4::Context->zebraconfig($zebra_server)->{'config'}; | ||
my $zebra_db_dir = C4::Context->zebraconfig($zebra_server)->{'directory'}; | ||
foreach my $zebra_db_name ( qw( biblios authorities ) ) { | ||
my $command = "zebraidx -c $zebra_config -d $zebra_db_name init"; | ||
my $return = system( $command . ' > /dev/null 2>&1' ); | ||
if ( $return != 0 ) { | ||
diag( "command '$command' died with value: " . $? >> 8 ); | ||
} | ||
|
||
$command = "zebraidx -c $zebra_config -d $zebra_db_name create $zebra_db_name"; | ||
diag $command; | ||
$return = system( $command . ' > /dev/null 2>&1' ); | ||
if ( $return != 0 ) { | ||
diag( "command '$command' died with value: " . $? >> 8 ); | ||
} | ||
} | ||
} | ||
|
||
diag 'starting zebrasrv...'; | ||
|
||
my $pidfile = File::Spec->catdir( C4::Context->config("logdir"), 'zebra.pid' ); | ||
my $command = sprintf( 'zebrasrv -f %s -D -l %s -p %s', | ||
$ENV{'KOHA_CONF'}, | ||
File::Spec->catdir( C4::Context->config("logdir"), 'zebra.log' ), | ||
$pidfile, | ||
); | ||
diag $command; | ||
my $output = qx( $command ); | ||
if ( $output ) { | ||
diag $output; | ||
} | ||
if ( -e $pidfile, 'pidfile exists' ) { | ||
diag 'zebrasrv started.'; | ||
} else { | ||
die 'unable to start zebrasrv'; | ||
} | ||
return $output; | ||
} | ||
|
||
=head3 stop_zebrasrv | ||
using the PID file for the zebra server, send it a TERM signal with | ||
"kill". We can't tell if the process actually dies or not. | ||
=cut | ||
|
||
sub stop_zebrasrv { | ||
|
||
my $pidfile = File::Spec->catdir( C4::Context->config("logdir"), 'zebra.pid' ); | ||
if ( -e $pidfile ) { | ||
open( my $pidh, '<', $pidfile ) | ||
or return; | ||
if ( defined $pidh ) { | ||
my ( $pid ) = <$pidh> or return; | ||
close $pidh; | ||
my $killed = kill 15, $pid; # 15 is TERM | ||
if ( $killed != 1 ) { | ||
warn "unable to kill zebrasrv with pid: $pid"; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
=head3 start_zebraqueue_daemon | ||
kick off a zebraqueue_daemon.pl process. | ||
=cut | ||
|
||
sub start_zebraqueue_daemon { | ||
|
||
my $command = q(bin/koha-zebraqueue-ctl.sh start); | ||
diag $command; | ||
my $started = system( $command ); | ||
diag "started: $started"; | ||
|
||
# my $command = sprintf( 'KOHA_CONF=%s ../misc/bin/zebraqueue_daemon.pl > %s 2>&1 &', | ||
# $ENV{'KOHA_CONF'}, | ||
# 'zebra.log', | ||
# ); | ||
# diag $command; | ||
# my $queue = system( $command ); | ||
# diag "queue: $queue"; | ||
|
||
} | ||
|
||
=head3 stop_zebraqueue_daemon | ||
=cut | ||
|
||
sub stop_zebraqueue_daemon { | ||
|
||
my $command = q(bin/koha-zebraqueue-ctl.sh stop); | ||
diag $command; | ||
my $started = system( $command ); | ||
diag "started: $started"; | ||
|
||
} |
Oops, something went wrong.