<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[175073] trunk/Tools</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/175073">175073</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2014-10-22 16:27:27 -0700 (Wed, 22 Oct 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>commitqueuetask should include more tests to ensure that the behavior
of PatchAnalysisTask._test_patch() is well defined
https://bugs.webkit.org/show_bug.cgi?id=137977

Patch by Jake Nielsen &lt;jacob_nielsen@apple.com&gt; on 2014-10-22
Reviewed by Alexey Proskuryakov.

* Scripts/webkitpy/tool/bot/commitqueuetask_unittest.py:
Adds the MockSimpleTestPlanCommitQueue class, which makes it easier
and more readable to define tests that are meant to test the behaviour
of PatchAnalysisTask._test_patch(), and adds several unit tests.
(FailingTestCommitQueue.test_results):
(PatchAnalysisResult):
(MockSimpleTestPlanCommitQueue):
(MockSimpleTestPlanCommitQueue.__init__):
(MockSimpleTestPlanCommitQueue.run_command):
(MockSimpleTestPlanCommitQueue._mock_test_result):
(MockSimpleTestPlanCommitQueue.test_results):
(CommitQueueTaskTest._run_and_expect_patch_analysis_result):
(test_flaky_test_failure):
(test_failed_archive):
(test_two_flaky_tests):
(test_one_flaky_test):
(test_very_flaky_patch):
(test_very_flaky_patch_with_some_tree_redness):
(test_different_test_failures):
(test_different_test_failures_with_some_tree_redness):
(test_mildly_flaky_patch):
(test_mildly_flaky_patch_with_some_tree_redness):
(test_tree_more_red_than_patch):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptswebkitpytoolbotcommitqueuetask_unittestpy">trunk/Tools/Scripts/webkitpy/tool/bot/commitqueuetask_unittest.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (175072 => 175073)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2014-10-22 23:18:30 UTC (rev 175072)
+++ trunk/Tools/ChangeLog        2014-10-22 23:27:27 UTC (rev 175073)
</span><span class="lines">@@ -1,5 +1,37 @@
</span><span class="cx"> 2014-10-22  Jake Nielsen  &lt;jacob_nielsen@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        commitqueuetask should include more tests to ensure that the behavior
+        of PatchAnalysisTask._test_patch() is well defined
+        https://bugs.webkit.org/show_bug.cgi?id=137977
+
+        Reviewed by Alexey Proskuryakov.
+
+        * Scripts/webkitpy/tool/bot/commitqueuetask_unittest.py:
+        Adds the MockSimpleTestPlanCommitQueue class, which makes it easier
+        and more readable to define tests that are meant to test the behaviour
+        of PatchAnalysisTask._test_patch(), and adds several unit tests.
+        (FailingTestCommitQueue.test_results):
+        (PatchAnalysisResult):
+        (MockSimpleTestPlanCommitQueue):
+        (MockSimpleTestPlanCommitQueue.__init__):
+        (MockSimpleTestPlanCommitQueue.run_command):
+        (MockSimpleTestPlanCommitQueue._mock_test_result):
+        (MockSimpleTestPlanCommitQueue.test_results):
+        (CommitQueueTaskTest._run_and_expect_patch_analysis_result):
+        (test_flaky_test_failure):
+        (test_failed_archive):
+        (test_two_flaky_tests):
+        (test_one_flaky_test):
+        (test_very_flaky_patch):
+        (test_very_flaky_patch_with_some_tree_redness):
+        (test_different_test_failures):
+        (test_different_test_failures_with_some_tree_redness):
+        (test_mildly_flaky_patch):
+        (test_mildly_flaky_patch_with_some_tree_redness):
+        (test_tree_more_red_than_patch):
+
+2014-10-22  Jake Nielsen  &lt;jacob_nielsen@apple.com&gt;
+
</ins><span class="cx">         PatchAnalysisTask._test_patch() needs refactoring
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=137904
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpytoolbotcommitqueuetask_unittestpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/tool/bot/commitqueuetask_unittest.py (175072 => 175073)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/tool/bot/commitqueuetask_unittest.py        2014-10-22 23:18:30 UTC (rev 175072)
+++ trunk/Tools/Scripts/webkitpy/tool/bot/commitqueuetask_unittest.py        2014-10-22 23:27:27 UTC (rev 175073)
</span><span class="lines">@@ -107,10 +107,42 @@
</span><span class="cx">         assert(self._test_run_counter &gt;= 0)
</span><span class="cx">         failures_for_run = self._test_failure_plan[self._test_run_counter]
</span><span class="cx">         assert(isinstance(failures_for_run, list))
</span><del>-        results = LayoutTestResults(test_results=map(self._mock_test_result, failures_for_run), did_exceed_test_failure_limit=(len(self._test_failure_plan[self._test_run_counter]) &gt;= 10))
</del><ins>+        results = LayoutTestResults(test_results=map(self._mock_test_result, failures_for_run), did_exceed_test_failure_limit=(len(failures_for_run) &gt;= 10))
</ins><span class="cx">         return results
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+class PatchAnalysisResult(object):
+    FAIL = &quot;Fail&quot;
+    DEFER = &quot;Defer&quot;
+    PASS = &quot;Pass&quot;
+
+
+class MockSimpleTestPlanCommitQueue(MockCommitQueue):
+    def __init__(self, first_test_failures, second_test_failures, clean_test_failures):
+        MockCommitQueue.__init__(self, [])
+        self._patch_test_results = [first_test_failures, second_test_failures]
+        self._clean_test_results = [clean_test_failures]
+        self._current_test_results = []
+
+    def run_command(self, command):
+        MockCommitQueue.run_command(self, command)
+        if command[0] == &quot;build-and-test&quot;:
+            if &quot;--no-clean&quot; in command:
+                self._current_test_results = self._patch_test_results.pop(0)
+            else:
+                self._current_test_results = self._clean_test_results.pop(0)
+
+            if self._current_test_results:
+                raise ScriptError(&quot;MOCK test failure&quot;)
+
+    def _mock_test_result(self, testname):
+        return test_results.TestResult(testname, [test_failures.FailureTextMismatch()])
+
+    def test_results(self):
+        assert(isinstance(self._current_test_results, list))
+        return LayoutTestResults(test_results=map(self._mock_test_result, self._current_test_results), did_exceed_test_failure_limit=(len(self._current_test_results) &gt;= 10))
+
+
</ins><span class="cx"> # We use GoldenScriptError to make sure that the code under test throws the
</span><span class="cx"> # correct (i.e., golden) exception.
</span><span class="cx"> class GoldenScriptError(ScriptError):
</span><span class="lines">@@ -118,6 +150,22 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class CommitQueueTaskTest(unittest.TestCase):
</span><ins>+    def _run_and_expect_patch_analysis_result(self, commit_queue, expected_analysis_result):
+        tool = MockTool(log_executive=True)
+        patch = tool.bugs.fetch_attachment(10000)
+        task = CommitQueueTask(commit_queue, patch)
+
+        try:
+            result = task.run()
+            if result:
+                analysis_result = PatchAnalysisResult.PASS
+            else:
+                analysis_result = PatchAnalysisResult.DEFER
+        except ScriptError:
+            analysis_result = PatchAnalysisResult.FAIL
+
+        self.assertEqual(analysis_result, expected_analysis_result)
+
</ins><span class="cx">     def _run_through_task(self, commit_queue, expected_logs, expected_exception=None, expect_retry=False):
</span><span class="cx">         self.maxDiff = None
</span><span class="cx">         tool = MockTool(log_executive=True)
</span><span class="lines">@@ -277,7 +325,6 @@
</span><span class="cx">         ])
</span><span class="cx">         # CommitQueueTask will only report flaky tests if we successfully parsed
</span><span class="cx">         # results.json and returned a LayoutTestResults object, so we fake one.
</span><del>-        commit_queue.test_results = lambda: LayoutTestResults(test_results=[], did_exceed_test_failure_limit=False)
</del><span class="cx">         expected_logs = &quot;&quot;&quot;run_webkit_patch: ['clean']
</span><span class="cx"> command_passed: success_message='Cleaned working directory' patch='10000'
</span><span class="cx"> run_webkit_patch: ['update']
</span><span class="lines">@@ -308,7 +355,6 @@
</span><span class="cx">             None,
</span><span class="cx">             ScriptError(&quot;MOCK tests failure&quot;),
</span><span class="cx">         ])
</span><del>-        commit_queue.test_results = lambda: LayoutTestResults(test_results=[], did_exceed_test_failure_limit=False)
</del><span class="cx">         # It's possible delegate to fail to archive layout tests, don't try to report
</span><span class="cx">         # flaky tests when that happens.
</span><span class="cx">         commit_queue.archive_last_test_results = lambda patch: None
</span><span class="lines">@@ -591,6 +637,83 @@
</span><span class="cx">         # FIXME: This should really be expect_retry=True for a better user experiance.
</span><span class="cx">         self._run_through_task(commit_queue, expected_logs, GoldenScriptError)
</span><span class="cx"> 
</span><ins>+    def test_two_flaky_tests(self):
+        commit_queue = MockSimpleTestPlanCommitQueue(
+            first_test_failures=[&quot;Fail1&quot;],
+            second_test_failures=[&quot;Fail2&quot;],
+            clean_test_failures=[&quot;Fail1&quot;, &quot;Fail2&quot;])
+
+        # FIXME: This should pass, but as of right now, it defers.
+        self._run_and_expect_patch_analysis_result(commit_queue, PatchAnalysisResult.DEFER)
+
+    def test_one_flaky_test(self):
+        commit_queue = MockSimpleTestPlanCommitQueue(
+            first_test_failures=[&quot;Fail1&quot;],
+            second_test_failures=[],
+            clean_test_failures=[])
+
+        self._run_and_expect_patch_analysis_result(commit_queue, PatchAnalysisResult.PASS)
+
+    def test_very_flaky_patch(self):
+        commit_queue = MockSimpleTestPlanCommitQueue(
+            first_test_failures=[&quot;Fail1&quot;, &quot;Fail2&quot;, &quot;Fail3&quot;, &quot;Fail4&quot;, &quot;Fail5&quot;],
+            second_test_failures=[&quot;Fail6&quot;, &quot;Fail7&quot;, &quot;Fail8&quot;, &quot;Fail9&quot;, &quot;Fail10&quot;],
+            clean_test_failures=[])
+
+        # FIXME: This should actually fail, but right now it defers
+        self._run_and_expect_patch_analysis_result(commit_queue, PatchAnalysisResult.DEFER)
+
+    def test_very_flaky_patch_with_some_tree_redness(self):
+        commit_queue = MockSimpleTestPlanCommitQueue(
+            first_test_failures=[&quot;PreExistingFail1&quot;, &quot;PreExistingFail2&quot;, &quot;Fail6&quot;, &quot;Fail7&quot;, &quot;Fail8&quot;, &quot;Fail9&quot;, &quot;Fail10&quot;],
+            second_test_failures=[&quot;PreExistingFail1&quot;, &quot;PreExistingFail2&quot;, &quot;Fail1&quot;, &quot;Fail2&quot;, &quot;Fail3&quot;, &quot;Fail4&quot;, &quot;Fail5&quot;],
+            clean_test_failures=[&quot;PreExistingFail1&quot;, &quot;PreExistingFail2&quot;])
+
+        # FIXME: This should actually fail, but right now it defers
+        self._run_and_expect_patch_analysis_result(commit_queue, PatchAnalysisResult.DEFER)
+
+    def test_different_test_failures(self):
+        commit_queue = MockSimpleTestPlanCommitQueue(
+            first_test_failures=[&quot;Fail1&quot;, &quot;Fail2&quot;, &quot;Fail3&quot;, &quot;Fail4&quot;, &quot;Fail5&quot;, &quot;Fail6&quot;],
+            second_test_failures=[&quot;Fail1&quot;, &quot;Fail2&quot;, &quot;Fail3&quot;, &quot;Fail4&quot;, &quot;Fail5&quot;],
+            clean_test_failures=[])
+
+        # FIXME: This should actually fail, but right now it defers
+        self._run_and_expect_patch_analysis_result(commit_queue, PatchAnalysisResult.DEFER)
+
+    def test_different_test_failures_with_some_tree_redness(self):
+        commit_queue = MockSimpleTestPlanCommitQueue(
+            first_test_failures=[&quot;PreExistingFail1&quot;, &quot;PreExistingFail2&quot;, &quot;Fail1&quot;, &quot;Fail2&quot;, &quot;Fail3&quot;, &quot;Fail4&quot;, &quot;Fail5&quot;, &quot;Fail6&quot;],
+            second_test_failures=[&quot;PreExistingFail1&quot;, &quot;PreExistingFail2&quot;, &quot;Fail1&quot;, &quot;Fail2&quot;, &quot;Fail3&quot;, &quot;Fail4&quot;, &quot;Fail5&quot;],
+            clean_test_failures=[&quot;PreExistingFail1&quot;, &quot;PreExistingFail2&quot;])
+
+        # FIXME: This should actually fail, but right now it defers
+        self._run_and_expect_patch_analysis_result(commit_queue, PatchAnalysisResult.DEFER)
+
+    def test_mildly_flaky_patch(self):
+        commit_queue = MockSimpleTestPlanCommitQueue(
+            first_test_failures=[&quot;Fail1&quot;],
+            second_test_failures=[&quot;Fail2&quot;],
+            clean_test_failures=[])
+
+        self._run_and_expect_patch_analysis_result(commit_queue, PatchAnalysisResult.DEFER)
+
+    def test_mildly_flaky_patch_with_some_tree_redness(self):
+        commit_queue = MockSimpleTestPlanCommitQueue(
+            first_test_failures=[&quot;PreExistingFail1&quot;, &quot;PreExistingFail2&quot;, &quot;Fail1&quot;],
+            second_test_failures=[&quot;PreExistingFail1&quot;, &quot;PreExistingFail2&quot;, &quot;Fail2&quot;],
+            clean_test_failures=[&quot;PreExistingFail1&quot;, &quot;PreExistingFail2&quot;])
+
+        self._run_and_expect_patch_analysis_result(commit_queue, PatchAnalysisResult.DEFER)
+
+    def test_tree_more_red_than_patch(self):
+        commit_queue = MockSimpleTestPlanCommitQueue(
+            first_test_failures=[&quot;Fail1&quot;, &quot;Fail2&quot;, &quot;Fail3&quot;],
+            second_test_failures=[&quot;Fail1&quot;, &quot;Fail2&quot;, &quot;Fail3&quot;],
+            clean_test_failures=[&quot;Fail1&quot;, &quot;Fail2&quot;, &quot;Fail3&quot;, &quot;Fail4&quot;])
+
+        self._run_and_expect_patch_analysis_result(commit_queue, PatchAnalysisResult.PASS)
+
</ins><span class="cx">     def _expect_validate(self, patch, is_valid):
</span><span class="cx">         class MockDelegate(object):
</span><span class="cx">             def refetch_patch(self, patch):
</span></span></pre>
</div>
</div>

</body>
</html>