Commit ea238be2 authored by Quinten Yearsley's avatar Quinten Yearsley Committed by Commit Bot

Refactor GitCLMock to make types consistent

This is a follow-up to https://crrev.com//f41d2d3d4e8af.

Reason: Previously, the results argument from MockGitCL
would sometimes be a CLStatus, and sometimes be a dict
of Build to TryJobStatus. Furthermore both try_job_results
and wait_for_try_jobs would return the same type, which
is longer the case for the real GitCL.

The purpose of this CL is to make MockGitCL easier to use
and also reflect the behavior of the actual GitCL class.

Change-Id: I6d08dbdc205a1191b47039002b4a18a9579b022b
Reviewed-on: https://chromium-review.googlesource.com/826707Reviewed-by: default avatarRaphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Reviewed-by: default avatarRobert Ma <robertma@chromium.org>
Commit-Queue: Quinten Yearsley <qyearsley@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524121}
parent a28f4d06
......@@ -2,16 +2,29 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from webkitpy.common.net.git_cl import GitCL
from webkitpy.common.net.git_cl import CLStatus, GitCL
# pylint: disable=unused-argument
class MockGitCL(object):
def __init__(self, host, results=None, issue_number='1234'):
self._host = host
self._results = results
def __init__(
self, host, try_job_results=None, status='closed',
issue_number='1234', time_out=False):
"""Constructs a fake GitCL with canned return values.
Args:
host: Host object, used for builder names.
try_job_results: A dict of Build to TryJobStatus.
status: CL status string.
issue_number: CL issue number as a string.
time_out: Whether to simulate timing out while waiting.
"""
self._builders = host.builders.all_try_builder_names()
self._status = status
self._try_job_results = try_job_results
self._issue_number = issue_number
self._time_out = time_out
self.calls = []
def run(self, args):
......@@ -19,7 +32,7 @@ class MockGitCL(object):
return 'mock output'
def trigger_try_jobs(self, builders=None, master=None):
builders = builders or self._host.builders.all_try_builder_names()
builders = builders or self._builders
if not master:
master = 'tryserver.blink'
command = ['try', '-m', master]
......@@ -31,16 +44,20 @@ class MockGitCL(object):
return self._issue_number
def try_job_results(self, **_):
return self._results
return self._try_job_results
def wait_for_try_jobs(self, **_):
return self._results
if self._time_out:
return None
return CLStatus(self._status, self._try_job_results)
def wait_for_closed_status(self, **_):
if self._time_out:
return None
return 'closed'
def latest_try_jobs(self, builder_names=None):
return self.filter_latest(self._results)
return self.filter_latest(self._try_job_results)
@staticmethod
def filter_latest(try_results):
......
......@@ -29,7 +29,7 @@ class TestImporterTest(LoggingTestCase):
host.filesystem.write_text_file(
'/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations', '')
importer = TestImporter(host)
importer.git_cl = MockGitCL(host, results=None)
importer.git_cl = MockGitCL(host, time_out=True)
success = importer.update_expectations_for_cl()
self.assertFalse(success)
self.assertLog([
......@@ -43,12 +43,9 @@ class TestImporterTest(LoggingTestCase):
host.filesystem.write_text_file(
'/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations', '')
importer = TestImporter(host)
importer.git_cl = MockGitCL(host, results=CLStatus(
status='closed',
try_job_results={
Build('builder-a', 123): TryJobStatus('COMPLETED', 'SUCCESS'),
},
))
importer.git_cl = MockGitCL(host, status='closed', try_job_results={
Build('builder-a', 123): TryJobStatus('COMPLETED', 'SUCCESS'),
})
success = importer.update_expectations_for_cl()
self.assertFalse(success)
self.assertLog([
......@@ -61,12 +58,9 @@ class TestImporterTest(LoggingTestCase):
host.filesystem.write_text_file(
'/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations', '')
importer = TestImporter(host)
importer.git_cl = MockGitCL(host, results=CLStatus(
status='lgtm',
try_job_results={
Build('builder-a', 123): TryJobStatus('COMPLETED', 'SUCCESS'),
},
))
importer.git_cl = MockGitCL(host, status='lgtm', try_job_results={
Build('builder-a', 123): TryJobStatus('COMPLETED', 'SUCCESS'),
})
success = importer.update_expectations_for_cl()
self.assertLog([
'INFO: Triggering try jobs for updating expectations.\n',
......@@ -79,12 +73,9 @@ class TestImporterTest(LoggingTestCase):
host.filesystem.write_text_file(
'/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations', '')
importer = TestImporter(host)
importer.git_cl = MockGitCL(host, results=CLStatus(
status='lgtm',
try_job_results={
Build('builder-a', 123): TryJobStatus('COMPLETED', 'FAILURE'),
},
))
importer.git_cl = MockGitCL(host, status='lgtm', try_job_results={
Build('builder-a', 123): TryJobStatus('COMPLETED', 'FAILURE'),
})
importer.fetch_new_expectations_and_baselines = lambda: None
success = importer.update_expectations_for_cl()
self.assertTrue(success)
......@@ -99,13 +90,10 @@ class TestImporterTest(LoggingTestCase):
'/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations', '')
importer = TestImporter(host)
# Only the latest job for each builder is counted.
importer.git_cl = MockGitCL(host, results=CLStatus(
status='lgtm',
try_job_results={
Build('cq-builder-a', 120): TryJobStatus('COMPLETED', 'FAILURE'),
Build('cq-builder-a', 123): TryJobStatus('COMPLETED', 'SUCCESS'),
},
))
importer.git_cl = MockGitCL(host, status='lgtm', try_job_results={
Build('cq-builder-a', 120): TryJobStatus('COMPLETED', 'FAILURE'),
Build('cq-builder-a', 123): TryJobStatus('COMPLETED', 'SUCCESS'),
})
success = importer.run_commit_queue_for_cl()
self.assertTrue(success)
self.assertLog([
......@@ -125,14 +113,11 @@ class TestImporterTest(LoggingTestCase):
host.filesystem.write_text_file(
'/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations', '')
importer = TestImporter(host)
importer.git_cl = MockGitCL(host, results=CLStatus(
status='lgtm',
try_job_results={
Build('cq-builder-a', 120): TryJobStatus('COMPLETED', 'SUCCESS'),
Build('cq-builder-a', 123): TryJobStatus('COMPLETED', 'FAILURE'),
Build('cq-builder-b', 200): TryJobStatus('COMPLETED', 'SUCCESS'),
},
))
importer.git_cl = MockGitCL(host, status='lgtm', try_job_results={
Build('cq-builder-a', 120): TryJobStatus('COMPLETED', 'SUCCESS'),
Build('cq-builder-a', 123): TryJobStatus('COMPLETED', 'FAILURE'),
Build('cq-builder-b', 200): TryJobStatus('COMPLETED', 'SUCCESS'),
})
importer.fetch_new_expectations_and_baselines = lambda: None
success = importer.run_commit_queue_for_cl()
self.assertFalse(success)
......@@ -151,13 +136,10 @@ class TestImporterTest(LoggingTestCase):
host.filesystem.write_text_file(
'/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations', '')
importer = TestImporter(host)
importer.git_cl = MockGitCL(host, results=CLStatus(
status='closed',
try_job_results={
Build('cq-builder-a', 120): TryJobStatus('COMPLETED', 'SUCCESS'),
Build('cq-builder-b', 200): TryJobStatus('COMPLETED', 'SUCCESS'),
},
))
importer.git_cl = MockGitCL(host, status='closed', try_job_results={
Build('cq-builder-a', 120): TryJobStatus('COMPLETED', 'SUCCESS'),
Build('cq-builder-b', 200): TryJobStatus('COMPLETED', 'SUCCESS'),
})
success = importer.run_commit_queue_for_cl()
self.assertFalse(success)
self.assertLog([
......@@ -180,13 +162,10 @@ class TestImporterTest(LoggingTestCase):
}
})
importer = TestImporter(host)
importer.git_cl = MockGitCL(host, results=CLStatus(
status='lgtm',
try_job_results={
Build('fakeos_blink_rel', 123): TryJobStatus('COMPLETED', 'FAILURE'),
Build('cq-builder-b', 200): TryJobStatus('COMPLETED', 'SUCCESS'),
},
))
importer.git_cl = MockGitCL(host, status='lgtm', try_job_results={
Build('fakeos_blink_rel', 123): TryJobStatus('COMPLETED', 'FAILURE'),
Build('cq-builder-b', 200): TryJobStatus('COMPLETED', 'SUCCESS'),
})
importer.fetch_new_expectations_and_baselines = lambda: None
success = importer.run_commit_queue_for_cl()
self.assertTrue(success)
......@@ -203,11 +182,10 @@ class TestImporterTest(LoggingTestCase):
])
def test_run_commit_queue_for_cl_timeout(self):
# This simulates the case where we time out while waiting for try jobs.
host = MockHost()
importer = TestImporter(host)
# The simulates the case where importer.git_cl.wait_for_try_jobs returns
# None, which would normally happen if we time out waiting for results.
importer.git_cl = MockGitCL(host, results=None)
importer.git_cl = MockGitCL(host, time_out=True)
success = importer.run_commit_queue_for_cl()
self.assertFalse(success)
self.assertLog([
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment