def _TestSendResults(self, new_data, expected_json, errors): """Test one call of SendResults with the given set of arguments. This method will fail a test case if the JSON that gets sent and the errors that are raised when results_dashboard.SendResults is called don't match the expected json and errors. Args: new_data: The new (not cached) data to send. expected_json_sent: A list of JSON string expected to be sent. errors: A list of corresponding errors expected to be received. """ self.mox.UnsetStubs() # urllib2.urlopen is the function that's called to send data to # the server. Here it is replaced with a mock object which is used # to record the expected JSON. # Because the JSON expected might be equivalent without being exactly # equal (in the string sense), a Mox Comparator is used. self.mox.StubOutWithMock(urllib2, 'urlopen') for json_line, error in zip(expected_json, errors): if error: urllib2.urlopen(IsEncodedJson(json_line)).AndRaise(error) else: urllib2.urlopen(IsEncodedJson(json_line)) self.mox.ReplayAll() results_dashboard.SendResults(new_data, 'https:/x.com', self.build_dir) self.mox.VerifyAll()
def main(args): # Parse options parser = optparse.OptionParser() parser.add_option('--name') parser.add_option('--results-file') parser.add_option('--output-json-file') parser.add_option('--got-revision-cp') parser.add_option('--build-dir') parser.add_option('--perf-id') parser.add_option('--results-url') parser.add_option('--buildername') parser.add_option('--buildnumber') parser.add_option('--got-webrtc-revision') parser.add_option('--got-v8-revision') parser.add_option('--version') parser.add_option('--git-revision') options, extra_args = parser.parse_args(args) # Validate options. if extra_args: parser.error('Unexpected command line arguments') if not options.perf_id or not options.results_url: parser.error('--perf-id and --results-url are required') main_revision = _GetMainRevision(options.got_revision_cp, options.build_dir) blink_revision = slave_utils.GetBlinkRevision(options.build_dir) revisions = slave_utils.GetPerfDashboardRevisionsWithProperties( options.got_webrtc_revision, options.got_v8_revision, options.version, options.git_revision, main_revision, blink_revision) reference_build = 'reference' in options.name stripped_test_name = options.name.replace('.reference', '') results = {} with open(options.results_file) as f: results = json.load(f) dashboard_json = {} if not 'charts' in results: # These are legacy results. dashboard_json = results_dashboard.MakeListOfPoints( results, options.perf_id, stripped_test_name, options.buildername, options.buildnumber, {}, revisions_dict=revisions) else: dashboard_json = results_dashboard.MakeDashboardJsonV1( results, revisions, stripped_test_name, options.perf_id, options.buildername, options.buildnumber, {}, reference_build) if dashboard_json: if options.output_json_file: with open (options.output_json_file, 'w') as output_file: json.dump(dashboard_json, output_file) if not results_dashboard.SendResults( dashboard_json, options.results_url, options.build_dir): return 1 else: print 'Error: No perf dashboard JSON was produced.' print '@@@STEP_FAILURE@@@' return 1 return 0
def _SendResults(self, send_results_args, expected_new_json, errors): self.mox.UnsetStubs() # Needed for multiple calls from same test. self.mox.StubOutWithMock(slave_utils, 'GetActiveMaster') slave_utils.GetActiveMaster().AndReturn('ChromiumPerf') self.mox.StubOutWithMock(urllib2, 'urlopen') for json_line, error in zip(expected_new_json, errors): if error: urllib2.urlopen(IsEncodedJson(json_line)).AndRaise(error) else: urllib2.urlopen(IsEncodedJson(json_line)) self.mox.ReplayAll() results_dashboard.SendResults(*send_results_args) self.mox.VerifyAll()
def _SendResults(self, send_results_args, expected_new_json, errors, mock_timestamp=False, webkit_master=False): """Test one call of SendResults with the given set of arguments. Args: send_results_args: The list of arguments to pass to SendResults. expected_new_json: A list of JSON string expected to be sent. errors: A list of corresponding errors expected to be received (Each item in the list is either a string or None.) mock_timestamp: Whether to stub out datetime with FakeDateTime(). webkit_master: Whether GetActiveMaster should give the webkit master. This method will fail a test case if the JSON that gets sent and the errors that are raised when results_dashboard.SendResults is called don't match the expected json and errors. """ # Unsetting stubs required here for multiple calls from same test. self.mox.UnsetStubs() self.mox.StubOutWithMock(slave_utils, 'GetActiveMaster') if webkit_master: slave_utils.GetActiveMaster().AndReturn('ChromiumWebkit') else: slave_utils.GetActiveMaster().AndReturn('ChromiumPerf') if mock_timestamp: self.mox.StubOutWithMock(datetime, 'datetime') datetime.datetime.utcnow().AndReturn(FakeDateTime()) # urllib2.urlopen is the function that's called to send data to # the server. Here it is replaced with a mock object which is used # to record the expected JSON. # Because the JSON expected might be equivalent without being exactly # equal (in the string sense), a Mox Comparator is used. self.mox.StubOutWithMock(urllib2, 'urlopen') for json_line, error in zip(expected_new_json, errors): if error: urllib2.urlopen(IsEncodedJson(json_line)).AndRaise(error) else: urllib2.urlopen(IsEncodedJson(json_line)) self.mox.ReplayAll() results_dashboard.SendResults(*send_results_args) self.mox.VerifyAll()