σ
P'^c           @@  s+  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 m
 Z
 d  d l m Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z d  d	 l m Z e j   Z d
   Z d d d d  Z d e f d     YZ d e f d     YZ d S(   i    (   t   absolute_importN(   t   count(   t   time(   t   current_app(   t   TimeoutError(   t   flatten_reply(   t   qualname(   t   Casec         C@  s   t  j j d |   d  S(   Ns   %s
(   t   syst   stderrt   write(   t   msg(    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   say   s    s	   Timed outi
   g      ΰ?c         C@  sV   t    } xF t d  D]8 } t    | | k r; t    n  |    } | r | Sq Wd  S(   Ni    (   R   R   R   (   t   funt   reasont   timeoutt   intervalt
   time_startt
   iterationst   ret(    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt	   try_while   s    		t   Workerc           B@  s   e  Z e Z e d   Z e Z d d d  Z d   Z	 d   Z
 d   Z d  d  Z d d d	  Z d d d
  Z d   Z e d d d   Z RS(   i   t   errorc         C@  s+   | |  _  | |  _ | p! t j   |  _ d  S(   N(   t   hostnamet   loglevelR   t   _get_current_objectt   app(   t   selfR   R   R   (    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   __init__+   s    		c         C@  s#   |  j  s |  j   t |  _  n  d  S(   N(   t   startedt   _fork_and_exect   True(   R   (    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   start0   s    	
c         C@  sZ   t  j   } | d k rM |  j j d d d |  j d d g  t  j d  n  | |  _ d  S(   Ni    t   workers   --loglevel=INFOs   -ns   -Pt   solo(   t   ost   forkR   t   worker_mainR   t   _exitt   pid(   R   R'   (    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyR   5   s    	c         O@  s   |  j  j j | |   S(   N(   R   t   controlt   ping(   R   t   argst   kwargs(    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyR)   >   s    c         C@  s1   |  j  d |  j g d |  } |  j t |  k S(   Nt   destinationR   (   R)   R   R   (   R   R   t   r(    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   is_aliveA   s    i
   g      ΰ?c         @  s>   t     f d   d | d   d | t d  j  d  S(   Nc           @  s    j     S(   N(   R.   (    (   R   R   (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   <lambda>G   t    s#   Worker won't start (after %s secs.)R   R   s   --WORKER %s IS ONLINE--(   R   R   R   (   R   R   R   (    (   R   R   s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   wait_until_startedE   s
    
c         @  s]   t  j  j t j  t    f d   d | d d d d t d  j  t  _	 d  S(   Nc           @  s    j     S(   N(   R.   (    (   R   R   (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyR/   P   R0   s&   Worker won't shutdown (after %s secs.)R   i
   R   g      ΰ?s   --WORKER %s IS SHUTDOWN--(
   R#   t   killR'   t   signalt   SIGTERMR   R   R   R   t   _shutdown_called(   R   R   R   (    (   R   R   s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   ensure_shutdownM   s    
c         C@  s   |  j    |  j   d  S(   N(   R    R1   (   R   (    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   ensure_startedW   s    
c         @  s   | p t  j   } | r6 d j t |  | g  } n | t t |  j     7} |  |    j   t j	     t
 j    f d    }  S(   Nt   .c           @  s:    j  s6 t d  j d j    f   j   n  d  S(   Ns.   -- Found worker not stopped at shutdown: %s
%ss   
(   R5   R   R   t   joinR6   (    (   t   stackR!   (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   _ensure_shutdown_oncef   s
    	(   t   sockett   gethostnameR9   R   t   strt   nextt
   worker_idsR7   t	   tracebackt   format_stackt   atexitt   register(   t   clsR   t   callerR;   (    (   R:   R!   s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   managed[   s    
N(   t   __name__t
   __module__t   FalseR   R   R@   R5   t   NoneR   R    R   R)   R.   R1   R6   R7   t   classmethodRG   (    (    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyR   &   s   				
	t
   WorkerCasec           B@  s°   e  Z e Z d Z e d     Z e d    Z d d  Z	 d d  Z
 d   Z d d  Z d d  Z d d	  Z d d
  Z d d d  Z d d d  Z d d d  Z RS(   c         C@  s8   t  j d  j t  j  t j |  j d |  |  _ d  S(   Nt   amqpRF   (   t   loggingt	   getLoggert   setLevelt   ERRORR   RG   R   R!   (   RE   (    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt
   setUpClassu   s    c         C@  s   |  j  j   d  S(   N(   R!   R6   (   RE   (    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   tearDownClassz   s    i   c         C@  s   |  j  |  j j  d  S(   N(   t
   assertTrueR!   R.   (   R   R   (    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   assertWorkerAlive~   s    c         C@  s"   |  j  j j |  j j g d | S(   NR   (   R   R(   t   inspectR!   R   (   R   R   (    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyRW      s    c         C@  s   t  |  |  j j S(   N(   R   R!   R   (   R   t   response(    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   my_response   s    g      ΰ?c         C@  sT   |  j  d |  j   } | rP x/ | |  j j D] } | d | k r/ t Sq/ Wn  t S(   NR   t   id(   RW   t   activeR!   R   R   RJ   (   R   t   task_idR   R[   t   task(    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   is_accepted   s    c         C@  sT   |  j  d |  j   } | rP x/ | |  j j D] } | d | k r/ t Sq/ Wn  t S(   NR   RZ   (   RW   t   reservedR!   R   R   RJ   (   R   R\   R   R_   R]   (    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   is_reserved   s    c         C@  sX   |  j  d |  j   } | rT x3 | |  j j D] } | d d | k r/ t Sq/ Wn  t S(   NR   t   requestRZ   (   RW   t	   scheduledR!   R   R   RJ   (   R   R\   R   t   schedulet   item(    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   is_scheduled   s    c         C@  s4   |  j  | |  p3 |  j | |  p3 |  j | |  S(   N(   R`   Re   R^   (   R   R\   R   (    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   is_received    s    i
   c         @  s(   t      f d   d d d d d S(   Nc           @  s    j      S(   N(   R^   (    (   R   R   R\   (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyR/   ¦   R0   s    Task not accepted within timeoutR   g      ΰ?R   i
   (   R   (   R   R\   R   R   (    (   R   R   R\   s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   ensure_accepted₯   s    c         @  s(   t      f d   d d d d d S(   Nc           @  s    j      S(   N(   Rf   (    (   R   R   R\   (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyR/   «   R0   s   Task not receied within timeoutR   g      ΰ?R   i
   (   R   (   R   R\   R   R   (    (   R   R   R\   s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   ensure_receivedͺ   s    c         @  s(   t      f d   d d d d d S(   Nc           @  s    j      S(   N(   Re   (    (   R   R   R\   (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyR/   °   R0   s!   Task not scheduled within timeoutR   g      ΰ?R   i
   (   R   (   R   R\   R   R   (    (   R   R   R\   s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   ensure_scheduled―   s    N(   RH   RI   t   HOSTNAMER   RK   R!   RL   RS   RT   RV   RW   RY   R^   R`   Re   Rf   Rg   Rh   Ri   (    (    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyRM   q   s   	(   t
   __future__R    RC   RO   R#   R3   R<   R   RA   t	   itertoolsR   R   t   celeryR   t   celery.exceptionsR   t   celery.app.controlR   t   celery.utils.importsR   t   celery.tests.caseR   R=   Rj   R   R   t   objectR   RM   (    (    (    s>   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/functional/case.pyt   <module>   s&   	
K