def get_dimensions(): """Returns bot_config.py's get_attributes() dict.""" # Importing this administrator provided script could have side-effects on # startup. That is why it is imported late. try: if _in_load_test_mode(): # Returns a minimal set of dimensions so it doesn't run tasks by error. dimensions = os_utilities.get_dimensions() return { 'id': dimensions['id'], 'load_test': ['1'], } import bot_config out = bot_config.get_dimensions() if not isinstance(out, dict): raise ValueError('Unexpected type %s' % out.__class__) return out except Exception as e: try: out = os_utilities.get_dimensions() out['error'] = [str(e)] out['quarantined'] = ['1'] return out except Exception as e: try: botid = os_utilities.get_hostname_short() except Exception as e2: botid = 'error_%s' % str(e2) return { 'id': [botid], 'error': ['%s\n%s' % (e, traceback.format_exc()[-2048:])], 'quarantined': ['1'], }
def test_run_bot(self): # Test the run_bot() loop. Does not use self.bot. self.mock(time, 'time', lambda: 126.0) class Foo(Exception): pass def poll_server(botobj): sleep_streak = botobj.state['sleep_streak'] self.assertEqual(botobj.remote, self.server) if sleep_streak == 5: raise Exception('Jumping out of the loop') return False self.mock(bot_main, 'poll_server', poll_server) def post_error(botobj, e): self.assertEqual(self.server, botobj._remote) lines = e.splitlines() self.assertEqual('Jumping out of the loop', lines[0]) self.assertEqual('Traceback (most recent call last):', lines[1]) raise Foo('Necessary to get out of the loop') self.mock(bot.Bot, 'post_error', post_error) self.mock(bot_main, 'get_remote', lambda: self.server) self.expected_requests([ ( 'https://localhost:1/swarming/api/v1/bot/server_ping', {}, 'foo', None, ), ]) with self.assertRaises(Foo): bot_main.run_bot(None) self.assertEqual(os_utilities.get_hostname_short(), os.environ['SWARMING_BOT_ID'])
def test_run_bot(self): # Test the run_bot() loop. Does not use self.bot. self.mock(time, 'time', lambda: 126.0) class Foo(Exception): pass def poll_server(botobj): sleep_streak = botobj.state['sleep_streak'] self.assertEqual(botobj.remote, self.server) if sleep_streak == 5: raise Exception('Jumping out of the loop') return False self.mock(bot_main, 'poll_server', poll_server) def post_error(botobj, e): self.assertEqual(self.server, botobj._remote) lines = e.splitlines() self.assertEqual('Jumping out of the loop', lines[0]) self.assertEqual('Traceback (most recent call last):', lines[1]) raise Foo('Necessary to get out of the loop') self.mock(bot.Bot, 'post_error', post_error) self.mock(bot_main, 'get_remote', lambda: self.server) self.expected_requests( [ ( 'https://localhost:1/swarming/api/v1/bot/server_ping', {}, 'foo', None, ), ]) with self.assertRaises(Foo): bot_main.run_bot(None) self.assertEqual( os_utilities.get_hostname_short(), os.environ['SWARMING_BOT_ID'])