test_testsplitter.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # coding: utf-8
  2. from yatest_lib import test_splitter
  3. def get_chunks(tests, modulo, mode):
  4. chunks = []
  5. if mode == "MODULO":
  6. for modulo_index in range(modulo):
  7. chunks.append(test_splitter.get_shuffled_chunk(tests, modulo, modulo_index))
  8. elif mode == "SEQUENTIAL":
  9. for modulo_index in range(modulo):
  10. chunks.append(test_splitter.get_sequential_chunk(tests, modulo, modulo_index))
  11. else:
  12. raise ValueError("no such mode")
  13. return chunks
  14. def check_not_intersect(chunk_list):
  15. test_set = set()
  16. total_size = 0
  17. for tests in chunk_list:
  18. total_size += len(tests)
  19. test_set.update(tests)
  20. return total_size == len(test_set)
  21. def check_max_diff(chunk_list):
  22. return max(map(len, chunk_list)) - min(map(len, chunk_list))
  23. def test_lot_of_chunks():
  24. for chunk_count in range(10, 20):
  25. for tests_count in range(chunk_count):
  26. chunks = get_chunks(range(tests_count), chunk_count, "SEQUENTIAL")
  27. assert check_not_intersect(chunks)
  28. assert check_max_diff(chunks) <= 1
  29. assert chunks.count([]) == chunk_count - tests_count
  30. assert len(chunks) == chunk_count
  31. chunks = get_chunks(range(tests_count), chunk_count, "MODULO")
  32. assert check_not_intersect(chunks)
  33. assert check_max_diff(chunks) <= 1
  34. assert chunks.count([]) == chunk_count - tests_count
  35. assert len(chunks) == chunk_count
  36. def test_lot_of_tests():
  37. for tests_count in range(10, 20):
  38. for chunk_count in range(2, tests_count):
  39. chunks = get_chunks(range(tests_count), chunk_count, "SEQUENTIAL")
  40. assert check_not_intersect(chunks)
  41. assert check_max_diff(chunks) <= 1
  42. assert len(chunks) == chunk_count
  43. chunks = get_chunks(range(tests_count), chunk_count, "MODULO")
  44. assert check_not_intersect(chunks)
  45. assert check_max_diff(chunks) <= 1
  46. assert len(chunks) == chunk_count
  47. def prime_chunk_count():
  48. for chunk_count in [7, 11, 13, 17, 23, 29]:
  49. for tests_count in range(chunk_count):
  50. chunks = get_chunks(range(tests_count), chunk_count, "SEQUENTIAL")
  51. assert check_not_intersect(chunks)
  52. assert check_max_diff(chunks) <= 1
  53. assert len(chunks) == chunk_count
  54. chunks = get_chunks(range(tests_count), chunk_count, "MODULO")
  55. assert check_not_intersect(chunks)
  56. assert check_max_diff(chunks) <= 1
  57. assert len(chunks) == chunk_count
  58. def get_divisors(number):
  59. divisors = []
  60. for d in range(1, number + 1):
  61. if number % d == 0:
  62. divisors.append(d)
  63. return divisors
  64. def equal_chunks():
  65. for chunk_count in range(12, 31):
  66. for tests_count in get_divisors(chunk_count):
  67. chunks = get_chunks(range(tests_count), chunk_count, "SEQUENTIAL")
  68. assert check_not_intersect(chunks)
  69. assert check_max_diff(chunks) == 0
  70. assert len(chunks) == chunk_count
  71. chunks = get_chunks(range(tests_count), chunk_count, "MODULO")
  72. assert check_not_intersect(chunks)
  73. assert check_max_diff(chunks) == 0
  74. assert len(chunks) == chunk_count
  75. def chunk_count_equal_tests_count():
  76. for chunk_count in range(10, 20):
  77. tests_count = chunk_count
  78. chunks = get_chunks(range(tests_count), chunk_count, "SEQUENTIAL")
  79. assert check_not_intersect(chunks)
  80. assert check_max_diff(chunks) <= 1
  81. assert len(chunks) == chunk_count
  82. chunks = get_chunks(range(tests_count), chunk_count, "MODULO")
  83. assert check_not_intersect(chunks)
  84. assert check_max_diff(chunks) <= 1
  85. assert len(chunks) == chunk_count