Exemplo n.º 1
0
def _AllTestPathsMatchingPatterns(patterns_list):
    """Returns a list of all test paths matching the given list of patterns."""
    matching_patterns_futures = [
        list_tests.GetTestsMatchingPatternAsync(p) for p in patterns_list
    ]

    test_paths = set()
    for i in xrange(len(patterns_list)):
        matching_patterns = matching_patterns_futures[i].get_result()
        test_paths |= set(matching_patterns)

    return sorted(test_paths)
def _CheckTestForDeprecationOrRemoval(entity_key):
  """Marks a TestMetadata entity as deprecated if the last row is too old.

  What is considered "too old" is defined by _DEPRECATION_REVISION_DELTA. Also,
  if all of the subtests in a test have been marked as deprecated, then that
  parent test will be marked as deprecated.

  This mapper doesn't un-deprecate tests if new data has been added; that
  happens in add_point.py.

  Args:
    entity: The TestMetadata entity to check.
  Returns:
    A TestMetadata that needs to be marked deprecated.
  """
  # Fetch the last row.
  entity = yield entity_key.get_async()
  query = graph_data.Row.query(
      graph_data.Row.parent_test == utils.OldStyleTestKey(entity.key))
  query = query.order(-graph_data.Row.timestamp)
  last_row = yield query.get_async()

  # Check if the test should be deleted entirely.
  now = datetime.datetime.now()

  if not last_row or last_row.timestamp < now - _REMOVAL_REVISON_DELTA:
    # descendants = list_tests.GetTestDescendants(entity.key, keys_only=True)
    child_paths = '/'.join([entity.key.id(), '*'])
    descendants = yield list_tests.GetTestsMatchingPatternAsync(child_paths)

    if entity.key in descendants:
      descendants.remove(entity.key)
    if not descendants:
      logging.info('removing')
      if last_row:
        logging.info('last row timestamp: %s', last_row.timestamp)
      else:
        logging.info('no last row, no descendants')

      _AddDeleteTestDataTask(entity)
      return

  if entity.deprecated:
    return

  # You shouldn't mix sync and async code, and TestMetadata.put() invokes a
  # complex _pre_put_hook() that will take a lot of work to get rid of. For
  # now we simply queue up a separate task to do the actual test deprecation.
  # This happens infrequently anyway, the much more common case is nothing
  # happens.
  if not last_row:
    should_deprecate = yield _CheckSuiteShouldBeDeprecated(entity)
    if should_deprecate:
      _AddDeprecateTestDataTask({
          'type': 'deprecate-test',
          'test_key': entity.key.urlsafe()})
    return

  if last_row.timestamp < now - _DEPRECATION_REVISION_DELTA:
    _AddDeprecateTestDataTask({
        'type': 'deprecate-test',
        'test_key': entity.key.urlsafe()})