def testUploadRetryErrors(self):
   """Verify that we retry errors (and eventually give up)"""
   m = upload_symbols.SymUpload = mock.Mock(side_effect=self.excp_result)
   errors = ctypes.c_int()
   ret = upload_symbols.UploadSymbol('/dev/null', self.url, num_errors=errors)
   self.assertEqual(ret, 1)
   m.assert_called_with('/dev/null', self.url)
   self.assertTrue(m.call_count >= upload_symbols.MAX_RETRIES)
 def testUploadSymbolNormal(self):
   """Verify we try to upload on a normal file"""
   m = upload_symbols.SymUpload = mock.Mock(return_value=self.good_result)
   osutils.Touch(self.sym_file)
   ret = upload_symbols.UploadSymbol(self.sym_file, self.url)
   self.assertEqual(ret, 0)
   m.assert_called_with(self.sym_file, self.url)
   self.assertEqual(m.call_count, 1)
示例#3
0
 def testUploadSymbolNormal(self):
     """Verify we try to upload on a normal file"""
     osutils.Touch(self.sym_file)
     sym_element = upload_symbols.SymbolElement(self.sym_item, None)
     ret = upload_symbols.UploadSymbol(self.url, sym_element, 'TestProduct')
     self.assertEqual(ret, 0)
     self.upload_mock.assert_called_with(self.url, self.sym_item,
                                         'TestProduct')
     self.assertEqual(self.upload_mock.call_count, 1)
 def testTruncateReallyLargeFiles(self):
   """Verify we try to shrink really big files"""
   m = upload_symbols.SymUpload = mock.Mock(return_value=self.good_result)
   with open(self.sym_file, 'w+b') as f:
     f.truncate(upload_symbols.CRASH_SERVER_FILE_LIMIT + 100)
     f.seek(0)
     f.write('STACK CFI 1234\n\n')
   ret = upload_symbols.UploadSymbol(self.sym_file, self.url)
   self.assertEqual(ret, 1)
   self.assertNotEqual(m.call_args[0][1], self.sym_file)
   self.assertEqual(m.call_count, 1)
示例#5
0
 def testUploadSymbolErrorCountExceeded(self):
     """Verify that when the error count gets too high, we stop uploading"""
     errors = ctypes.c_int(10000)
     # Pass in garbage values so that we crash if num_errors isn't handled.
     ret = upload_symbols.UploadSymbol(None,
                                       upload_symbols.SymbolElement(
                                           self.sym_item, None),
                                       'TestProduct',
                                       sleep=None,
                                       num_errors=errors)
     self.assertEqual(ret, 0)
示例#6
0
 def testUploadRetryErrors(self, side_effect=None):
     """Verify that we retry errors (and eventually give up)"""
     if not side_effect:
         side_effect = urllib2.HTTPError('http://', 400, 'fail', {}, None)
     self.upload_mock.side_effect = side_effect
     errors = ctypes.c_int()
     item = upload_symbols.FakeItem(sym_file='/dev/null')
     element = upload_symbols.SymbolElement(item, None)
     ret = upload_symbols.UploadSymbol(self.url,
                                       element,
                                       'TestProduct',
                                       num_errors=errors)
     self.assertEqual(ret, 1)
     self.upload_mock.assert_called_with(self.url, item, 'TestProduct')
     self.assertTrue(
         self.upload_mock.call_count >= upload_symbols.MAX_RETRIES)
 def testTruncateTooBigFiles(self):
   """Verify we shrink big files"""
   def SymUpload(sym_file, _url):
     content = osutils.ReadFile(sym_file)
     self.assertEqual(content, 'some junk\n')
     return self.good_result
   m = upload_symbols.SymUpload = mock.Mock(side_effect=SymUpload)
   content = (
       'STACK CFI 1234',
       'some junk',
       'STACK CFI 1234',
   )
   osutils.WriteFile(self.sym_file, '\n'.join(content))
   ret = upload_symbols.UploadSymbol(self.sym_file, self.url, file_limit=1)
   self.assertEqual(ret, 0)
   self.assertNotEqual(m.call_args[0][1], self.sym_file)
   self.assertEqual(m.call_count, 1)
示例#8
0
 def testTruncateReallyLargeFiles(self):
     """Verify we try to shrink really big files"""
     warn_mock = self.PatchObject(logging, 'PrintBuildbotStepWarnings')
     with open(self.sym_file, 'w+b') as f:
         f.truncate(upload_symbols.CRASH_SERVER_FILE_LIMIT + 100)
         f.seek(0)
         f.write('STACK CFI 1234\n\n')
     ret = upload_symbols.UploadSymbol(
         self.url, upload_symbols.SymbolElement(self.sym_item, None),
         'TestProduct')
     self.assertEqual(ret, 0)
     # Make sure the item passed to the upload has a temp file and not the
     # original -- only the temp one has been truncated.
     temp_item = self.upload_mock.call_args[0][1]
     self.assertNotEqual(temp_item.sym_file, self.sym_item.sym_file)
     self.assertEqual(self.upload_mock.call_count, 1)
     self.assertEqual(warn_mock.call_count, 1)
示例#9
0
    def testTruncateTooBigFiles(self):
        """Verify we shrink big files"""
        def SymUpload(_url, sym_item):
            content = osutils.ReadFile(sym_item.sym_file)
            self.assertEqual(content, 'some junk\n')

        self.upload_mock.upload_mock.side_effect = SymUpload
        content = '\n'.join((
            'STACK CFI 1234',
            'some junk',
            'STACK CFI 1234',
        ))
        osutils.WriteFile(self.sym_file, content)
        ret = upload_symbols.UploadSymbol(self.url,
                                          upload_symbols.SymbolElement(
                                              self.sym_item, None),
                                          'TestProduct',
                                          file_limit=1)
        self.assertEqual(ret, 0)
        # Make sure the item passed to the upload has a temp file and not the
        # original -- only the temp one has been stripped down.
        temp_item = self.upload_mock.call_args[0][1]
        self.assertNotEqual(temp_item.sym_file, self.sym_item.sym_file)
        self.assertEqual(self.upload_mock.call_count, 1)