Beispiel #1
0
 def _ensure_cache(self):
     if self._num_items_cold is None and self.items_cold:
         items_cold = large.unpack(self.items_cold)
         self._num_items_cold = len(items_cold)
         self._total_bytes_items_cold = sum(items_cold)
     if self._num_items_hot is None and self.items_hot:
         items_hot = large.unpack(self.items_hot)
         self._num_items_hot = len(items_hot)
         self._total_bytes_items_hot = sum(items_hot)
 def test_result_completed_task(self):
   """Tests that completed tasks are correctly reported."""
   now = datetime.datetime(2010, 1, 2, 3, 4, 5, 6)
   str_now = unicode(now.strftime(self.DATETIME_FORMAT))
   self.mock_now(now)
   self.client_create_task_raw()
   self.set_as_bot()
   task_id = self.bot_run_task()
   # First ask without perf metadata.
   response = self.call_api('result', body={'task_id': task_id})
   expected = {
     u'bot_dimensions': [
       {u'key': u'id', u'value': [u'bot1']},
       {u'key': u'os', u'value': [u'Amiga']},
       {u'key': u'pool', u'value': [u'default']},
     ],
     u'bot_id': u'bot1',
     u'bot_version': self.bot_version,
     u'costs_usd': [0.1],
     u'created_ts': str_now,
     u'completed_ts': str_now,
     u'duration': 0.1,
     u'exit_code': u'0',
     u'failure': False,
     u'internal_failure': False,
     u'modified_ts': str_now,
     u'name': u'hi',
     u'server_versions': [u'v1a'],
     u'started_ts': str_now,
     u'state': u'COMPLETED',
     u'task_id': task_id,
     u'try_number': u'1',
   }
   self.assertEqual(expected, response.json)
   expected[u'performance_stats'] = {
     u'bot_overhead': 0.1,
     u'isolated_download': {
       u'duration': 1.0,
       u'initial_number_items': u'10',
       u'initial_size': u'100000',
       u'items_cold': [20],
       u'items_hot': [30],
     },
     u'isolated_upload': {
       u'duration': 2.0,
       u'items_cold': [40],
       u'items_hot': [50],
     },
   }
   response = self.call_api(
       'result',
       body={'task_id': task_id, 'include_performance_stats': True})
   actual = response.json
   for k in ('isolated_download', 'isolated_upload'):
     for j in ('items_cold', 'items_hot'):
       actual['performance_stats'][k][j] = large.unpack(
           base64.b64decode(actual['performance_stats'][k][j]))
   self.assertEqual(expected, actual)
  def test_list_ok(self):
    """Asserts that list requests all TaskResultSummaries."""
    first, second, str_now_120, start, end = self._gen_two_tasks()
    first_no_perf = first.copy()
    first_no_perf.pop('performance_stats')
    # Basic request.
    request = swarming_rpcs.TasksRequest(
        end=end, start=start, include_performance_stats=True)
    expected = {u'now': str_now_120, u'items': [second, first]}
    actual = self.call_api('list', body=message_to_dict(request)).json
    for k in ('isolated_download', 'isolated_upload'):
      for j in ('items_cold', 'items_hot'):
        actual['items'][1]['performance_stats'][k][j] = large.unpack(
            base64.b64decode(actual['items'][1]['performance_stats'][k][j]))
    self.assertEqual(expected, actual)

    # Sort by CREATED_TS.
    request = swarming_rpcs.TasksRequest(
        sort=swarming_rpcs.TaskSort.CREATED_TS)
    actual = self.call_api('list', body=message_to_dict(request)).json
    self.assertEqual(
        {u'now': str_now_120, u'items': [second, first_no_perf]}, actual)

    # Sort by MODIFIED_TS.
    request = swarming_rpcs.TasksRequest(
        sort=swarming_rpcs.TaskSort.MODIFIED_TS)
    actual = self.call_api('list', body=message_to_dict(request)).json
    self.assertEqual(
        {u'now': str_now_120, u'items': [first_no_perf, second]}, actual)

    # With two tags.
    request = swarming_rpcs.TasksRequest(
        end=end, start=start, tags=['project:yay', 'commit:pre'])
    self.assertEqual(
        {u'now': str_now_120, u'items': [second]},
        self.call_api('list', body=message_to_dict(request)).json)

    # A spurious tag.
    request = swarming_rpcs.TasksRequest(end=end, start=start, tags=['foo:bar'])
    self.assertEqual(
        {u'now': str_now_120},
        self.call_api('list', body=message_to_dict(request)).json)

    # Both state and tag.
    request = swarming_rpcs.TasksRequest(
        end=end, start=start, tags=['commit:pre'],
        state=swarming_rpcs.TaskState.COMPLETED_SUCCESS)
    self.assertEqual(
        {u'now': str_now_120, u'items': [second]},
        self.call_api('list', body=message_to_dict(request)).json)

    # Both sort and tag.
    request = swarming_rpcs.TasksRequest(
        end=end, start=start, tags=['commit:pre'],
        sort=swarming_rpcs.TaskSort.MODIFIED_TS,
        state=swarming_rpcs.TaskState.COMPLETED_SUCCESS)
    with self.call_should_fail('400'):
      self.call_api('list', body=message_to_dict(request))
Beispiel #4
0
 def items_hot_array(self):
     return large.unpack(self.items_hot or '')
Beispiel #5
0
 def items_cold_array(self):
     # It seems like it's impossible to add it as a method to LargeIntegerArray
     # in a way that works in jinja2 templates.
     return large.unpack(self.items_cold or '')
  def test_tasks_ok(self):
    """Asserts that tasks produces bot information."""
    self.mock(random, 'getrandbits', lambda _: 0x88)
    now = datetime.datetime(2010, 1, 2, 3, 4, 5, 6)
    self.mock_now(now)

    self.set_as_bot()
    self.client_create_task_raw()
    token, _ = self.get_bot_token()
    res = self.bot_poll()
    self.bot_complete_task(token, task_id=res['manifest']['task_id'])

    now_1 = self.mock_now(now, 1)
    now_1_str = unicode(now_1.strftime(self.DATETIME_FORMAT))
    self.mock(random, 'getrandbits', lambda _: 0x55)
    self.client_create_task_raw(name='philbert')
    token, _ = self.get_bot_token()
    res = self.bot_poll()
    self.bot_complete_task(
        token, exit_code=1, task_id=res['manifest']['task_id'])

    start = (
        utils.datetime_to_timestamp(now + datetime.timedelta(seconds=0.5)) /
        1000000.)
    end = (
        utils.datetime_to_timestamp(now_1 + datetime.timedelta(seconds=0.5)) /
        1000000.)

    self.set_as_privileged_user()
    request = swarming_rpcs.BotTasksRequest(
        end=end, start=start, include_performance_stats=True)
    body = message_to_dict(request)
    body['bot_id'] = 'bot1'
    response = self.call_api('tasks', body=body)
    expected = {
      u'items': [
        {
          u'bot_dimensions': [
            {u'key': u'id', u'value': [u'bot1']},
            {u'key': u'os', u'value': [u'Amiga']},
            {u'key': u'pool', u'value': [u'default']},
          ],
          u'bot_id': u'bot1',
          u'bot_version': self.bot_version,
          u'completed_ts': now_1_str,
          u'costs_usd': [0.1],
          u'created_ts': now_1_str,
          u'duration': 0.1,
          u'exit_code': u'1',
          u'failure': True,
          u'internal_failure': False,
          u'modified_ts': now_1_str,
          u'name': u'philbert',
          u'performance_stats': {
            u'bot_overhead': 0.1,
            u'isolated_download': {
              u'duration': 1.0,
              u'initial_number_items': u'10',
              u'initial_size': u'100000',
              u'items_cold': [20],
              u'items_hot': [30],
            },
            u'isolated_upload': {
              u'duration': 2.0,
              u'items_cold': [40],
              u'items_hot': [50],
            },
          },
          u'server_versions': [u'v1a'],
          u'started_ts': now_1_str,
          u'state': u'COMPLETED',
          u'task_id': u'5cee870005511',
          u'try_number': u'1',
        },
      ],
      u'now': unicode(now_1.strftime(self.DATETIME_FORMAT)),
    }
    actual = response.json
    for k in ('isolated_download', 'isolated_upload'):
      for j in ('items_cold', 'items_hot'):
        actual['items'][0]['performance_stats'][k][j] = large.unpack(
            base64.b64decode(actual['items'][0]['performance_stats'][k][j]))
    self.assertEqual(expected, actual)