Bugzilla – Attachment 39854 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]
[SIGNED OFF] Bug 14256: Check for unique constraint to regenerate random data
SIGNED-OFF-Bug-14256-Check-for-unique-constraint-t.patch (text/plain), 3.29 KB, created by
Tomás Cohen Arazi (tcohen)
on 2015-06-04 12:30:20 UTC
(
hide
)
Description:
[SIGNED OFF] Bug 14256: Check for unique constraint to regenerate random data
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2015-06-04 12:30:20 UTC
Size:
3.29 KB
patch
obsolete
>From 7fc44c56b2077b374fcfa7a556f1e5c876e051e4 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 3 Jun 2015 15:54:57 -0300 >Subject: [PATCH] [SIGNED OFF] Bug 14256: Check for unique constraint to > regenerate random data > >Unique constraints should be checked when creating random data. Otherwise >we get failures when the generated data already exists on the DB. > >This patch takes advantage of ->unique_constraints() to do the job, >looping through all the unique constraints defined for the source. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com> >--- > t/lib/TestBuilder.pm | 63 ++++++++++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 56 insertions(+), 7 deletions(-) > >diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm >index 72364e3..7814df3 100644 >--- a/t/lib/TestBuilder.pm >+++ b/t/lib/TestBuilder.pm >@@ -155,13 +155,62 @@ sub _buildColumnValues { > > my $col_values; > my @columns = $self->schema->source($source)->columns; >- for my $col_name( @columns ) { >- my $col_value = $self->_buildColumnValue({ >- source => $source, >- column_name => $col_name, >- value => $value, >- }); >- $col_values->{$col_name} = $col_value if( defined( $col_value ) ); >+ 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 >+ for my $col_name( @columns ) { >+ my $col_value = $self->_buildColumnValue({ >+ source => $source, >+ column_name => $col_name, >+ value => $value, >+ }); >+ $col_values->{$col_name} = $col_value if( defined( $col_value ) ); >+ } >+ >+ # 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} ); >+ >+ if ( scalar keys %unique_constraints > 0 ) { >+ >+ # verify the data would respect each unique constraint >+ foreach my $constraint (keys %unique_constraints) { >+ >+ my $condition; >+ my @constraint_columns = $unique_constraints{$constraint}; >+ # loop through all constraint columns and build the condition >+ foreach my $constraint_column ( @constraint_columns ) { >+ # build the filter >+ $condition->{ $constraint_column } = >+ $col_values->{ $constraint_column }; >+ } >+ >+ my $count = $self->schema >+ ->resultset( $source ) >+ ->search( $condition ) >+ ->count(); >+ if ( $count > 0 ) { >+ $at_least_one_constraint_failed = 1; >+ # no point checking more stuff, exit the loop >+ last; >+ } >+ } >+ >+ if ( $at_least_one_constraint_failed ) { >+ $values_ok = 0; >+ } else { >+ $values_ok = 1; >+ } >+ >+ } else { >+ $values_ok = 1; >+ } > } > return $col_values; > } >-- >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