Bugzilla – Attachment 40042 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]
[PASSED QA] Bug 14256: (follow-up) Check for unique constraint to regenerate random data
PASSED-QA-Bug-14256-follow-up-Check-for-unique-con.patch (text/plain), 4.88 KB, created by
Kyle M Hall (khall)
on 2015-06-09 18:50:45 UTC
(
hide
)
Description:
[PASSED QA] Bug 14256: (follow-up) Check for unique constraint to regenerate random data
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2015-06-09 18:50:45 UTC
Size:
4.88 KB
patch
obsolete
>From 014753521780c5e3e98c77fbe6e8018a5ae3f37e Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@koha-community.org> >Date: Thu, 4 Jun 2015 11:35:15 +0200 >Subject: [PATCH] [PASSED QA] Bug 14256: (follow-up) Check for unique constraint to regenerate random data > >There were some issues in the previous patch. This patch fixes the >following: >- rename $value with $original_value >- remove $at_least_one_constraint_failed and $values_ok which make the > code unnecessarily complicated >- the constraints have to be checked only if no original value is passed >- _buildColumnValue created a key to the default value hashref, it broke > the test: > last BUILD_VALUE if exists( $default_value->{$source} ); > >Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > t/lib/TestBuilder.pm | 47 ++++++++++++++++++++--------------------------- > 1 files changed, 20 insertions(+), 27 deletions(-) > >diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm >index 7814df3..5d3157a 100644 >--- a/t/lib/TestBuilder.pm >+++ b/t/lib/TestBuilder.pm >@@ -150,42 +150,44 @@ sub _formatSource { > > sub _buildColumnValues { > my ($self, $params) = @_; >- my $source = _formatSource( { source => $params->{source} } ); >- my $value = $params->{value}; >+ my $source = _formatSource( { source => $params->{source} } ); >+ my $original_value = $params->{value}; > > my $col_values; > my @columns = $self->schema->source($source)->columns; > my %unique_constraints = $self->schema->source($source)->unique_constraints(); > >- my $values_ok = 0; >- my $at_least_one_constraint_failed; >- >- while ( not $values_ok ) { >- >- $at_least_one_constraint_failed = 0; >- # generate random values >+ my $build_value = 1; >+ BUILD_VALUE: while ( $build_value ) { >+ # generate random values for all columns > for my $col_name( @columns ) { > my $col_value = $self->_buildColumnValue({ > source => $source, > column_name => $col_name, >- value => $value, >+ value => $original_value, > }); > $col_values->{$col_name} = $col_value if( defined( $col_value ) ); > } >+ $build_value = 0; > > # If default values are set, maybe the data exist in the DB > # But no need to wait for another value >- last if exists( $default_value->{$source} ); >+ # FIXME this can be wrong if a default value is defined for a field >+ # which is not a constraint and that the generated value for the >+ # constraint already exists. >+ last BUILD_VALUE if exists( $default_value->{$source} ); > >- if ( scalar keys %unique_constraints > 0 ) { >+ # If there is no original value given and unique constraints exist, >+ # check if the generated values do not exist yet. >+ if ( not defined $original_value and scalar keys %unique_constraints > 0 ) { > > # verify the data would respect each unique constraint >- foreach my $constraint (keys %unique_constraints) { >+ CONSTRAINTS: foreach my $constraint (keys %unique_constraints) { > > my $condition; >- my @constraint_columns = $unique_constraints{$constraint}; >+ my $constraint_columns = $unique_constraints{$constraint}; > # loop through all constraint columns and build the condition >- foreach my $constraint_column ( @constraint_columns ) { >+ foreach my $constraint_column ( @$constraint_columns ) { > # build the filter > $condition->{ $constraint_column } = > $col_values->{ $constraint_column }; >@@ -196,20 +198,11 @@ sub _buildColumnValues { > ->search( $condition ) > ->count(); > if ( $count > 0 ) { >- $at_least_one_constraint_failed = 1; > # no point checking more stuff, exit the loop >- last; >+ $build_value = 1; >+ last CONSTRAINTS; > } > } >- >- if ( $at_least_one_constraint_failed ) { >- $values_ok = 0; >- } else { >- $values_ok = 1; >- } >- >- } else { >- $values_ok = 1; > } > } > return $col_values; >@@ -283,7 +276,7 @@ sub _buildColumnValue { > if( exists( $value->{$col_name} ) ) { > $col_value = $value->{$col_name}; > } >- elsif( exists( $default_value->{$source}->{$col_name} ) ) { >+ elsif( exists $default_value->{$source} and exists $default_value->{$source}->{$col_name} ) { > $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} ) { >-- >1.7.2.5
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