1#!/usr/bin/env vpython3 2# Copyright 2020 The Chromium Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import json 7import os 8from typing import Any, Dict, Set, Tuple 9import unittest 10from unittest import mock 11 12from pyfakefs import fake_filesystem_unittest 13 14from unexpected_passes_common import builders 15from unexpected_passes_common import constants 16from unexpected_passes_common import data_types 17from unexpected_passes_common import unittest_utils 18 19# Protected access is allowed for unittests. 20# pylint: disable=protected-access 21 22class FakeFilesystemTestCaseWithFileCreation(fake_filesystem_unittest.TestCase): 23 def CreateFile(self, *args, **kwargs): 24 # TODO(crbug.com/40160566): Remove this and just use fs.create_file() when 25 # Catapult is updated to a newer version of pyfakefs that is compatible with 26 # Chromium's version. 27 if hasattr(self.fs, 'create_file'): 28 self.fs.create_file(*args, **kwargs) 29 else: 30 self.fs.CreateFile(*args, **kwargs) 31 32 33class GetCiBuildersUnittest(FakeFilesystemTestCaseWithFileCreation): 34 def setUp(self) -> None: 35 self._builders_instance = unittest_utils.GenericBuilders( 36 suite='webgl_conformance') 37 self._isolate_patcher = mock.patch.object( 38 self._builders_instance, 39 'GetIsolateNames', 40 return_value={'telemetry_gpu_integration_test'}) 41 self._isolate_mock = self._isolate_patcher.start() 42 self.addCleanup(self._isolate_patcher.stop) 43 44 def testJsonContentLoaded(self) -> None: 45 """Tests that the correct JSON data is loaded in.""" 46 self.setUpPyfakefs() 47 gpu_json = { 48 'AAAAA1 AUTOGENERATED FILE DO NOT EDIT': {}, 49 'Android Release (Nexus 5X)': { 50 'isolated_scripts': [{ 51 'args': [ 52 'webgl_conformance', 53 ], 54 'isolate_name': 55 'telemetry_gpu_integration_test', 56 }], 57 }, 58 'GPU Linux Builder': {}, 59 } 60 gpu_fyi_json = { 61 'AAAAA1 AUTOGENERATED FILE DO NOT EDIT': {}, 62 'ANGLE GPU Android Release (Nexus 5X)': { 63 'isolated_scripts': [{ 64 'args': [ 65 'webgl_conformance', 66 ], 67 'isolate_name': 68 'telemetry_gpu_integration_test', 69 }], 70 }, 71 'GPU FYI Linux Builder': {}, 72 } 73 ci_infra_config_json = { 74 'Infra Config GPU': { 75 'isolated_scripts': [{ 76 'args': [ 77 'webgl_conformance', 78 ], 79 'isolate_name': 80 'telemetry_gpu_integration_test', 81 }], 82 }, 83 } 84 # Should be ignored. 85 tryserver_json = { 86 'AAAAA1 AUTOGENERATED FILE DO NOT EDIT': {}, 87 'Trybot': { 88 'isolated_scripts': [{ 89 'args': [ 90 'webgl_conformance', 91 ], 92 'isolate_name': 93 'telemetry_gpu_integration_test', 94 }], 95 }, 96 } 97 # Also should be ignored. 98 try_infra_config_json = { 99 'Infra Config Try': { 100 'isolated_scripts': [{ 101 'args': [ 102 'webgl_conformance', 103 ], 104 'isolate_name': 105 'telemetry_gpu_integration_test', 106 }], 107 }, 108 } 109 # Also should be ignored. 110 not_buildbot_json = { 111 'Not buildbot': { 112 'isolated_scripts': [{ 113 'args': [ 114 'webgl_conformance', 115 ], 116 'isolate_name': 117 'telemetry_gpu_integration_test', 118 }], 119 }, 120 } 121 122 self.CreateFile(os.path.join(builders.TESTING_BUILDBOT_DIR, 123 'chromium.gpu.json'), 124 contents=json.dumps(gpu_json)) 125 self.CreateFile(os.path.join(builders.TESTING_BUILDBOT_DIR, 126 'chromium.gpu.fyi.json'), 127 contents=json.dumps(gpu_fyi_json)) 128 self.CreateFile(os.path.join(builders.INFRA_CONFIG_BUILDERS_DIR, 'ci', 129 'Infra Config GPU', 'targets', 130 'infra.gpu.json'), 131 contents=json.dumps(ci_infra_config_json)) 132 self.CreateFile(os.path.join(builders.TESTING_BUILDBOT_DIR, 133 'tryserver.gpu.json'), 134 contents=json.dumps(tryserver_json)) 135 self.CreateFile(os.path.join(builders.INFRA_CONFIG_BUILDERS_DIR, 'try', 136 'Infra Config Try', 'targets', 137 'infra.gpu.json'), 138 contents=json.dumps(try_infra_config_json)) 139 self.CreateFile(os.path.join(builders.TESTING_BUILDBOT_DIR, 140 'not_buildbot.json'), 141 contents=json.dumps(not_buildbot_json)) 142 143 gpu_builders = self._builders_instance.GetCiBuilders() 144 self.assertEqual( 145 gpu_builders, 146 set([ 147 data_types.BuilderEntry('Android Release (Nexus 5X)', 148 constants.BuilderTypes.CI, False), 149 data_types.BuilderEntry('ANGLE GPU Android Release (Nexus 5X)', 150 constants.BuilderTypes.CI, False), 151 data_types.BuilderEntry('Infra Config GPU', 152 constants.BuilderTypes.CI, False), 153 data_types.BuilderEntry('GPU Linux Builder', 154 constants.BuilderTypes.CI, False), 155 data_types.BuilderEntry('GPU FYI Linux Builder', 156 constants.BuilderTypes.CI, False), 157 ])) 158 159 def testPublicInternalBuilders(self) -> None: 160 """Tests that public internal builders are treated as internal.""" 161 self.setUpPyfakefs() 162 gpu_json = { 163 'AAAAA1 AUTOGENERATED FILE DO NOT EDIT': {}, 164 'Android Release (Nexus 5X)': { 165 'isolated_scripts': [{ 166 'args': [ 167 'webgl_conformance', 168 ], 169 'isolate_name': 170 'telemetry_gpu_integration_test', 171 }], 172 }, 173 'GPU Linux Builder': {}, 174 } 175 gpu_internal_json = { 176 'AAAAA1 AUTOGENERATED FILE DO NOT EDIT': {}, 177 'Android Chrome Release (Nexus 5X)': { 178 'isolated_scripts': [{ 179 'args': [ 180 'webgl_conformance', 181 ], 182 'isolate_name': 183 'telemetry_gpu_integration_test', 184 }], 185 }, 186 'GPU Chrome Linux Builder': {}, 187 } 188 internal_json = { 189 'AAAAA1 AUTOGENERATED FILE DO NOT EDIT': {}, 190 'Android Internal Release (Nexus 5X)': { 191 'isolated_scripts': [{ 192 'args': [ 193 'webgl_conformance', 194 ], 195 'isolate_name': 196 'telemetry_gpu_integration_test', 197 }], 198 }, 199 'GPU Internal Linux Builder': {}, 200 } 201 internal_infra_config_json = { 202 'Infra Config Internal': { 203 'isolated_scripts': [{ 204 'args': [ 205 'webgl_conformance', 206 ], 207 'isolate_name': 208 'telemetry_gpu_integration_test', 209 }], 210 }, 211 } 212 213 self.CreateFile(os.path.join(builders.TESTING_BUILDBOT_DIR, 214 'chromium.gpu.json'), 215 contents=json.dumps(gpu_json)) 216 self.CreateFile(os.path.join(builders.TESTING_BUILDBOT_DIR, 217 'chrome.gpu.fyi.json'), 218 contents=json.dumps(gpu_internal_json)) 219 self.CreateFile(os.path.join(builders.INTERNAL_TESTING_BUILDBOT_DIR, 220 'internal.json'), 221 contents=json.dumps(internal_json)) 222 self.CreateFile(os.path.join(builders.INTERNAL_INFRA_CONFIG_BUILDERS_DIR, 223 'ci', 'Infra Config Internal', 'targets', 224 'infra.config.json'), 225 contents=json.dumps(internal_infra_config_json)) 226 227 # Dummy file so that pyfakefs doesn't complain when we check for public 228 # infra/config files. 229 self.CreateFile(os.path.join(builders.INFRA_CONFIG_BUILDERS_DIR, 'ci', 230 'Fake', 'targets', 'fake.json'), 231 contents=json.dumps({})) 232 233 gpu_builders = self._builders_instance.GetCiBuilders() 234 self.assertEqual( 235 gpu_builders, 236 set([ 237 data_types.BuilderEntry('Android Release (Nexus 5X)', 238 constants.BuilderTypes.CI, False), 239 data_types.BuilderEntry('GPU Linux Builder', 240 constants.BuilderTypes.CI, False), 241 ])) 242 243 internal_instance = unittest_utils.GenericBuilders( 244 suite='webgl_conformance', include_internal_builders=True) 245 with mock.patch.object(internal_instance, 246 'GetIsolateNames', 247 return_value={'telemetry_gpu_integration_test'}): 248 gpu_builders = internal_instance.GetCiBuilders() 249 self.assertEqual( 250 gpu_builders, 251 set([ 252 data_types.BuilderEntry('Android Release (Nexus 5X)', 253 constants.BuilderTypes.CI, False), 254 data_types.BuilderEntry('Android Chrome Release (Nexus 5X)', 255 constants.BuilderTypes.CI, True), 256 data_types.BuilderEntry('Android Internal Release (Nexus 5X)', 257 constants.BuilderTypes.CI, True), 258 data_types.BuilderEntry('GPU Linux Builder', 259 constants.BuilderTypes.CI, False), 260 data_types.BuilderEntry('GPU Chrome Linux Builder', 261 constants.BuilderTypes.CI, True), 262 data_types.BuilderEntry('GPU Internal Linux Builder', 263 constants.BuilderTypes.CI, True), 264 data_types.BuilderEntry('Infra Config Internal', 265 constants.BuilderTypes.CI, True) 266 ])) 267 268 def testFilterBySuite(self) -> None: 269 """Tests that only builders that run the given suite are returned.""" 270 271 def SideEffect(tm: Dict[str, Any]) -> bool: 272 tests = tm.get('isolated_scripts', []) 273 for t in tests: 274 if t.get('isolate_name') == 'foo_integration_test': 275 if 'webgl_conformance' in t.get('args', []): 276 return True 277 return False 278 279 self.setUpPyfakefs() 280 gpu_json = { 281 'AAAAA1 AUTOGENERATED FILE DO NOT EDIT': {}, 282 'Android Tester': { 283 'isolated_scripts': [ 284 { 285 'args': [ 286 'webgl_conformance', 287 ], 288 'isolate_name': 'not_telemetry', 289 }, 290 ], 291 }, 292 'Linux Tester': { 293 'isolated_scripts': [ 294 { 295 'args': [ 296 'not_a_suite', 297 ], 298 'isolate_name': 'foo_integration_test', 299 }, 300 ], 301 }, 302 'Windows Tester': { 303 'isolated_scripts': [ 304 { 305 'args': [ 306 'webgl_conformance', 307 ], 308 'isolate_name': 'foo_integration_test', 309 }, 310 ], 311 }, 312 } 313 matching_infra_config_json = { 314 'Matching Infra Config': { 315 'isolated_scripts': [ 316 { 317 'args': [ 318 'webgl_conformance', 319 ], 320 'isolate_name': 'foo_integration_test', 321 }, 322 ], 323 }, 324 } 325 not_matching_infra_config_json = { 326 'Not Matching Infra Config': { 327 'isolated_scripts': [ 328 { 329 'args': [ 330 'not_a_suite', 331 ], 332 'isolate_name': 'foo_integration_test', 333 }, 334 ], 335 }, 336 } 337 338 self.CreateFile(os.path.join(builders.TESTING_BUILDBOT_DIR, 339 'chromium.json'), 340 contents=json.dumps(gpu_json)) 341 self.CreateFile(os.path.join(builders.INFRA_CONFIG_BUILDERS_DIR, 'ci', 342 'Matching Infra Config', 'targets', 343 'infra.config.json'), 344 contents=json.dumps(matching_infra_config_json)) 345 self.CreateFile(os.path.join(builders.INFRA_CONFIG_BUILDERS_DIR, 'ci', 346 'Not Matching Infra Config', 'targets', 347 'infra.config.json'), 348 contents=json.dumps(not_matching_infra_config_json)) 349 350 with mock.patch.object(self._builders_instance, 351 '_BuilderRunsTestOfInterest', 352 side_effect=SideEffect): 353 gpu_builders = self._builders_instance.GetCiBuilders() 354 self.assertEqual( 355 gpu_builders, { 356 data_types.BuilderEntry('Windows Tester', constants.BuilderTypes.CI, 357 False), 358 data_types.BuilderEntry('Matching Infra Config', 359 constants.BuilderTypes.CI, False), 360 }) 361 362 def testRealContentCanBeLoaded(self) -> None: 363 """Tests that *something* from the real JSON files can be loaded.""" 364 # This directory is not available on swarming, so if it doesn't exist, just 365 # skip the test. 366 if not os.path.exists(builders.TESTING_BUILDBOT_DIR): 367 return 368 self.assertNotEqual(len(self._builders_instance.GetCiBuilders()), 0) 369 370 371class GetMirroredBuildersForCiBuilderUnittest(unittest.TestCase): 372 def setUp(self) -> None: 373 self._builders_instance = builders.Builders('suite', False) 374 self._bb_patcher = mock.patch.object(self._builders_instance, 375 '_GetBuildbucketOutputForCiBuilder') 376 self._bb_mock = self._bb_patcher.start() 377 self.addCleanup(self._bb_patcher.stop) 378 self._fake_ci_patcher = mock.patch.object(self._builders_instance, 379 'GetFakeCiBuilders', 380 return_value={}) 381 self._fake_ci_mock = self._fake_ci_patcher.start() 382 self.addCleanup(self._fake_ci_patcher.stop) 383 self._non_chromium_patcher = mock.patch.object( 384 self._builders_instance, 385 'GetNonChromiumBuilders', 386 return_value={'foo_non_chromium'}) 387 self._non_chromium_mock = self._non_chromium_patcher.start() 388 self.addCleanup(self._non_chromium_patcher.stop) 389 390 def testFakeCiBuilder(self) -> None: 391 """Tests that a fake CI builder gets properly mapped.""" 392 self._fake_ci_mock.return_value = { 393 data_types.BuilderEntry('foo_ci', constants.BuilderTypes.CI, False): 394 {data_types.BuilderEntry('foo_try', constants.BuilderTypes.TRY, False)} 395 } 396 try_builder, found_mirror = ( 397 self._builders_instance._GetMirroredBuildersForCiBuilder( 398 data_types.BuilderEntry('foo_ci', constants.BuilderTypes.CI, 399 False))) 400 self.assertTrue(found_mirror) 401 self.assertEqual( 402 try_builder, 403 set([ 404 data_types.BuilderEntry('foo_try', constants.BuilderTypes.TRY, 405 False) 406 ])) 407 self._bb_mock.assert_not_called() 408 409 def testNoBuildbucketOutput(self) -> None: 410 """Tests that a failure to get Buildbucket output is surfaced.""" 411 self._bb_mock.return_value = '' 412 builder_entry = data_types.BuilderEntry('nonexistent', 413 constants.BuilderTypes.CI, False) 414 try_builder, found_mirror = ( 415 self._builders_instance._GetMirroredBuildersForCiBuilder(builder_entry)) 416 self.assertFalse(found_mirror) 417 self.assertEqual(try_builder, set([builder_entry])) 418 419 def testBuildbucketOutput(self): 420 """Tests that Buildbucket output is parsed correctly.""" 421 self._bb_mock.return_value = json.dumps({ 422 'output': { 423 'properties': { 424 'mirrored_builders': [ 425 'try:foo_try', 426 'try:bar_try', 427 ] 428 } 429 } 430 }) 431 try_builders, found_mirror = ( 432 self._builders_instance._GetMirroredBuildersForCiBuilder( 433 data_types.BuilderEntry('foo_ci', constants.BuilderTypes.CI, 434 False))) 435 self.assertTrue(found_mirror) 436 self.assertEqual( 437 try_builders, 438 set([ 439 data_types.BuilderEntry('foo_try', constants.BuilderTypes.TRY, 440 False), 441 data_types.BuilderEntry('bar_try', constants.BuilderTypes.TRY, 442 False) 443 ])) 444 445 def testBuildbucketOutputInternal(self) -> None: 446 """Tests that internal Buildbucket output is parsed correctly.""" 447 self._bb_mock.return_value = json.dumps({ 448 'output': { 449 'properties': { 450 'mirrored_builders': [ 451 'try:foo_try', 452 'try:bar_try', 453 ] 454 } 455 } 456 }) 457 try_builders, found_mirror = ( 458 self._builders_instance._GetMirroredBuildersForCiBuilder( 459 data_types.BuilderEntry('foo_ci', constants.BuilderTypes.CI, True))) 460 self.assertTrue(found_mirror) 461 self.assertEqual( 462 try_builders, 463 set([ 464 data_types.BuilderEntry('foo_try', constants.BuilderTypes.TRY, 465 True), 466 data_types.BuilderEntry('bar_try', constants.BuilderTypes.TRY, True) 467 ])) 468 469 470class GetTryBuildersUnittest(FakeFilesystemTestCaseWithFileCreation): 471 def setUp(self) -> None: 472 self._builders_instance = builders.Builders('suite', False) 473 self._get_patcher = mock.patch.object(self._builders_instance, 474 '_GetMirroredBuildersForCiBuilder') 475 self._get_mock = self._get_patcher.start() 476 self.addCleanup(self._get_patcher.stop) 477 self._runs_test_patcher = mock.patch.object(self._builders_instance, 478 '_BuilderRunsTestOfInterest') 479 self._runs_test_mock = self._runs_test_patcher.start() 480 self.addCleanup(self._runs_test_patcher.stop) 481 482 self.setUpPyfakefs() 483 # Make sure the directory exists. 484 self.CreateFile( 485 os.path.join(builders.TESTING_BUILDBOT_DIR, 'placeholder.txt')) 486 487 def testMirrorNoOutputCausesFailure(self) -> None: 488 """Tests that a failure to get Buildbot output raises an exception.""" 489 # Create a dummy file so that pyfakefs does not complain about a directory 490 # not existing. 491 self.CreateFile(os.path.join(builders.INFRA_CONFIG_BUILDERS_DIR, 'try', 492 'Fake', 'targets', 'fake.json'), 493 contents=json.dumps({})) 494 builder = data_types.BuilderEntry('foo_ci', constants.BuilderTypes.CI, 495 False) 496 self._get_mock.return_value = (set([builder]), False) 497 self._runs_test_mock.return_value = True 498 with self.assertRaises(RuntimeError): 499 self._builders_instance.GetTryBuilders([builder]) 500 501 def testMirrorOutputReturned(self) -> None: 502 """Tests that parsed, mirrored builders get returned on success.""" 503 504 def SideEffect(ci_builder: data_types.BuilderEntry 505 ) -> Tuple[Set[data_types.BuilderEntry], bool]: 506 b = [ 507 data_types.BuilderEntry(ci_builder.name.replace('ci', 'try'), 508 constants.BuilderTypes.TRY, False), 509 data_types.BuilderEntry(ci_builder.name.replace('ci', 'try2'), 510 constants.BuilderTypes.TRY, False), 511 ] 512 return set(b), True 513 514 # Create a dummy file so that pyfakefs does not complain about a directory 515 # not existing. 516 self.CreateFile(os.path.join(builders.INFRA_CONFIG_BUILDERS_DIR, 'try', 517 'Fake', 'targets', 'fake.json'), 518 contents=json.dumps({})) 519 520 self._get_mock.side_effect = SideEffect 521 self._runs_test_mock.return_value = False 522 mirrored_builders = self._builders_instance.GetTryBuilders([ 523 data_types.BuilderEntry('foo_ci', constants.BuilderTypes.CI, False), 524 data_types.BuilderEntry('bar_ci', constants.BuilderTypes.CI, False), 525 ]) 526 self.assertEqual( 527 mirrored_builders, 528 set([ 529 data_types.BuilderEntry('foo_try', constants.BuilderTypes.TRY, 530 False), 531 data_types.BuilderEntry('foo_try2', constants.BuilderTypes.TRY, 532 False), 533 data_types.BuilderEntry('bar_try', constants.BuilderTypes.TRY, 534 False), 535 data_types.BuilderEntry('bar_try2', constants.BuilderTypes.TRY, 536 False), 537 ])) 538 539 def testDedicatedJsonContentLoaded(self) -> None: 540 """Tests that tryserver JSON content is loaded.""" 541 542 def SideEffect(test_spec: Dict[str, Any]) -> bool: 543 # Treat non-empty test specs as valid. 544 return bool(test_spec) 545 546 self._runs_test_mock.side_effect = SideEffect 547 # Should be ignored. 548 gpu_json = { 549 'AAAAA1 AUTOGENERATED FILE DO NOT EDIT': {}, 550 'Android Release (Nexus 5X)': { 551 'isolated_scripts': [{ 552 'args': [ 553 'webgl_conformance', 554 ], 555 'isolate_name': 556 'telemetry_gpu_integration_test', 557 }], 558 }, 559 'GPU Linux Builder': {}, 560 } 561 # Should be ignored. 562 gpu_fyi_json = { 563 'AAAAA1 AUTOGENERATED FILE DO NOT EDIT': {}, 564 'ANGLE GPU Android Release (Nexus 5X)': { 565 'isolated_scripts': [{ 566 'args': [ 567 'webgl_conformance', 568 ], 569 'isolate_name': 570 'telemetry_gpu_integration_test', 571 }], 572 }, 573 'GPU FYI Linux Builder': {}, 574 } 575 # Also should be ignored. 576 ci_infra_config_json = { 577 'CI Infra Config': { 578 'isolated_scripts': [{ 579 'args': [ 580 'webgl_conformance', 581 ], 582 'isolate_name': 583 'telemetry_gpu_integration_test', 584 }], 585 }, 586 } 587 tryserver_json = { 588 'AAAAA1 AUTOGENERATED FILE DO NOT EDIT': {}, 589 'Trybot': { 590 'isolated_scripts': [{ 591 'args': [ 592 'webgl_conformance', 593 ], 594 'isolate_name': 595 'telemetry_gpu_integration_test', 596 }], 597 }, 598 'Trybot Empty': {}, 599 } 600 try_infra_config_json = { 601 'Mirrored CI Infra Config': { 602 'isolated_scripts': [{ 603 'args': [ 604 'webgl_conformance', 605 ], 606 'isolate_name': 607 'telemetry_gpu_integration_test', 608 }], 609 }, 610 } 611 # Also should be ignored. 612 not_buildbot_json = { 613 'Not buildbot': { 614 'isolated_scripts': [{ 615 'args': [ 616 'webgl_conformance', 617 ], 618 'isolate_name': 619 'telemetry_gpu_integration_test', 620 }], 621 }, 622 } 623 624 self.CreateFile(os.path.join(builders.TESTING_BUILDBOT_DIR, 625 'chromium.gpu.json'), 626 contents=json.dumps(gpu_json)) 627 self.CreateFile(os.path.join(builders.TESTING_BUILDBOT_DIR, 628 'chromium.gpu.fyi.json'), 629 contents=json.dumps(gpu_fyi_json)) 630 self.CreateFile(os.path.join(builders.INFRA_CONFIG_BUILDERS_DIR, 'ci', 631 'CI Infra Config', 'targets', 632 'infra.config.json'), 633 contents=json.dumps(ci_infra_config_json)) 634 self.CreateFile(os.path.join(builders.TESTING_BUILDBOT_DIR, 635 'tryserver.gpu.json'), 636 contents=json.dumps(tryserver_json)) 637 self.CreateFile(os.path.join(builders.INFRA_CONFIG_BUILDERS_DIR, 'try', 638 'Try Infra Config', 'targets', 639 'infra.config.json'), 640 contents=json.dumps(try_infra_config_json)) 641 self.CreateFile(os.path.join(builders.TESTING_BUILDBOT_DIR, 642 'not_buildbot.json'), 643 contents=json.dumps(not_buildbot_json)) 644 645 gpu_builders = self._builders_instance.GetTryBuilders({}) 646 self.assertEqual( 647 gpu_builders, { 648 data_types.BuilderEntry('Trybot', constants.BuilderTypes.TRY, 649 False), 650 data_types.BuilderEntry('Try Infra Config', 651 constants.BuilderTypes.TRY, False), 652 }) 653 654 def testDedicatedFilterBySuite(self) -> None: 655 """Tests that only builders that run the given suite are returned.""" 656 657 def SideEffect(tm: Dict[str, Any]) -> bool: 658 tests = tm.get('isolated_scripts', []) 659 for t in tests: 660 if t.get('isolate_name') == 'foo_integration_test': 661 if 'webgl_conformance' in t.get('args', []): 662 return True 663 return False 664 665 self._runs_test_mock.side_effect = SideEffect 666 gpu_json = { 667 'AAAAA1 AUTOGENERATED FILE DO NOT EDIT': {}, 668 'Android Tester': { 669 'isolated_scripts': [ 670 { 671 'args': [ 672 'webgl_conformance', 673 ], 674 'isolate_name': 'not_telemetry', 675 }, 676 ], 677 }, 678 'Linux Tester': { 679 'isolated_scripts': [ 680 { 681 'args': [ 682 'not_a_suite', 683 ], 684 'isolate_name': 'foo_integration_test', 685 }, 686 ], 687 }, 688 'Windows Tester': { 689 'isolated_scripts': [ 690 { 691 'args': [ 692 'webgl_conformance', 693 ], 694 'isolate_name': 'foo_integration_test', 695 }, 696 ], 697 }, 698 } 699 matching_infra_config_json = { 700 'Matching Infra Config Mirrored CI': { 701 'isolated_scripts': [ 702 { 703 'args': [ 704 'webgl_conformance', 705 ], 706 'isolate_name': 'foo_integration_test', 707 }, 708 ], 709 }, 710 } 711 not_matching_infra_config_json = { 712 'Not Matching Infra Config': { 713 'isolated_scripts': [ 714 { 715 'args': [ 716 'not_a_suite', 717 ], 718 'isolate_name': 'foo_integration_test', 719 }, 720 ], 721 }, 722 } 723 724 self.CreateFile(os.path.join(builders.TESTING_BUILDBOT_DIR, 725 'tryserver.chromium.json'), 726 contents=json.dumps(gpu_json)) 727 self.CreateFile(os.path.join(builders.INFRA_CONFIG_BUILDERS_DIR, 'try', 728 'Matching Infra Config', 'targets', 729 'infra.config.json'), 730 contents=json.dumps(matching_infra_config_json)) 731 self.CreateFile(os.path.join(builders.INFRA_CONFIG_BUILDERS_DIR, 'try', 732 'Not Matching Infra Config', 'targets', 733 'infra.config.json'), 734 contents=json.dumps(not_matching_infra_config_json)) 735 736 737 gpu_builders = self._builders_instance.GetTryBuilders({}) 738 self.assertEqual( 739 gpu_builders, { 740 data_types.BuilderEntry('Windows Tester', 741 constants.BuilderTypes.TRY, False), 742 data_types.BuilderEntry('Matching Infra Config', 743 constants.BuilderTypes.TRY, False), 744 }) 745 746 def testDedicatedAndMirroredCombined(self) -> None: 747 """Tests that both dedicated and mirrored trybots are returned.""" 748 749 def SideEffect(_: Any) -> Tuple[Set[data_types.BuilderEntry], bool]: 750 return set({ 751 data_types.BuilderEntry('mirrored_trybot', constants.BuilderTypes.TRY, 752 False) 753 }), True 754 755 self._get_mock.side_effect = SideEffect 756 self._runs_test_mock.return_value = True 757 tryserver_json = { 758 'AAAAA1 AUTOGENERATED FILE DO NOT EDIT': {}, 759 'Trybot': { 760 'isolated_scripts': [{ 761 'args': [ 762 'webgl_conformance', 763 ], 764 'isolate_name': 765 'telemetry_gpu_integration_test', 766 }], 767 }, 768 } 769 infra_config_json = { 770 'Infra Config Mirrored CI': { 771 'isolated_scripts': [{ 772 'args': [ 773 'webgl_conformance', 774 ], 775 'isolate_name': 776 'telemetry_gpu_integration_test', 777 }], 778 }, 779 } 780 781 self.CreateFile(os.path.join(builders.TESTING_BUILDBOT_DIR, 782 'tryserver.chromium.json'), 783 contents=json.dumps(tryserver_json)) 784 self.CreateFile(os.path.join(builders.INFRA_CONFIG_BUILDERS_DIR, 'try', 785 'Infra Config', 'targets', 786 'infra.config.json'), 787 contents=json.dumps(infra_config_json)) 788 789 try_builders = self._builders_instance.GetTryBuilders({ 790 data_types.BuilderEntry('ci_builder', constants.BuilderTypes.CI, False) 791 }) 792 self.assertEqual( 793 try_builders, { 794 data_types.BuilderEntry('mirrored_trybot', 795 constants.BuilderTypes.TRY, False), 796 data_types.BuilderEntry('Trybot', constants.BuilderTypes.TRY, 797 False), 798 data_types.BuilderEntry('Infra Config', constants.BuilderTypes.TRY, 799 False), 800 }) 801 802 803if __name__ == '__main__': 804 unittest.main(verbosity=2) 805