From 435197a0944c5b4cdad4c6b9e9ddff5ad05734d9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 22 May 2015 18:39:11 +0200 Subject: [PATCH] Bug 14256: Make TestBuilder regenerates a string if to short In some cases, especially branchcode and categorycode, the generated string for a primary key already existed in DB. Which make the tests fail, and the data are not gererated. This patch regenerate a string if the one generated is too short and can be longer. Test plan: Use the diff from the previous comment, and confirm that the tests only fail in the very few cases. QA: Actually I don't know if the better could be to use the existing value, but maybe not... Signed-off-by: Mark Tompsett NOTE: Perhaps a hardcoded size like >=2 could be replaced by the minimum of (+1 max string length in the field, size cap). After a couple glitches testing, my bad, it does reduce failures drastically. I had category code of length 4 in my database at the time. --- t/lib/TestBuilder.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm index 72364e3..826ab1a 100644 --- a/t/lib/TestBuilder.pm +++ b/t/lib/TestBuilder.pm @@ -299,7 +299,11 @@ sub _gen_text { $regex = '[A-Za-z]'; } my $random = String::Random->new( max => $size ); - return $random->randregex($regex); + my $string = $random->randregex($regex); + while ( defined $size and $size > 2 and length( $string ) <= 2 ) { + $string = $random->randregex($regex); + } + return $string; } sub _gen_set_enum { -- 2.1.4