Bugzilla – Attachment 39789 Details for
Bug 14256
Tests for TestBuilder fail randomly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14256: (followup) do not repeat existing values on primary columns
Bug-14256-followup-do-not-repeat-existing-values-o.patch (text/plain), 2.66 KB, created by
Tomás Cohen Arazi (tcohen)
on 2015-06-02 19:14:35 UTC
(
hide
)
Description:
Bug 14256: (followup) do not repeat existing values on primary columns
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2015-06-02 19:14:35 UTC
Size:
2.66 KB
patch
obsolete
>From 375df0cd663b3327dafa0007843d4bda701800b0 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@gmail.com> >Date: Tue, 2 Jun 2015 16:09:47 -0300 >Subject: [PATCH] Bug 14256: (followup) do not repeat existing values on > primary columns > >This followup patch makes _buildColumnValue test the generated >random value so TestBuilder doesn't try to insert repeated values >on primary columns. > >It also removes an unnecesary use of 'eval' that made it difficult to >spot errors. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/lib/TestBuilder.pm | 34 ++++++++++++++++++++++++++-------- > 1 file changed, 26 insertions(+), 8 deletions(-) > >diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm >index 826ab1a..5fbb149 100644 >--- a/t/lib/TestBuilder.pm >+++ b/t/lib/TestBuilder.pm >@@ -1,9 +1,10 @@ > package t::lib::TestBuilder; > > use Modern::Perl; >+ > use Koha::Database; > use String::Random; >- >+use List::MoreUtils qw(any); > > my $gen_type = { > tinyint => \&_gen_int, >@@ -34,6 +35,7 @@ my $gen_type = { > mediumblob => \&_gen_blob, > blob => \&_gen_blob, > longblob => \&_gen_blob, >+ > }; > > our $default_value = { >@@ -238,17 +240,33 @@ sub _buildColumnValue { > $col_value = $default_value->{$source}->{$col_name}; > } > elsif( not $col_info->{default_value} and not $col_info->{is_auto_increment} and not $col_info->{is_foreign_key} ) { >- eval { >- my $data_type = $col_info->{data_type}; >- $data_type =~ s| |_|; >- $col_value = $gen_type->{$data_type}->( $self, { info => $col_info } ); >- }; >- die "The type $col_info->{data_type} is not defined\n" if ($@); >+ >+ my $data_type = $col_info->{data_type}; >+ $data_type =~ s| |_|; >+ >+ if ( any { $data_type eq $_ } (keys $gen_type) ) { >+ my $value_ok = 'no'; >+ while ( $value_ok eq 'no' ) { >+ # generate value >+ $col_value = $gen_type->{$data_type}->( $self, { info => $col_info } ); >+ # should value be unique? >+ my $primary_names = $self->schema->source($source)->primary_columns(); >+ if ( not ( any { $col_name eq $_ } $primary_names and >+ $self->schema >+ ->resultset($source) >+ ->search({ $col_name => $col_value }) >+ ->count > 0 ) ) { >+ >+ $value_ok = 'yes'; >+ } >+ } >+ } else { >+ die "The type $col_info->{data_type} is not defined\n"; >+ } > } > return $col_value; > } > >- > sub _gen_int { > my ($self, $params) = @_; > my $data_type = $params->{info}->{data_type}; >-- >2.4.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14256
:
39430
|
39463
|
39788
|
39789
|
39824
|
39825
|
39835
|
39836
|
39854
|
39855
|
40041
|
40042