Exemplo n.º 1
0
  def tearDown(self):
    # Wait for children to exit.
    try:
      timeout_util.WaitForReturnValue([[]], multiprocessing.active_children,
                                      timeout=_EXIT_TIMEOUT)
    except timeout_util.TimeoutError:
      pass

    # Complain if there are any children left over.
    active_children = multiprocessing.active_children()
    for child in active_children:
      if hasattr(child, 'Kill'):
        child.Kill(signal.SIGKILL, log_level=logging.WARNING)
        child.join()
    self.assertEqual(multiprocessing.active_children(), [])
    self.assertEqual(active_children, [])
Exemplo n.º 2
0
def WaitForTreeStatus(status_url=None,
                      period=1,
                      timeout=1,
                      throttled_ok=False):
    """Wait for tree status to be open (or throttled, if |throttled_ok|).

  Args:
    status_url: The status url to check i.e.
      'https://status.appspot.com/current?format=json'
    period: How often to poll for status updates.
    timeout: How long to wait until a tree status is discovered.
    throttled_ok: is TREE_THROTTLED an acceptable status?

  Returns:
    The most recent tree status, either constants.TREE_OPEN or
    constants.TREE_THROTTLED (if |throttled_ok|)

  Raises:
    timeout_util.TimeoutError if timeout expired before tree reached
    acceptable status.
  """
    if not status_url:
        status_url = CROS_TREE_STATUS_JSON_URL

    acceptable_states = set([constants.TREE_OPEN])
    verb = 'open'
    if throttled_ok:
        acceptable_states.add(constants.TREE_THROTTLED)
        verb = 'not be closed'

    timeout = max(timeout, 1)

    def _LogMessage(remaining):
        logging.info('Waiting for the tree to %s (%s left)...', verb,
                     remaining)

    def _get_status():
        return _GetStatus(status_url)

    return timeout_util.WaitForReturnValue(acceptable_states,
                                           _get_status,
                                           timeout=timeout,
                                           period=period,
                                           side_effect_func=_LogMessage)
Exemplo n.º 3
0
 def _TestWaitForReturnValue(self, values, timeout, **kwargs):
     """Run through a test for WaitForReturnValue."""
     func = self.GetFunc(list(range(20)))
     return timeout_util.WaitForReturnValue(values, func, timeout, **kwargs)