forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shard_util_test.py
executable file
·62 lines (52 loc) · 2.05 KB
/
shard_util_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env vpython3
# Copyright 2020 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import collections
from mock import patch
import os
import unittest
import shard_util
# example output of
# xcodebuild_runner.SimulatorParallelTestRunner.fetch_test_names
_EXAMPLE_FETCH_TEST_NAMES_RESPONSE = [
('CacheTestCase', 'testA'),
('CacheTestCase', 'testB'),
('CacheTestCase', 'testC'),
('TabUITestCase', 'testD'),
('TabUITestCase', 'testE'),
('KeyboardTestCase', 'testF'),
('PasswordManagerTestCase', 'testG'),
('ToolBarTestCase', 'testH'),
# in this scenario PasswordManagerPasswordCheckupDisabledTestCase inherits
# from PasswordManagerTestCase so it will run testG
('PasswordManagerPasswordCheckupDisabledTestCase', 'testI'),
('PasswordManagerPasswordCheckupDisabledTestCase', 'testG'),
]
class TestShardUtil(unittest.TestCase):
"""Test cases for shard_util.py"""
def test_balance_into_sublists_debug(self):
"""Ensure the balancing algorithm works"""
test_cases = [
test_case for (test_case, _) in _EXAMPLE_FETCH_TEST_NAMES_RESPONSE
]
test_counts = collections.Counter(test_cases)
sublists_1 = shard_util.balance_into_sublists(test_counts, 1)
self.assertEqual(len(sublists_1), 1)
self.assertEqual(len(sublists_1[0]), 6)
sublists_3 = shard_util.balance_into_sublists(test_counts, 3)
self.assertEqual(len(sublists_3), 3)
# CacheTestCase has 3,
# TabUITestCase has 2, ToolBarTestCase has 1
# PasswordManagerTestCase has 2, KeyboardTestCase has 1
# PasswordManagerPasswordCheckupDisabledTestCase has 2 (due to inheritance)
# They will be balanced into:
# [CacheTestCase, ToolBarTestCase],
# [[TabUITestCase, KeyboardTestCase],
# [PasswordManagerPasswordCheckupDisabledTestCase, PasswordManagerTestCase]]
self.assertEqual(
sorted([len(sublists_3[0]),
len(sublists_3[1]),
len(sublists_3[2])]), [2, 2, 2])
if __name__ == '__main__':
unittest.main()