TT#62215 Return zero exit code for successful tests and non-zero on any error

Change-Id: I5a0a5a8c64b2a1024a00a3c593bd2f856b31b7e7
changes/69/32069/5
Flaviu Mates 6 years ago
parent 127631399d
commit aa50796905

@ -4,7 +4,6 @@ use lib 't/api-rest2/lib';
use strict; use strict;
use warnings; use warnings;
use TestFramework; use TestFramework;
use Test::More;
use threads; use threads;
use Thread::Queue; use Thread::Queue;
use Data::Dumper; use Data::Dumper;
@ -55,17 +54,16 @@ for ( @test_files ) {
$tests_queue->end(); $tests_queue->end();
for (1..2) { for (1..2) {
push @threads, threads->create( {'context' => 'void'}, \&worker, $tests_queue ); push @threads, threads->create( {'context' => 'scalar'}, \&worker, $tests_queue, 0 );
} }
my @exit_codes;
foreach ( @threads ){ foreach ( @threads ){
$_->join(); push @exit_codes, $_->join();
} }
done_testing();
sub worker { sub worker {
my ($tests_queue) = @_; my ( $tests_queue, $exit_code ) = @_;
while ( my $test_file = $tests_queue->dequeue_nb() ) { while ( my $test_file = $tests_queue->dequeue_nb() ) {
chomp $test_file; chomp $test_file;
@ -76,12 +74,17 @@ sub worker {
my $result = $test_framework->run(); my $result = $test_framework->run();
my $total_time = time - $start_time; my $total_time = time - $start_time;
print "Finished test execution for $test_file, test execution returned with exit code ".$result->{success}."\n"; print "Finished test execution for $test_file\n";
if ( !$result->{success} ) { if ( !$result->{success} ) {
$exit_code = 1;
print $result->{error_count}." errors were found!\n"; print $result->{error_count}." errors were found!\n";
} }
print "Tests for $test_file took $total_time seconds.\n\n"; print "Tests for $test_file took $total_time seconds.\n\n";
} }
return $exit_code;
} }
1; if ( grep { $_ == 1 } @exit_codes ) {
exit 1;
}
exit 0;
Loading…
Cancel
Save