Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import collections | 5 import collections |
| 6 import json | 6 import json |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 import tempfile | 10 import tempfile |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 mirrors[path_in_mirror] = TestRepo('mirror(%s)' % path_in_mirror, clock, | 57 mirrors[path_in_mirror] = TestRepo('mirror(%s)' % path_in_mirror, clock, |
| 58 'fake') | 58 'fake') |
| 59 mirrors[path_in_mirror]._repo_path = full_path | 59 mirrors[path_in_mirror]._repo_path = full_path |
| 60 mirrors[path_in_mirror].run('init', '--bare') | 60 mirrors[path_in_mirror].run('init', '--bare') |
| 61 | 61 |
| 62 class LogFormatter(logging.Formatter): | 62 class LogFormatter(logging.Formatter): |
| 63 def format(self, record): | 63 def format(self, record): |
| 64 s = super(LogFormatter, self).format(record) | 64 s = super(LogFormatter, self).format(record) |
| 65 return s.replace(base_repo_path, '[TMPDIR]') | 65 return s.replace(base_repo_path, '[TMPDIR]') |
| 66 | 66 |
| 67 class LogFilterer(logging.Filter): | |
| 68 def filter(self, record): | |
| 69 # infra.libs.git2.repo logs this message if the command took longer than | |
|
martiniss
2016/06/13 21:30:37
:(
| |
| 70 # 1s to run. This causes test flakes occasionally. | |
| 71 if (record.name.startswith('infra.libs.git2.repo.Repo') and | |
|
martiniss
2016/06/13 21:45:01
need a pragma: no cover for this, since it's flaki
| |
| 72 record.msg.startswith('Finished in ')): | |
| 73 return False | |
| 74 | |
| 75 return record.name.startswith(( | |
| 76 'infra.services.gsubtreed', | |
| 77 'infra.libs.git2', | |
| 78 )) | |
| 79 | |
| 67 def checkpoint(message, include_committer=False, include_config=False): | 80 def checkpoint(message, include_committer=False, include_config=False): |
| 68 repos = collections.OrderedDict() | 81 repos = collections.OrderedDict() |
| 69 repos['origin'] = origin.snap(include_committer, include_config) | 82 repos['origin'] = origin.snap(include_committer, include_config) |
| 70 for _, mirror in sorted(mirrors.items()): | 83 for _, mirror in sorted(mirrors.items()): |
| 71 repos[mirror.short_name] = mirror.snap(include_committer, include_config) | 84 repos[mirror.short_name] = mirror.snap(include_committer, include_config) |
| 72 ret.append([message, repos]) | 85 ret.append([message, repos]) |
| 73 | 86 |
| 74 def run(): | 87 def run(): |
| 75 stdout = sys.stdout | 88 stdout = sys.stdout |
| 76 stderr = sys.stderr | 89 stderr = sys.stderr |
| 77 | 90 |
| 78 logout = StringIO() | 91 logout = StringIO() |
| 79 root_logger = logging.getLogger() | 92 root_logger = logging.getLogger() |
| 80 shandler = logging.StreamHandler(logout) | 93 shandler = logging.StreamHandler(logout) |
| 81 shandler.setFormatter(LogFormatter('%(levelname)s: %(message)s')) | 94 shandler.setFormatter(LogFormatter('%(levelname)s: %(message)s')) |
| 95 shandler.addFilter(LogFilterer()) | |
| 82 root_logger.addHandler(shandler) | 96 root_logger.addHandler(shandler) |
| 83 shandler.setLevel(logging.INFO) | 97 shandler.setLevel(logging.INFO) |
| 84 | 98 |
| 85 # Run pusher threads sequentially and deterministically. | 99 # Run pusher threads sequentially and deterministically. |
| 86 gsubtreed.Pusher.FAKE_THREADING = True | 100 gsubtreed.Pusher.FAKE_THREADING = True |
| 87 | 101 |
| 88 success = False | 102 success = False |
| 89 processed = {} | 103 processed = {} |
| 90 try: | 104 try: |
| 91 with open(os.devnull, 'w') as dn: | 105 with open(os.devnull, 'w') as dn: |
| 92 # TODO(iannucci): Let expect_tests absorb stdio | 106 # TODO(iannucci): Let expect_tests absorb stdio |
| 93 sys.stderr = sys.stdout = dn | 107 sys.stderr = sys.stdout = dn |
| 94 local.reify() | 108 local.reify() |
| 95 success, processed = gsubtreed.inner_loop(local, cref) | 109 success, processed = gsubtreed.inner_loop(local, cref) |
| 96 except Exception: # pragma: no cover | 110 except Exception: # pragma: no cover |
| 97 ret.append(traceback.format_exc().splitlines()) | 111 ret.append(traceback.format_exc().splitlines()) |
| 98 finally: | 112 finally: |
| 99 gsubtreed.Pusher.FAKE_THREADING = False | 113 gsubtreed.Pusher.FAKE_THREADING = False |
| 100 | 114 |
| 101 sys.stdout = stdout | 115 sys.stdout = stdout |
| 102 sys.stderr = stderr | 116 sys.stderr = stderr |
| 103 | 117 |
| 104 root_logger.removeHandler(shandler) | 118 root_logger.removeHandler(shandler) |
| 105 | 119 |
| 106 # infra.libs.git2.repo logs this message if the command took longer than | 120 ret.append({'log output': logout.getvalue().splitlines()}) |
| 107 # 1s to run. This causes test flakes occasionally. | |
| 108 log_lines = [x for x in logout.getvalue().splitlines() | |
| 109 if 'Finished in ' not in x] | |
| 110 ret.append({'log output': log_lines}) | |
| 111 | 121 |
| 112 ret.append({ | 122 ret.append({ |
| 113 'inner_loop success': success, | 123 'inner_loop success': success, |
| 114 'processed': processed, | 124 'processed': processed, |
| 115 }) | 125 }) |
| 116 | 126 |
| 117 gsubtreed_test_definitions.GSUBTREED_TESTS[test_name]( | 127 gsubtreed_test_definitions.GSUBTREED_TESTS[test_name]( |
| 118 origin=origin, run=run, checkpoint=checkpoint, mirrors=mirrors, | 128 origin=origin, run=run, checkpoint=checkpoint, mirrors=mirrors, |
| 119 config=cref, local_origin_repo=local) | 129 config=cref, local_origin_repo=local) |
| 120 | 130 |
| 121 return expect_tests.Result(ret) | 131 return expect_tests.Result(ret) |
| 122 | 132 |
| 123 | 133 |
| 124 @expect_tests.test_generator | 134 @expect_tests.test_generator |
| 125 def GenTests(): | 135 def GenTests(): |
| 126 for test_name, test in gsubtreed_test_definitions.GSUBTREED_TESTS.iteritems(): | 136 for test_name, test in gsubtreed_test_definitions.GSUBTREED_TESTS.iteritems(): |
| 127 yield expect_tests.Test( | 137 yield expect_tests.Test( |
| 128 __package__ + '.' + test_name, | 138 __package__ + '.' + test_name, |
| 129 expect_tests.FuncCall(RunTest, test_name), | 139 expect_tests.FuncCall(RunTest, test_name), |
| 130 expect_base=test_name, ext='yaml', break_funcs=[test], | 140 expect_base=test_name, ext='yaml', break_funcs=[test], |
| 131 covers=( | 141 covers=( |
| 132 expect_tests.Test.covers_obj(RunTest) + | 142 expect_tests.Test.covers_obj(RunTest) + |
| 133 expect_tests.Test.covers_obj(gsubtreed_test_definitions) | 143 expect_tests.Test.covers_obj(gsubtreed_test_definitions) |
| 134 )) | 144 )) |
| OLD | NEW |