Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: appengine/findit/handlers/test/trigger_analyses_test.py

Issue 2425453002: [Findit] Process analysis requests of Waterfall failures concurrently. (Closed)
Patch Set: fix nit. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import json
6 import re
7
8 from google.appengine.ext import testbed
9 import webapp2
10 import webtest
11
12 from testing_utils import testing
13
14 from model.wf_build import WfBuild
15 from handlers import trigger_analyses
16 from waterfall import buildbot
17 from waterfall import build_util
18 from waterfall import build_failure_analysis_pipelines
19 from waterfall.build_info import BuildInfo
20
21
22 class TriggerAnalyseseTest(testing.AppengineTestCase):
23 app_module = webapp2.WSGIApplication([
24 ('/trigger-analyses', trigger_analyses.TriggerAnalyses),
25 ], debug=True)
26
27 def _MockDownloadBuildData(self, build):
28 def Mocked_DownloadBuildData(*_):
29 return build
30 self.mock(build_util, 'DownloadBuildData', Mocked_DownloadBuildData)
31
32 def _MockExtractBuildInfo(self, build_info):
33 def Mocked_ExtractBuildInfo(*_):
34 return build_info
35 self.mock(buildbot, 'ExtractBuildInfo', Mocked_ExtractBuildInfo)
36
37 def _MockScheduleAnalysisIfNeeded(self, requests):
38 def Mocked_ScheduleAnalysisIfNeeded(*args, **kwargs):
39 requests.append((args, kwargs))
40 self.mock(build_failure_analysis_pipelines,
41 'ScheduleAnalysisIfNeeded', Mocked_ScheduleAnalysisIfNeeded)
42
43 def testWhenBuildIsNotAvailable(self):
44 self._MockDownloadBuildData(None)
45 self._MockExtractBuildInfo(None)
46 requests = []
47 self._MockScheduleAnalysisIfNeeded(requests)
48
49 builds = [
50 {
51 'master_name': 'm',
52 'builder_name': 'b',
53 'build_number': 1,
54 'failed_steps': [],
55 },
56 ]
57
58 trigger_analyses._TriggerNewAnalysesOnDemand(builds)
59 self.assertEqual(0, len(requests))
60
61 def testWhenBuildDataIsNotAvailable(self):
62 build = WfBuild.Create('m', 'b', 1)
63 build.data = None
64 self._MockDownloadBuildData(build)
65
66 self._MockExtractBuildInfo(None)
67 requests = []
68 self._MockScheduleAnalysisIfNeeded(requests)
69
70 builds = [
71 {
72 'master_name': 'm',
73 'builder_name': 'b',
74 'build_number': 1,
75 'failed_steps': [],
76 },
77 ]
78
79 trigger_analyses._TriggerNewAnalysesOnDemand(builds)
80 self.assertEqual(0, len(requests))
81
82 def testWhenBuildDataIsDownloadedSuccessfully(self):
83 build = WfBuild.Create('m', 'b', 1)
84 build.data = '{}'
85 self._MockDownloadBuildData(build)
86
87 build_info = BuildInfo('m', 'b', 1)
88 build_info.completed = False
89 self._MockExtractBuildInfo(build_info)
90
91 requests = []
92 self._MockScheduleAnalysisIfNeeded(requests)
93
94 builds = [
95 {
96 'master_name': 'm',
97 'builder_name': 'b',
98 'build_number': 1,
99 'failed_steps': [],
100 },
101 ]
102 trigger_analyses._TriggerNewAnalysesOnDemand(builds)
103 self.assertEqual(1, len(requests))
104 self.assertFalse(requests[0][1]['build_completed'])
105
106 def testNonAdminCanNotSendRequest(self):
107 self.assertRaisesRegexp(
108 webtest.app.AppError,
109 re.compile('.*401 Unauthorized.*'
110 'Error: Either not login or no permission.*',
111 re.MULTILINE | re.DOTALL),
112 self.test_app.post,
113 '/trigger-analyses',
114 params=json.dumps({'builds': []}))
115
116 def testAdminCanRequestAnalysisOfFailureOnUnsupportedMaster(self):
117 self.mock_current_user(user_email='test@chromium.org', is_admin=True)
118
119 build = WfBuild.Create('m', 'b', 1)
120 build.data = '{}'
121 self._MockDownloadBuildData(build)
122
123 build_info = BuildInfo('m', 'b', 1)
124 build_info.completed = True
125 self._MockExtractBuildInfo(build_info)
126
127 requests = []
128 self._MockScheduleAnalysisIfNeeded(requests)
129
130 builds = [
131 {
132 'master_name': 'm',
133 'builder_name': 'b',
134 'build_number': 1,
135 'failed_steps': [],
136 },
137 ]
138
139 response = self.test_app.post(
140 '/trigger-analyses',
141 params=json.dumps({'builds': builds}))
142 self.assertEquals(200, response.status_int)
143 self.assertEqual(1, len(requests))
144 self.assertTrue(requests[0][1]['build_completed'])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698