]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 579695: Make xt/search.t do substring tests using a more consistent
authorMax Kanat-Alexander <mkanat@bugzilla.org>
Sun, 18 Jul 2010 09:13:36 +0000 (02:13 -0700)
committerMax Kanat-Alexander <mkanat@bugzilla.org>
Sun, 18 Jul 2010 09:13:36 +0000 (02:13 -0700)
substring length, thus fixing an intermittent failure that would
show up when searching the cf_multi_select field.
r=mkanat, a=mkanat (module owner)

xt/lib/Bugzilla/Test/Search.pm
xt/lib/Bugzilla/Test/Search/Constants.pm
xt/lib/Bugzilla/Test/Search/FieldTest.pm

index af595e373c4b10bacd6e34b547f2ff622a9bd2d3..72c3828064d2f9cb4dd9a8f94ba0a03702888871 100644 (file)
@@ -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";
index 9b13e1a42974788e1a05e0ae82198775f3fbc4bb..7fe7d0efa4e1f98654bcb7dcf1a2851f4ec9beb8 100644 (file)
@@ -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 #
 ################
index b0307dec4a9e9ffc47c71850e543581e884c9bea..940b482961bcabbbed8e18a8f101fe9d4de45e18 100644 (file)
@@ -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);
 }