Bug 18055: Speed up '00-strict.t' test, with Parallel::ForkManager
authorMason James <mtj@kohaaloha.com>
Sun, 5 Feb 2017 01:40:06 +0000 (14:40 +1300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 28 Mar 2018 18:53:05 +0000 (15:53 -0300)
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 libsys-cpu-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

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Edit: removed debian/control changes as the file is generated

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
C4/Installer/PerlDependencies.pm
t/db_dependent/00-strict.t [changed mode: 0644->0755]

index 8961453..720ebab 100644 (file)
@@ -873,7 +873,16 @@ our $PERL_DEPS = {
         'min_ver'  => '5.01',
         # also required for Zebra installs: about page: bug 20061
     },
-
+    'Parallel::ForkManager' => {
+        usage => 'Core',
+        required => 0,
+        min_ver => '0.75',
+    },
+    'Sys::CPU' => {
+        usage => 'Core',
+        required => 0,
+        min_ver => '0.52',
+    },
 };
 
 1;
old mode 100644 (file)
new mode 100755 (executable)
index 3b16d4c..4aa0a0c
@@ -1,24 +1,60 @@
+#!/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', 'reviews',
-    'rewrite-config.PL', 'rotating_collections', 'serials', 'services', 'skel',
-    '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',           'reviews',
+    'rewrite-config.PL', 'rotating_collections',
+    'serials',           'services',
+    'skel',              'suggestion',
+    'svc',               'tags',
+    'tools',             'virtualshelves'
+);
 
 $Test::Strict::TEST_STRICT = 0;
 $Test::Strict::TEST_SKIP = [ 'misc/kohalib.pl', 'misc/plack/koha.psgi' ];
 
-all_perl_files_ok(@dirs);
+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;
+
+done_testing();