go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/internal/services/resultingester/test_data.go (about) 1 // Copyright 2022 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package resultingester 16 17 import ( 18 "time" 19 20 "google.golang.org/protobuf/types/known/durationpb" 21 "google.golang.org/protobuf/types/known/structpb" 22 "google.golang.org/protobuf/types/known/timestamppb" 23 24 gerritpb "go.chromium.org/luci/common/proto/gerrit" 25 "go.chromium.org/luci/common/proto/mask" 26 "go.chromium.org/luci/resultdb/pbutil" 27 rdbpb "go.chromium.org/luci/resultdb/proto/v1" 28 ) 29 30 var sampleVar = pbutil.Variant("k1", "v1") 31 32 var originalTmd = &rdbpb.TestMetadata{ 33 Name: "original_name", 34 Location: &rdbpb.TestLocation{ 35 Repo: "old_repo", 36 FileName: "old_file_name", 37 Line: 567, 38 }, 39 BugComponent: &rdbpb.BugComponent{ 40 System: &rdbpb.BugComponent_Monorail{ 41 Monorail: &rdbpb.MonorailComponent{ 42 Project: "chrome", 43 Value: "Blink>Component", 44 }, 45 }, 46 }, 47 } 48 49 var updatedTmd = &rdbpb.TestMetadata{ 50 Name: "updated_name", 51 Location: &rdbpb.TestLocation{ 52 Repo: "repo", 53 FileName: "file_name", 54 Line: 456, 55 }, 56 BugComponent: &rdbpb.BugComponent{ 57 System: &rdbpb.BugComponent_IssueTracker{ 58 IssueTracker: &rdbpb.IssueTrackerComponent{ 59 ComponentId: 12345, 60 }, 61 }, 62 }, 63 } 64 65 var testProperties = &structpb.Struct{ 66 Fields: map[string]*structpb.Value{ 67 "stringkey": structpb.NewStringValue("stringvalue"), 68 "numberkey": structpb.NewNumberValue(123), 69 }, 70 } 71 72 func mockedQueryTestVariantsRsp() *rdbpb.QueryTestVariantsResponse { 73 response := &rdbpb.QueryTestVariantsResponse{ 74 TestVariants: []*rdbpb.TestVariant{ 75 { 76 TestId: "ninja://test_consistent_failure", 77 VariantHash: "hash", 78 Status: rdbpb.TestVariantStatus_EXONERATED, 79 Exonerations: []*rdbpb.TestExoneration{ 80 // Test behaviour in the presence of multiple exoneration reasons. 81 { 82 ExplanationHtml: "LUCI Analysis reported this test as flaky.", 83 Reason: rdbpb.ExonerationReason_OCCURS_ON_OTHER_CLS, 84 }, 85 { 86 ExplanationHtml: "Test is marked informational.", 87 Reason: rdbpb.ExonerationReason_NOT_CRITICAL, 88 }, 89 { 90 Reason: rdbpb.ExonerationReason_OCCURS_ON_MAINLINE, 91 }, 92 }, 93 Results: []*rdbpb.TestResultBundle{ 94 { 95 Result: &rdbpb.TestResult{ 96 ResultId: "one", 97 Name: "invocations/build-1234/tests/ninja%3A%2F%2Ftest_consistent_failure/results/one", 98 Expected: false, 99 Status: rdbpb.TestStatus_FAIL, 100 SummaryHtml: "SummaryHTML", 101 StartTime: timestamppb.New(time.Date(2010, time.March, 1, 0, 0, 0, 0, time.UTC)), 102 Duration: durationpb.New(time.Second*3 + time.Microsecond), 103 FailureReason: &rdbpb.FailureReason{ 104 PrimaryErrorMessage: "abc.def(123): unexpected nil-deference", 105 }, 106 Properties: testProperties, 107 }, 108 }, 109 }, 110 SourcesId: "sources1", 111 }, 112 { 113 TestId: "ninja://test_expected", 114 VariantHash: "hash", 115 Status: rdbpb.TestVariantStatus_EXPECTED, 116 Results: []*rdbpb.TestResultBundle{ 117 { 118 Result: &rdbpb.TestResult{ 119 ResultId: "one", 120 Name: "invocations/build-1234/tests/ninja%3A%2F%2Ftest_expected/results/one", 121 StartTime: timestamppb.New(time.Date(2010, time.May, 1, 0, 0, 0, 0, time.UTC)), 122 Status: rdbpb.TestStatus_PASS, 123 Expected: true, 124 Duration: durationpb.New(time.Second * 5), 125 }, 126 }, 127 }, 128 }, 129 { 130 TestId: "ninja://test_filtering_event", 131 VariantHash: "hash", 132 Status: rdbpb.TestVariantStatus_EXPECTED, 133 Results: []*rdbpb.TestResultBundle{ 134 { 135 Result: &rdbpb.TestResult{ 136 ResultId: "one", 137 Name: "invocations/build-1234/tests/ninja%3A%2F%2Ftest_filtering_event/results/one", 138 StartTime: timestamppb.New(time.Date(2010, time.February, 2, 0, 0, 0, 0, time.UTC)), 139 Status: rdbpb.TestStatus_SKIP, 140 SkipReason: rdbpb.SkipReason_AUTOMATICALLY_DISABLED_FOR_FLAKINESS, 141 Expected: true, 142 }, 143 }, 144 }, 145 }, 146 { 147 TestId: "ninja://test_from_luci_bisection", 148 VariantHash: "hash", 149 Status: rdbpb.TestVariantStatus_UNEXPECTED, 150 Results: []*rdbpb.TestResultBundle{ 151 { 152 Result: &rdbpb.TestResult{ 153 ResultId: "one", 154 Name: "invocations/build-1234/tests/ninja%3A%2F%2Ftest_from_luci_bisection/results/one", 155 Status: rdbpb.TestStatus_PASS, 156 Expected: false, 157 Tags: pbutil.StringPairs("is_luci_bisection", "true"), 158 }, 159 }, 160 }, 161 }, 162 { 163 TestId: "ninja://test_has_unexpected", 164 VariantHash: "hash", 165 Status: rdbpb.TestVariantStatus_FLAKY, 166 Results: []*rdbpb.TestResultBundle{ 167 { 168 Result: &rdbpb.TestResult{ 169 ResultId: "one", 170 Name: "invocations/invocation-0b/tests/ninja%3A%2F%2Ftest_has_unexpected/results/one", 171 StartTime: timestamppb.New(time.Date(2010, time.February, 1, 0, 0, 10, 0, time.UTC)), 172 Status: rdbpb.TestStatus_FAIL, 173 Expected: false, 174 }, 175 }, 176 { 177 Result: &rdbpb.TestResult{ 178 ResultId: "two", 179 Name: "invocations/invocation-0a/tests/ninja%3A%2F%2Ftest_has_unexpected/results/two", 180 StartTime: timestamppb.New(time.Date(2010, time.February, 1, 0, 0, 20, 0, time.UTC)), 181 Status: rdbpb.TestStatus_PASS, 182 Expected: true, 183 }, 184 }, 185 }, 186 }, 187 { 188 TestId: "ninja://test_known_flake", 189 VariantHash: "hash_2", 190 Status: rdbpb.TestVariantStatus_UNEXPECTED, 191 Variant: pbutil.Variant("k1", "v2"), 192 TestMetadata: updatedTmd, 193 Results: []*rdbpb.TestResultBundle{ 194 { 195 Result: &rdbpb.TestResult{ 196 ResultId: "one", 197 Name: "invocations/build-1234/tests/ninja%3A%2F%2Ftest_known_flake/results/one", 198 StartTime: timestamppb.New(time.Date(2010, time.February, 1, 0, 0, 0, 0, time.UTC)), 199 Status: rdbpb.TestStatus_FAIL, 200 Expected: false, 201 Duration: durationpb.New(time.Second * 2), 202 Tags: pbutil.StringPairs("os", "Mac", "monorail_component", "Monorail>Component"), 203 }, 204 }, 205 }, 206 }, 207 { 208 TestId: "ninja://test_new_failure", 209 VariantHash: "hash_1", 210 Status: rdbpb.TestVariantStatus_UNEXPECTED, 211 Variant: pbutil.Variant("k1", "v1"), 212 TestMetadata: updatedTmd, 213 Results: []*rdbpb.TestResultBundle{ 214 { 215 Result: &rdbpb.TestResult{ 216 ResultId: "one", 217 Name: "invocations/build-1234/tests/ninja%3A%2F%2Ftest_new_failure/results/one", 218 StartTime: timestamppb.New(time.Date(2010, time.January, 1, 0, 0, 0, 0, time.UTC)), 219 Status: rdbpb.TestStatus_FAIL, 220 Expected: false, 221 Duration: durationpb.New(time.Second * 1), 222 Tags: pbutil.StringPairs("random_tag", "random_tag_value", "public_buganizer_component", "951951951"), 223 }, 224 }, 225 }, 226 }, 227 { 228 TestId: "ninja://test_new_flake", 229 VariantHash: "hash", 230 Status: rdbpb.TestVariantStatus_FLAKY, 231 Results: []*rdbpb.TestResultBundle{ 232 { 233 Result: &rdbpb.TestResult{ 234 ResultId: "two", 235 Name: "invocations/invocation-1234/tests/ninja%3A%2F%2Ftest_new_flake/results/two", 236 StartTime: timestamppb.New(time.Date(2010, time.January, 1, 0, 0, 20, 0, time.UTC)), 237 Status: rdbpb.TestStatus_FAIL, 238 Expected: false, 239 Duration: durationpb.New(time.Second * 11), 240 }, 241 }, 242 { 243 Result: &rdbpb.TestResult{ 244 ResultId: "one", 245 Name: "invocations/invocation-1234/tests/ninja%3A%2F%2Ftest_new_flake/results/one", 246 StartTime: timestamppb.New(time.Date(2010, time.January, 1, 0, 0, 10, 0, time.UTC)), 247 Status: rdbpb.TestStatus_FAIL, 248 Expected: false, 249 Duration: durationpb.New(time.Second * 10), 250 }, 251 }, 252 { 253 Result: &rdbpb.TestResult{ 254 ResultId: "three", 255 Name: "invocations/invocation-4567/tests/ninja%3A%2F%2Ftest_new_flake/results/three", 256 StartTime: timestamppb.New(time.Date(2010, time.January, 1, 0, 0, 15, 0, time.UTC)), 257 Status: rdbpb.TestStatus_PASS, 258 Expected: true, 259 Duration: durationpb.New(time.Second * 12), 260 }, 261 }, 262 }, 263 }, 264 { 265 TestId: "ninja://test_no_new_results", 266 VariantHash: "hash", 267 Status: rdbpb.TestVariantStatus_UNEXPECTED, 268 Results: []*rdbpb.TestResultBundle{ 269 { 270 Result: &rdbpb.TestResult{ 271 ResultId: "one", 272 Name: "invocations/build-1234/tests/ninja%3A%2F%2Ftest_no_new_results/results/one", 273 StartTime: timestamppb.New(time.Date(2010, time.April, 1, 0, 0, 0, 0, time.UTC)), 274 Status: rdbpb.TestStatus_FAIL, 275 Expected: false, 276 Duration: durationpb.New(time.Second * 4), 277 }, 278 }, 279 }, 280 }, 281 { 282 TestId: "ninja://test_skip", 283 VariantHash: "hash", 284 Status: rdbpb.TestVariantStatus_UNEXPECTEDLY_SKIPPED, 285 Results: []*rdbpb.TestResultBundle{ 286 { 287 Result: &rdbpb.TestResult{ 288 ResultId: "one", 289 Name: "invocations/build-1234/tests/ninja%3A%2F%2Ftest_skip/results/one", 290 StartTime: timestamppb.New(time.Date(2010, time.February, 2, 0, 0, 0, 0, time.UTC)), 291 Status: rdbpb.TestStatus_SKIP, 292 Expected: false, 293 }, 294 }, 295 }, 296 }, 297 { 298 TestId: "ninja://test_unexpected_pass", 299 VariantHash: "hash", 300 Status: rdbpb.TestVariantStatus_UNEXPECTED, 301 Results: []*rdbpb.TestResultBundle{ 302 { 303 Result: &rdbpb.TestResult{ 304 ResultId: "one", 305 Name: "invocations/build-1234/tests/ninja%3A%2F%2Ftest_unexpected_pass/results/one", 306 Status: rdbpb.TestStatus_PASS, 307 Expected: false, 308 }, 309 }, 310 }, 311 }, 312 }, 313 Sources: map[string]*rdbpb.Sources{ 314 "sources1": { 315 GitilesCommit: &rdbpb.GitilesCommit{ 316 Host: "project.googlesource.com", 317 Project: "myproject/src", 318 Ref: "refs/heads/main", 319 CommitHash: "abcdefabcd1234567890abcdefabcd1234567890", 320 Position: 16801, 321 }, 322 Changelists: []*rdbpb.GerritChange{ 323 { 324 Host: "project-review.googlesource.com", 325 Project: "myproject/src2", 326 Change: 9991, 327 Patchset: 82, 328 }, 329 }, 330 IsDirty: false, 331 }, 332 }, 333 } 334 335 isFieldNameJSON := false 336 isUpdateMask := false 337 m, err := mask.FromFieldMask(testVariantReadMask, &rdbpb.TestVariant{}, isFieldNameJSON, isUpdateMask) 338 if err != nil { 339 panic(err) 340 } 341 for _, tv := range response.TestVariants { 342 if err := m.Trim(tv); err != nil { 343 panic(err) 344 } 345 } 346 return response 347 } 348 349 func gerritChangesByHostForTesting() map[string][]*gerritpb.ChangeInfo { 350 result := make(map[string][]*gerritpb.ChangeInfo) 351 result["project-review.googlesource.com"] = []*gerritpb.ChangeInfo{ 352 { 353 Number: 9991, 354 Project: "myproject/src2", 355 Owner: &gerritpb.AccountInfo{ 356 Email: "username@chromium.org", 357 }, 358 }, 359 } 360 return result 361 }