File: //usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/test_threads.cpython-38.pyc
U
W[�! � @ s� d Z ddlmZmZ eZddlmZ ddlZddl Z ddl
mZ ddlm
Z
ddlmZ ddlmZ G d d
� d
e
�Ze� �e�� � dS )z2
Tests for implementations of L{IReactorThreads}.
� )�division�absolute_import)�refN)�isInIOThread)�ReactorBuilder)�
ThreadPool)�IReactorThreadsc @ s^ e Zd ZdZefZdd� Zdd� Zdd� Zdd � Z d
d� Z
dd
� Zdd� Zdd� Z
dd� ZdS )�ThreadTestsBuilderzD
Builder for defining tests relating to L{IReactorThreads}.
c s� g �| � � ���� � | �� t� | �� jd� � ��fdd�}��|� | ��d� | ��d d� | ��d d� | �� j d � d
S )z�
C{reactor.getThreadPool()} returns an instance of L{ThreadPool} which
starts when C{reactor.run()} is called and stops before it returns.
z(Pool should not start before reactor.runc s$ �� � j� �� � j� ��� d S �N)�append�started�joined�stop� ��pool�reactor�stater �D/usr/lib/python3/dist-packages/twisted/internet/test/test_threads.py�f( s z0ThreadTestsBuilder.test_getThreadPool.<locals>.f� r z#Pool should start after reactor.run� z-Pool should not be joined before reactor.stopz0Pool should be stopped after reactor.run returnsN)
�buildReactor�
getThreadPoolZassertIsInstancer ZassertFalser �callWhenRunning�
runReactor�
assertTruer
)�selfr r r r �test_getThreadPool s. �
� ��z%ThreadTestsBuilder.test_getThreadPoolc C s, | � � }|�d� |�� }| �|jd� dS )zm
C{reactor.suggestThreadPoolSize()} sets the maximum size of the reactor
threadpool.
� N)r ZsuggestThreadPoolSizer �assertEqual�max)r r r r r r �test_suggestThreadPoolSize: s
z-ThreadTestsBuilder.test_suggestThreadPoolSizec sV | � � � � fdd�}� �d� j|� � �� }| �� d� � �� }| �|| dk � dS )aR
A function scheduled with L{IReactorThreads.callFromThread} invoked
from a delayed call is run immediately in the next reactor iteration.
When invoked from the reactor thread, previous implementations of
L{IReactorThreads.callFromThread} would skip the pipe/socket based wake
up step, assuming the reactor would wake up on its own. However, this
resulted in the reactor not noticing an insert into the thread queue at
the right time (in this case, after the thread queue has been processed
for that reactor iteration).
c s � � � d S r
)r r �r r r �
threadCallS s zAThreadTestsBuilder.test_delayedCallFromThread.<locals>.threadCallr �<