def test_retry(self):
     transaction = NetworkTransaction(initial_backoff_seconds=0)
     self.assertEqual(transaction.run(self._raise_500_error), 42)
     self.assertEqual(self._run_count, 3)
     self.assertLog(['WARNING: Received HTTP status 500 loading "http://example.com/".  '
                     'Retrying in 0 seconds...\n',
                     'WARNING: Received HTTP status 500 loading "http://example.com/".  '
                     'Retrying in 0.0 seconds...\n'])
 def test_timeout(self):
     transaction = NetworkTransaction(initial_backoff_seconds=60 * 60, timeout_seconds=60)
     did_process_exception = False
     did_throw_exception = True
     try:
         transaction.run(self._raise_500_error)
         did_throw_exception = False
     except NetworkTimeout:
         did_process_exception = True
     self.assertTrue(did_throw_exception)
     self.assertTrue(did_process_exception)
Example #3
0
 def test_exception(self):
     transaction = NetworkTransaction()
     did_process_exception = False
     did_throw_exception = True
     try:
         transaction.run(self._raise_exception)
         did_throw_exception = False
     except Exception as error:  # pylint: disable=broad-except
         did_process_exception = True
         self.assertEqual(error, self.exception)
     self.assertTrue(did_throw_exception)
     self.assertTrue(did_process_exception)
Example #4
0
 def fetch_layout_test_results(self, results_url, full=False):
     """Returns a LayoutTestResults object for results fetched from a given URL.
     Uses full_results.json if full is True, otherwise failing_results.json.
     """
     base_filename = 'full_results.json' if full else 'failing_results.json'
     results_file = NetworkTransaction(return_none_on_404=True).run(
         lambda: self.fetch_file('%s/%s' % (results_url, base_filename)))
     if results_file is None:
         _log.debug('Got 404 response from:\n%s/%s', results_url, base_filename)
         return None
     revision = NetworkTransaction(return_none_on_404=True).run(
         lambda: self.fetch_file('%s/LAST_CHANGE' % results_url))
     if revision is None:
         _log.debug('Got 404 response from:\n%s/LAST_CHANGE', results_url)
     return LayoutTestResults.results_from_string(results_file, revision)
Example #5
0
    def get_layout_test_step_name(self, build):
        url = '%s/testfile?%s' % (TEST_RESULTS_SERVER, urllib.urlencode({
            'builder': build.builder_name,
            'buildnumber': build.build_number,
            'name': 'full_results.json',
            # This forces the server to gives us JSON rather than an HTML page.
            'callback': json_results_generator.JSON_CALLBACK,
        }))
        data = NetworkTransaction(return_none_on_404=True).run(
            lambda: self.fetch_file(url))
        if not data:
            _log.debug('Got 404 response from:\n%s', url)
            return None

        # Strip out the callback
        data = json.loads(json_results_generator.strip_json_wrapper(data))
        suites = [
            entry['TestType'] for entry in data
            # Some suite names are like 'webkit_layout_tests on Intel GPU (with
            # patch)'. Only make sure it starts with webkit_layout_tests and
            # runs with a patch. This should be changed eventually to use actual
            # structured data from the test results server.
            if (entry['TestType'].startswith('webkit_layout_tests') and
                entry['TestType'].endswith('(with patch)'))
        ]
        # In manual testing, I sometimes saw results where the same suite was
        # repeated twice. De-duplicate here to try to catch this.
        suites = list(set(suites))
        if len(suites) != 1:
            raise Exception(
                'build %s on builder %s expected to only have one layout test '
                'step, instead has %s' % (
                    build.build_number, build.builder_name, suites))

        return suites[0]
Example #6
0
    def _upload_data(self, content_type, data):
        def callback():
            # FIXME: Setting a timeout, either globally using socket.setdefaulttimeout()
            # or in urlopen(), doesn't appear to work on Mac 10.5 with Python 2.7.
            # For now we will ignore the timeout value and hope for the best.
            request = urllib2.Request(self._url, data, {'Content-Type': content_type})
            return urllib2.urlopen(request)

        return NetworkTransaction(timeout_seconds=self._timeout_seconds).run(callback)
Example #7
0
    def fetch_retry_summary_json(self, build):
        """Fetches and returns the text of the archived retry_summary file.

        This file is expected to contain the results of retrying layout tests
        with and without a patch in a try job. It includes lists of tests
        that failed only with the patch ("failures"), and tests that failed
        both with and without ("ignored").
        """
        url_base = '%s/%s' % (self.builder_results_url_base(build.builder_name), build.build_number)
        return NetworkTransaction(return_none_on_404=True).run(
            lambda: self.fetch_file('%s/%s' % (url_base, 'retry_summary.json')))
Example #8
0
 def get_binary(self, url, return_none_on_404=False):
     return NetworkTransaction(return_none_on_404=return_none_on_404).run(
         lambda: self.request('GET', url).read())
Example #9
0
 def test_convert_404_to_none(self):
     transaction = NetworkTransaction(return_none_on_404=True)
     self.assertIsNone(transaction.run(self._raise_404_error))
Example #10
0
 def test_success(self):
     transaction = NetworkTransaction()
     self.assertEqual(transaction.run(lambda: 42), 42)
Example #11
0
 def get_binary(self, url, return_none_on_404=False):
     return NetworkTransaction(return_none_on_404=return_none_on_404).run(
         lambda: urllib2.urlopen(url).read())