From: Max Kanat-Alexander Date: Sun, 18 Jul 2010 09:13:36 +0000 (-0700) Subject: Bug 579695: Make xt/search.t do substring tests using a more consistent X-Git-Tag: bugzilla-3.7.3~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a53ead418eba721625ce1b7fb8717099f2f878ee;p=thirdparty%2Fbugzilla.git Bug 579695: Make xt/search.t do substring tests using a more consistent substring length, thus fixing an intermittent failure that would show up when searching the cf_multi_select field. r=mkanat, a=mkanat (module owner) --- diff --git a/xt/lib/Bugzilla/Test/Search.pm b/xt/lib/Bugzilla/Test/Search.pm index af595e373c..72c3828064 100644 --- a/xt/lib/Bugzilla/Test/Search.pm +++ b/xt/lib/Bugzilla/Test/Search.pm @@ -302,7 +302,7 @@ sub create_keyword { sub create_user { my ($prefix) = @_; - my $user_name = $prefix . '-' . random(10) . "@" . random(10) + my $user_name = $prefix . '-' . random(15) . "@" . random(12) . "." . random(3); my $user_realname = $prefix . '-' . random(); my $user = Bugzilla::User->create({ @@ -374,7 +374,7 @@ sub _create_field_values { $values{'keywords'} = create_keyword($number)->name; foreach my $field qw(assigned_to qa_contact reporter cc) { - $values{$field} = create_user("$number-$field-")->login; + $values{$field} = create_user("$number-$field")->login; } my $classification = Bugzilla::Classification->create( @@ -415,7 +415,7 @@ sub _create_field_values { # "short_desc" as a word and matches it in every bug. my $value = "$number-$field" . random(); if ($field eq 'bug_file_loc' or $field eq 'see_also') { - $value = "http://$value" . random(3) + $value = "http://$value-" . random(3) . "/show_bug.cgi?id=$number"; } $values{$field} = $value; @@ -439,8 +439,8 @@ sub _create_field_values { . ' ' . random(); my @flags; - my $setter = create_user("$number-setter"); - my $requestee = create_user("$number-requestee"); + my $setter = create_user("$number-setters.login_name"); + my $requestee = create_user("$number-requestees.login_name"); $values{set_flags} = _create_flags($number, $setter, $requestee); my $month = $for_create ? "12" : "02"; diff --git a/xt/lib/Bugzilla/Test/Search/Constants.pm b/xt/lib/Bugzilla/Test/Search/Constants.pm index 9b13e1a429..7fe7d0efa4 100644 --- a/xt/lib/Bugzilla/Test/Search/Constants.pm +++ b/xt/lib/Bugzilla/Test/Search/Constants.pm @@ -46,6 +46,7 @@ our @EXPORT = qw( OR_BROKEN OR_SKIP SKIP_FIELDS + SUBSTR_NO_FIELD_ADD SUBSTR_SIZE TESTS TESTS_PER_RUN @@ -156,22 +157,35 @@ use constant USER_FIELDS => qw( ); # For the "substr"-type searches, how short of a substring should -# we use? +# we use? The goal is to be shorter than the full string, but +# long enough to still be globally unique. use constant SUBSTR_SIZE => 20; # However, for some fields, we use a different size. use constant FIELD_SUBSTR_SIZE => { - alias => 12, - bug_file_loc => 30, + alias => 11, # Just the month and day. deadline => -5, creation_ts => -8, delta_ts => -8, + percentage_complete => 7, work_time => 3, remaining_time => 3, - see_also => 30, - target_milestone => 12, + target_milestone => 15, + longdesc => 25, + # Just the hour and minute. + FIELD_TYPE_DATETIME, -5, }; +# For most fields, we add the length of the name of the field plus +# the SUBSTR_SIZE specified above to determine how large of a substring +# we're going to use. However, for some fields, it doesn't make sense to +# add in their field name this way. +use constant SUBSTR_NO_FIELD_ADD => FIELD_TYPE_DATETIME, qw( + target_milestone remaining_time percentage_complete work_time + attachments.mimetype attachments.submitter attachments.filename + attachments.description flagtypes.name +); + ################ # Known Broken # ################ diff --git a/xt/lib/Bugzilla/Test/Search/FieldTest.pm b/xt/lib/Bugzilla/Test/Search/FieldTest.pm index b0307dec4a..940b482961 100644 --- a/xt/lib/Bugzilla/Test/Search/FieldTest.pm +++ b/xt/lib/Bugzilla/Test/Search/FieldTest.pm @@ -454,13 +454,27 @@ sub _translate_value_for_bug { sub _substr_value { my ($self, $value) = @_; my $field = $self->field; + my $type = $self->field_object->type; my $substr_size = SUBSTR_SIZE; if (exists FIELD_SUBSTR_SIZE->{$field}) { $substr_size = FIELD_SUBSTR_SIZE->{$field}; } - + elsif (exists FIELD_SUBSTR_SIZE->{$type}) { + $substr_size = FIELD_SUBSTR_SIZE->{$type}; + } if ($substr_size > 0) { - return substr($value, 0, $substr_size); + # The field name is included in every field value, and if it's + # long, it might take up the whole substring, and we don't want that. + if (!grep { $_ eq $field or $_ eq $type } SUBSTR_NO_FIELD_ADD) { + $substr_size += length($field); + } + my $string = substr($value, 0, $substr_size); + # Make percentage_complete substrings strings match integers uniquely, + # by searching for the full decimal number. + if ($field eq 'percentage_complete' and length($string) < $substr_size) { + $string .= ".000"; + } + return $string; } return substr($value, $substr_size); }