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 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)
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 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)
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)