
    <e                         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 ej	        Z
 G d d          Z G d dej                  Zedk    r ej                     dS dS )	    N)support)threading_helperc                   &    e Zd Zd Zd Zd Zd ZdS )Timerc                 R    t          j                    | _        d| _        d| _        d S Nr   )	threading	Condition_cond_time_stopselfs    &/usr/lib/python3.11/test/test_sched.py__init__zTimer.__init__   s$    (**




    c                 R    | j         5  | j        cd d d            S # 1 swxY w Y   d S N)r   r   r   s    r   timez
Timer.time   ss    Z 	 	:	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s     c                     |dk    sJ | j         5  || j        z  }| j        |k     r0| j        | _        | j                                          | j        |k     0|| _        d d d            d S # 1 swxY w Y   d S r   )r   r   r   waitr   ts     r   sleepzTimer.sleep   s    AvvvvZ 	 	OA*q..!Z

!!! *q.. DJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA**A.1A.c                     |dk    sJ | j         5  | xj        |z  c_        | j                                          d d d            d S # 1 swxY w Y   d S r   )r   r   
notify_allr   s     r   advancezTimer.advance"   s    AvvvvZ 	$ 	$JJ!OJJJ!!###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   *AAAN)__name__
__module____qualname__r   r   r   r    r   r   r   r      sP          
  
  $ $ $ $ $r   r   c                       e Zd Zd Zd Z ej                    d             Zd Zd Z	 ej                    d             Z
d Zd Zd	 Zd
 Zd ZdS )TestCasec                     g fd}t          j        t          j        t          j                  }dD ]}|                    |d||f          }|                                 |                     g d           d S )Nc                 .                         |           S r   appendxls    r   <lambda>z%TestCase.test_enter.<locals>.<lambda>-        r   )      ?皙?333333?皙?皙?   )r1   r0   r/   r.   r-   sched	schedulerr   r   enterrunassertEqualr   funr5   r)   zr*   s        @r   
test_enterzTestCase.test_enter+   s    ####ODItz::	* 	1 	1A1cA400AA55566666r   c                     g fd}t          j        t          j        t          j                  }dD ]}|                    |d||f          }|                                 |                     g d           d S )Nc                 .                         |           S r   r&   r(   s    r   r+   z(TestCase.test_enterabs.<locals>.<lambda>6   r,   r   皙?{Gz?Q?{Gz?{Gz?r2   )rD   rC   rB   rA   r@   )r4   r5   r   r   enterabsr7   r8   r9   s        @r   test_enterabszTestCase.test_enterabs4   s    ####ODItz::	/ 	4 	4A""1aqd33AA:::;;;;;r   c                 8   t          j                    }|j        }t                      }t	          j        |j        |j                  }|                    dd|d           |                    dd|d           t          j
        |j                  }|                                 |                    d           |                     |                    t                     d           |                     |                                           dD ]}|                    |dz
  d||f          }|                    d           |                     |                    t                     d           |                     |                    t                     d           |                     |                                           |                    d           |                     |                    t                     d	           |                     |                                           |                    d           |                     |                    t                     d
           |                     |                                           |                    d           t'          j        |           |                     |                                           |                     |                                d
           d S )Nr2   r2      rI   targettimeout)         rQ   rO   rP     )queueQueueputr   r4   r5   r   r   r6   r	   Threadr7   startr   r8   getTIMEOUT
assertTrueemptyr   join_thread)r   qr:   timerr5   r   r)   r;   s           r   test_enter_concurrentzTestCase.test_enter_concurrent=   sw   KMMeOEJ<<	1c4(((1c4(((IM222				aw//333		""" 	5 	5AAq#t44AAaw//333w//333		"""aw//333		"""aw//333		"""d$Q'''		"""q)))))r   c           	         g fd}t          j        t          j        t          j                  }g dg dfg dg dfg dg dfg dg dfg}|D ]\  }}|                     ||          5  |D ]}|                    d|||f           |                                 |                     |           |                     |	                                           
                                 d d d            n# 1 swxY w Y   d S )	Nc                 .                         |           S r   r&   r(   s    r   r+   z(TestCase.test_priority.<locals>.<lambda>]   r,   r   )r2   rQ   rI   rO   rP   )rP   rO   rI   rQ   r2   )rQ   rP   rI   r2   rO   )r2   rQ   rI   rQ   r2   )r2   r2   rQ   rQ   rI   )
prioritiesexpectedrD   )r4   r5   r   r   subTestrE   r7   r8   rZ   r[   clear)r   r:   r5   casesrb   rc   priorityr*   s          @r   test_priorityzTestCase.test_priority[   s~   ####ODItz::	 __ooo.__ooo.__ooo.__ooo.	
 %* 		 		 JhGG   * I IH&&tXsXKHHHH  H--- 	 1 1222			              		 		s   .BC>>D	D	c                 H  	 g 		fd}t          j        t          j        t          j                  }t          j                    }|                    |dz   d|d          }|                    |dz   d|d          }|                    |dz   d|d          }|                    |d	z   d|d
          }|                    |dz   d|d          }|                    |           |                    |           |                                 |                     	g d           d S )Nc                 .                         |           S r   r&   r(   s    r   r+   z&TestCase.test_cancel.<locals>.<lambda>s   r,   r   rD   r2   )rD   rC   )rC   rB   )rB   rA   )rA   r@   )r@   )rC   rB   rA   )r4   r5   r   r   rE   cancelr7   r8   )
