run-perf-tests should report server-side errors
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Jan 2012 23:49:00 +0000 (23:49 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Jan 2012 23:49:00 +0000 (23:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76802

Reviewed by Tony Chang.

Report errors whenever server's response doesn't match "OK".

* Scripts/webkitpy/common/net/file_uploader.py:
(FileUploader.upload_single_text_file):
(FileUploader.upload_as_multipart_form_data):
(FileUploader._upload_data.callback):
(FileUploader):
(FileUploader._upload_data):
* Scripts/webkitpy/performance_tests/perftestsrunner.py:
(PerfTestsRunner._upload_json):
* Scripts/webkitpy/performance_tests/perftestsrunner_unittest.py:
(test_upload_json):
(test_upload_json.MockFileUploader.upload_single_text_file):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@105650 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/common/net/file_uploader.py
Tools/Scripts/webkitpy/performance_tests/perftestsrunner.py
Tools/Scripts/webkitpy/performance_tests/perftestsrunner_unittest.py

index a6c0241a4cbf0060f2d80c59928196179a45d18d..17d2645ba0f3137c4710801e3f270a310ab4c04d 100644 (file)
@@ -1,3 +1,24 @@
+2012-01-23  Ryosuke Niwa  <rniwa@webkit.org>
+
+        run-perf-tests should report server-side errors
+        https://bugs.webkit.org/show_bug.cgi?id=76802
+
+        Reviewed by Tony Chang.
+
+        Report errors whenever server's response doesn't match "OK".
+
+        * Scripts/webkitpy/common/net/file_uploader.py:
+        (FileUploader.upload_single_text_file):
+        (FileUploader.upload_as_multipart_form_data):
+        (FileUploader._upload_data.callback):
+        (FileUploader):
+        (FileUploader._upload_data):
+        * Scripts/webkitpy/performance_tests/perftestsrunner.py:
+        (PerfTestsRunner._upload_json):
+        * Scripts/webkitpy/performance_tests/perftestsrunner_unittest.py:
+        (test_upload_json):
+        (test_upload_json.MockFileUploader.upload_single_text_file):
+
 2012-01-22  Ryosuke Niwa  <rniwa@webkit.org>
 
         run-perf-tests ignore Skipped list on chromium
index 6278e1c8c4b30277e49de487da199847a28b326b..73d758bd8294e1c53e3416dc5471a2f51859d314 100644 (file)
@@ -89,7 +89,7 @@ class FileUploader(object):
         self._timeout_seconds = timeout_seconds
 
     def upload_single_text_file(self, filesystem, content_type, filename):
-        self._upload_data(content_type, filesystem.read_text_file(filename))
+        return self._upload_data(content_type, filesystem.read_text_file(filename))
 
     def upload_as_multipart_form_data(self, filesystem, files, params, timeout_seconds):
         file_objs = []
@@ -99,17 +99,19 @@ class FileUploader(object):
 
         # FIXME: We should use the same variable names for the formal and actual parameters.
         content_type, data = _encode_multipart_form_data(attrs, file_objs)
-        self._upload_data(content_type, data)
+        return self._upload_data(content_type, data)
 
     def _upload_data(self, content_type, data):
         def callback():
             request = urllib2.Request(self._url, data, {"Content-Type": content_type})
-            urllib2.urlopen(request)
+            return urllib2.urlopen(request)
 
         orig_timeout = socket.getdefaulttimeout()
+        response = None
         try:
             # FIXME: We shouldn't mutate global static state.
             socket.setdefaulttimeout(self._timeout_seconds)
-            NetworkTransaction(timeout_seconds=self._timeout_seconds).run(callback)
+            response = NetworkTransaction(timeout_seconds=self._timeout_seconds).run(callback)
         finally:
             socket.setdefaulttimeout(orig_timeout)
+            return response
index 202537bd0b99b3d4db631f4b6fda6883c5d73910..d2713e411dc76d2b4409f118e1ecd98b7728076f 100644 (file)
@@ -174,11 +174,18 @@ class PerfTestsRunner(object):
     def _upload_json(self, test_results_server, json_path, file_uploader=FileUploader):
         uploader = file_uploader("https://%s/api/test/report" % test_results_server, 120)
         try:
-            uploader.upload_single_text_file(self._host.filesystem, 'application/json', json_path)
+            response = uploader.upload_single_text_file(self._host.filesystem, 'application/json', json_path)
         except Exception, error:
             _log.error("Failed to upload JSON file in 120s: %s" % error)
             return False
 
+        response_body = [line.strip('\n') for line in response]
+        if response_body != ['OK']:
+            _log.error("Uploaded JSON but got a bad response:")
+            for line in response_body:
+                _log.error(line)
+            return False
+
         self._printer.write("JSON file uploaded.")
         return True
 
index 6cb355fcf14f18d83469cd66751a93bfbd346183..0996c8e23c9fda738043a322d2d765727f59be72 100755 (executable)
 
 """Unit tests for run_perf_tests."""
 
+import StringIO
 import json
 import unittest
 
 from webkitpy.common import array_stream
 from webkitpy.common.host_mock import MockHost
 from webkitpy.common.system.filesystem_mock import MockFileSystem
+from webkitpy.common.system.outputcapture import OutputCapture
 from webkitpy.layout_tests.port.driver import DriverInput, DriverOutput
 from webkitpy.layout_tests.port.test import TestPort
 from webkitpy.layout_tests.views import printing
@@ -240,11 +242,12 @@ max 1120
 
     def test_upload_json(self):
         regular_output = array_stream.ArrayStream()
-        runner = self.create_runner(buildbot_output=regular_output)
+        runner = self.create_runner(regular_output=regular_output)
         runner._host.filesystem.files['/mock-checkout/some.json'] = 'some content'
 
         called = []
         upload_single_text_file_throws = False
+        upload_single_text_file_return_value = StringIO.StringIO('OK')
 
         class MockFileUploader:
             def __init__(mock, url, timeout):
@@ -259,10 +262,18 @@ max 1120
                 called.append('upload_single_text_file')
                 if upload_single_text_file_throws:
                     raise "Some exception"
+                return upload_single_text_file_return_value
 
         runner._upload_json('some.host', 'some.json', MockFileUploader)
         self.assertEqual(called, ['FileUploader', 'upload_single_text_file'])
 
+        output = OutputCapture()
+        output.capture_output()
+        upload_single_text_file_return_value = StringIO.StringIO('Some error')
+        runner._upload_json('some.host', 'some.json', MockFileUploader)
+        _, _, logs = output.restore_output()
+        self.assertEqual(logs, 'Uploaded JSON but got a bad response:\nSome error\n')
+
         # Throwing an exception upload_single_text_file shouldn't blow up _upload_json
         called = []
         upload_single_text_file_throws = True