From 63c40a0d2deed7bdc911db8c8c14b184044cebe1 Mon Sep 17 00:00:00 2001 From: Mason James Date: Sun, 5 Feb 2017 14:40:06 +1300 Subject: [PATCH] Bug 18055 - Speed up '00-strict.t' test, with Parallel::ForkManager Content-Type: text/plain; charset="utf-8" to test... 1/ run 00-strict.t test, (16.5 mins on a 4xcpu system) $ time prove t/db_dependent/00-strict.t ... Files=1, Tests=654, 994 wallclock secs ( 0.19 usr 0.04 sys + 873.40 cusr 116.20 csys = 989.83 CPU) Result: PASS real 16m34.104s 2/ apply patch 3/ install Parallel::ForkManager package $ sudo apt-get install libparallel-forkmanager-perl 4/ run 00-strict.t test again, (now 6 mins.. much faster) $ time prove t/db_dependent/00-strict.t ... Files=1, Tests=654, 364 wallclock secs ( 0.07 usr 0.01 sys + 1159.20 cusr 153.41 csys = 1312.69 CPU) Result: PASS real 6m4.355s --- C4/Installer/PerlDependencies.pm | 5 ++++ debian/control | 1 + t/db_dependent/00-strict.t | 64 ++++++++++++++++++++++++++++++++-------- 3 files changed, 58 insertions(+), 12 deletions(-) mode change 100644 => 100755 t/db_dependent/00-strict.t diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index 4e1f75f..0457863 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -852,6 +852,11 @@ our $PERL_DEPS = { required => 1, min_ver => '0.28', }, + 'Parallel::ForkManager' => { + usage => 'Core', + required => 0, + min_ver => '1.06', + }, }; 1; diff --git a/debian/control b/debian/control index 209828f..16f3432 100644 --- a/debian/control +++ b/debian/control @@ -92,6 +92,7 @@ Build-Depends: libalgorithm-checkdigits-perl, libnet-z3950-zoom-perl, libnumber-format-perl, libopenoffice-oodoc-perl, + libparallel-forkmanager-perl, libpath-tiny-perl, libpdf-api2-perl, libpdf-api2-simple-perl, diff --git a/t/db_dependent/00-strict.t b/t/db_dependent/00-strict.t old mode 100644 new mode 100755 index 688b449..70263bd --- a/t/db_dependent/00-strict.t +++ b/t/db_dependent/00-strict.t @@ -1,24 +1,64 @@ +#!/usr/bin/perl # This script is called by the pre-commit git hook to test modules compile use strict; use warnings; + +use threads; # used for parallel use Test::More; use Test::Strict; -use File::Spec; -use File::Find; +use Parallel::ForkManager; +use Sys::CPU; + use lib("misc/translator"); use lib("installer"); -my @dirs = ( 'acqui', 'admin', 'authorities', 'basket', - 'catalogue', 'cataloguing', 'changelanguage.pl', 'circ', 'debian', 'docs', - 'edithelp.pl', 'errors', 'fix-perl-path.PL', 'help.pl', 'installer', - 'koha_perl_deps.pl', 'kohaversion.pl', 'labels', - 'mainpage.pl', 'Makefile.PL', 'members', 'misc', 'offline_circ', 'opac', - 'patroncards', 'reports', 'reserve', 'resetversion.pl', 'reviews', - 'rewrite-config.PL', 'rotating_collections', 'serials', 'services', 'skel', - 'sms', 'suggestion', 'svc', 'tags', 'tools', 'virtualshelves' ); +my @dirs = ( + 'acqui', 'admin', + 'authorities', 'basket', + 'catalogue', 'cataloguing', + 'changelanguage.pl', 'circ', + 'debian', 'docs', + 'edithelp.pl', 'errors', + 'fix-perl-path.PL', 'help.pl', + 'installer', 'koha_perl_deps.pl', + 'kohaversion.pl', 'labels', + 'mainpage.pl', 'Makefile.PL', + 'members', 'misc', + 'offline_circ', 'opac', + 'patroncards', 'reports', + 'reserve', 'resetversion.pl', + 'reviews', 'rewrite-config.PL', + 'rotating_collections', 'serials', + 'services', 'skel', + 'sms', 'suggestion', + 'svc', 'tags', + 'tools', 'virtualshelves' +); $Test::Strict::TEST_STRICT = 0; -$Test::Strict::TEST_SKIP = [ 'misc/kohalib.pl', 'sms/sms_listen_windows_start.pl', 'misc/plack/koha.psgi' ]; +$Test::Strict::TEST_SKIP = [ + 'misc/kohalib.pl', 'sms/sms_listen_windows_start.pl', + 'misc/plack/koha.psgi' +]; + +my $ncpu; +if ( $ENV{KOHA_JENKINS} ) { + $ncpu = 2; # works fastest on kc.org jenkins box +} else { + $ncpu = Sys::CPU::cpu_count(); +} + +my $pm = new Parallel::ForkManager($ncpu); + +foreach my $d (@dirs) { + $pm->start and next; # do the fork + + all_perl_files_ok($d); + + $pm->finish; # do the exit in the child process +} + +$pm->wait_all_children; -all_perl_files_ok(@dirs); +done_testing(); -- 2.1.4