r   r:   r5   nowevent1event2event3event4event5r*   s
            @r   test_cancelzTestCase.test_cancelq   s   ####ODItz::	ikk##C$J3@@##C$J3@@##C$J3@@##C$J3@@##C$J3@@      .../////r   c                 d   t          j                    }|j        }t                      }t	          j        |j        |j                  }|                                }|                    |dz   d|d          }|                    |dz   d|d          }|                    |dz   d|d          }|                    |dz   d|d          }	|                    |d	z   d|d
          }
t          j
        |j                  }|                                 |                    d           |                     |                    t                     d           |                     |                                           |                    |           |                    |	           |                    d           |                     |                                           |                    d           |                     |                    t                     d	           |                     |                                           |                    d           |                     |                    t                     d           |                     |                                           |                    d           t)          j        |           |                     |                                           |                     |                                d           d S )Nr2   rH   rQ   )rQ   rO   )rO   rP   )rP   rI   rJ   rK   rM   rR   )rS   rT   rU   r   r4   r5   r   r   rE   r	   rV   r7   rW   r   r8   rX   rY   rZ   r[   rk   r   r\   )r   r]   r:   r^   r5   rl   rm   rn   rp   rq   ro   r   s               r   test_cancel_concurrentzTestCase.test_cancel_concurrent   s   KMMeOEJ<<	jjll##C!GQT::##C!GQT::##C!GQT::##C!GQT::##C!GQT::IM222				aw//333		"""      a		"""aw//333		"""aw//333		"""d$Q'''		"""q)))))r   c                 `   g }t          j                    }|                    dd|j        d           |                    dd|j        d          }|                    dd|j        d           |                    |           |                                 |                     |ddg           d S )Nr2   )a)b)crv   rx   )r4   r5   rE   r'   rk   r7   r8   )r   eventsr5   rw   s       r   test_cancel_correct_eventz"TestCase.test_cancel_correct_event   s    O%%	1a777q!V]F;;1a777#s,,,,,r   c                    g fd}t          j        t          j        t          j                  }|                     |                                           dD ]}|                    |d||f          }|                     |                                           |                                 |                     |                                           d S )Nc                 .                         |           S r   r&   r(   s    r   r+   z%TestCase.test_empty.<locals>.<lambda>   r,   r   r?   r2   )	r4   r5   r   r   rZ   r[   rE   assertFalser7   r9   s        @r   
test_emptyzTestCase.test_empty   s    ####ODItz::		))***/ 	4 	4A""1aqd33AA**+++	))*****r   c                   	 g 		fd}t          j        t          j        t          j                  }t          j                    }|                    |dz   d|          }|                    |dz   d|          }|                    |dz   d|          }|                    |dz   d|          }|                    |dz   d|          }|                     |j        |||||g           d S )Nc                 .                         |           S r   r&   r(   s    r   r+   z%TestCase.test_queue.<locals>.<lambda>   r,   r   r@   r2   rD   rC   rA   rB   )r4   r5   r   r   rE   r8   rS   )
r   r:   r5   rl   e5e1e2e4e3r*   s
            @r   
test_queuezTestCase.test_queue   s    ####ODItz::	ikkd
As33d
As33d
As33d
As33d
As33 	2r2r2*>?????r   c           	         g fd}t          j                     }t          j        t           j         t           j                  }|                    |d|           |                    |d|d           |                    |d|d           |                    |d|dddi           |                                 |                     d	i fdi fdi fdddifg           d S )
Nc                  6                         | |f           d S r   r&   )rv   rw   seqs     r   r:   z&TestCase.test_args_kwargs.<locals>.fun   s    JJ1vr   r2   )r2   rQ   )argument)rv   rw   foorI   )r   kwargsr!   )r   r4   r5   r   rE   r7   assertCountEqual)r   r:   rl   r5   r   s       @r   test_args_kwargszTestCase.test_args_kwargs   s   	 	 	 	 	 ikkODItz::	33'''3388833<<<33
KKKcHRLeQZ 	$
 	 	 	 	 	r   c                     g fd}t          j        t          j        t          j                  }dD ]}|                    |d||f           |                    d           |                     g            d S )Nc                 .                         |           S r   r&   r(   s    r   r+   z0TestCase.test_run_non_blocking.<locals>.<lambda>   r,   r   )
   	            r2   F)blockingr3   )r   r:   r5   r)   r*   s       @r   test_run_non_blockingzTestCase.test_run_non_blocking   s    ####ODItz::	! 	- 	-AOOAq#t,,,,u%%%Br   N)r   r   r    r<   rF   r   requires_working_threadingr_   rh   rr   rt   rz   r~   r   r   r   r!   r   r   r#   r#   )   s        7 7 7< < < 1022* * 32*:  ,0 0 0 1022* * 32*>	- 	- 	-	+ 	+ 	+@ @ @  &         r   r#   __main__)rS   r4   r	   r   unittesttestr   test.supportr   SHORT_TIMEOUTrY   r   r#   r   mainr!   r   r   <module>r      s                  ) ) ) ) ) ) 
$ $ $ $ $ $ $ $8u  u  u  u  u x  u  u  u p zHMOOOOO r   