ó
úR‹_c           @  sí  d  Z  d d l m Z d d l m Z d d l Z e j d d k rX e d ƒ e Z	 n d e f d	 „  ƒ  YZ	 d d l Z e	 e _ d d l
 j Z d d
 l m Z e j ƒ  d d l
 m Z d d l m Z y d d l m Z Wn! e k
 rd d l m Z n Xd d l m Z d d l Z d d l Z d d l Z e	 e _ d Z e j r]e d 9Z n  d „  Z d „  Z d „  Z  d „  Z! d „  Z" e j# d ƒ e j$ e j% o«e j& d ƒ d e j' f d „  ƒ  Yƒ ƒ Z( e) d k rée j* ƒ  n  d S(   sj   This test checks that underlying socket instances (gevent.socket.socket._sock)
are not leaked by the hub.
iÿÿÿÿ(   t   print_function(   t   socketNi    i   R   t   Socketc           B  s   e  Z d  Z RS(   s"   Something we can have a weakref to(   t   __name__t
   __module__t   __doc__(    (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test__refcount.pyR   %   s   (   t   monkey(   t   flaky(   t   pformat(   t   start_new_thread(   t   sleepgš™™™™™¹?i   c          C  sP   t  j  ƒ  }  |  j t ƒ |  j t  j t  j d ƒ |  j d ƒ |  j d ƒ |  S(   Ni   s	   127.0.0.1i    i   (   s	   127.0.0.1i    (   R   t
   settimeoutt   SOCKET_TIMEOUTt
   setsockoptt
   SOL_SOCKETt   SO_REUSEADDRt   bindt   listen(   t   s(    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test__refcount.pyt   init_server?   s    c         C  s‡   y |  j  ƒ  \ } } Wn$ t j k
 r< | r5 ‚  q= d  Sn X| j d ƒ } | d k sj t t | ƒ ƒ ‚ | j d ƒ } | j ƒ  d  S(   Nid   t   hellot   bye(   t   acceptR   t   timeoutt   recvt   AssertionErrort   reprt   sendt   close(   R   t   raise_on_timeoutt   connt   _t   res(    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test__refcount.pyt   handle_requestH   s    c         C  si   t  j  ƒ  } | j d |  f ƒ | j d ƒ } | j d ƒ } | d k s[ t t | ƒ ƒ ‚ | j ƒ  d  S(   Ns	   127.0.0.1R   id   R   (   R   t   connectR   R   R   R   R   (   t   portR   R    (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test__refcount.pyt   make_requestZ   s    c         C  s¥   t  ƒ  } t t | |  f ƒ |  rE | j ƒ  d } t t | f ƒ n  t d t ƒ t j | j	 ƒ } | j
 ƒ  t j r¡ y t d t ƒ Wq¡ t k
 r q¡ Xn  | S(   Ni   gš™™™™™¹?(   R   R	   R!   t   getsocknameR$   R
   R   t   weakreft   reft   _sockR   t	   greentestt   WINt	   Exception(   t
   run_clientR   R#   t   w(    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test__refcount.pyt   run_interactiong   s    	
	c         C  s·   t  d |  ƒ } t j r% t j ƒ  n  | ƒ  r³ t t t j | ƒ  ƒ ƒ ƒ xW t j | ƒ  ƒ D]C } t t | ƒ ƒ x* t j | ƒ D] } t d t | ƒ ƒ qƒ Wq] Wt d ƒ ‚ n  d  S(   NR,   t   -s   server should be dead by now(	   R.   R)   t   PYPYt   gct   collectt   printR   t   get_referrersR   (   R,   R-   t   xt   y(    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test__refcount.pyt   run_and_check~   s    		sC   Often fail with timeouts or force closed connections; not sure why.s8   Often fail with force closed connections; not sure why. t   Testc           B  sG   e  Z e j Z e j e j ƒ d  „  ƒ Z	 e j e j ƒ d „  ƒ Z
 RS(   c         C  s   t  t ƒ t  t ƒ d  S(   N(   R7   t   True(   t   self(    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test__refcount.pyt   test_clean_exit–   s    
c         C  s   t  t ƒ t  t ƒ d  S(   N(   R7   t   False(   R:   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test__refcount.pyt   test_timeout_exit›   s    
(   R   R   R)   t   LARGE_TIMEOUTt   __timeout__R   t   reraises_flaky_timeoutR   R   R;   R=   (    (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test__refcount.pyR8      s   	t   __main__(+   R   t
   __future__R    t   _socketR   t   c_sockett   syst   version_infot
   __import__R   t   gevent.testingt   testingR)   t   geventR   t	   patch_allR   t   pprintR   t   threadR	   t   ImportErrort   _threadt   timeR
   R&   R1   t   _realsocketR   t   RUNNING_ON_CIR   R!   R$   R.   R7   t   skipOnCIt   skipIft   RUN_LEAKCHECKSt   PY3t   TestCaseR8   R   t   main(    (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test__refcount.pyt   <module>   sL   
		 
									