HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //usr/lib64/python3.9/site-packages/borg/testsuite/__pycache__/locking.cpython-39.opt-1.pyc
a

HZ�h�5�@sddlZddlZddlmZmZddlmZddlZddl	m
Z
ddlmZm
Z
ddlmZmZmZmZmZmZmZmZmZmZmZdZd	Zd
ZdZe��dd
��ZGdd�d�Ze��dd��Z Gdd�d�Z!Gdd�d�Z"e��dd��Z#Gdd�d�Z$dS)�N)�Thread�Lock)�
format_exc�)�	daemonize)�get_process_id�
process_alive)�TimeoutTimer�
ExclusiveLockr�
LockRoster�ADD�REMOVE�SHARED�	EXCLUSIVE�LockTimeout�	NotLocked�	NotMyLock)Zfoo�r)Zbarrr�(g�������?cCs.t�\}}}t�dd�}t|||�s|SqdS)zBReturn a free PID not used by any process (naturally this is racy)i�i�N)r�randomZrandintr)�host�pid�tid�r�</usr/lib64/python3.9/site-packages/borg/testsuite/locking.py�free_pidsrc@seZdZdd�Zdd�ZdS)�TestTimeoutTimercCs"d}t|���}t�|d�dS)N��?g�?)r	�start�time�sleep)�self�timeout�trrr�test_timeoutszTestTimeoutTimer.test_timeoutcCsd\}}t||���}dS)N)Nr)r	r)r!r"r r#rrr�test_notimeout_sleep&sz%TestTimeoutTimer.test_notimeout_sleepN)�__name__�
__module__�__qualname__r$r%rrrrrsrcCst|�d��S)N�lock��str�join�Ztmpdirrrr�lockpath/sr.c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestExclusiveLockcCs0t|dd��}Wd�n1s"0YdS)Nr)r")r
�r!r.r)rrr�test_checks5szTestExclusiveLock.test_checkscCsHt|td���}|��t|td��Wd�n1s:0YdS�N��id)r
�ID1�acquire�
break_lock�ID2r0rrr�test_acquire_break_reacquire9sz.TestExclusiveLock.test_acquire_break_reacquirec	Cslt|td��Lt�t��"t|tdd���Wd�n1s@0YWd�n1s^0YdS)Nr3皙�����?�r4r")r
r5�pytest�raisesrr8r6�r!r.rrrr$?szTestExclusiveLock.test_timeoutc
	Cs,t�\}}}}|||f}d}t||d���}	t||d��Bt�t��|	��Wd�n1sd0YWd�n1s�0Yt�t��|	��Wd�n1s�0Yt||d��Lt�t��"t||dd���Wd�n1s�0YWd�n1�s0YdS)N�zfoo.bar.example.netrrr3r:r;)	rr
r6r<r=r�releaserr)
r!r.rrrr�our_id�dead_id�cant_know_if_dead_id�	dead_lockrrr�test_kill_staleDs
D&z!TestExclusiveLock.test_kill_stalecCs6tt}}t||d���}|j}|�||�|j}dSr2)r5r8r
r6Zunique_name�migrate_lock)r!r.�old_id�new_idr)Zold_unique_nameZnew_unique_namerrr�test_migrate_lockTs
z#TestExclusiveLock.test_migrate_lockc

s�Gdd�d�}�fdd��d
��fdd�	}td�|�}|�}t��d}d\}}tt�D],}	t||||	ft|	||�|fd	�}|��qX|��dS)Nc@s6eZdZd
dd�Zdd�Zdd�Zdd	�Zd
d�ZdS)zBTestExclusiveLock.test_race_condition.<locals>.SynchronizedCounterrcSst�|_||_||_dS�N)�
ThreadingLockr)�count�maxcount)r!rLrrr�__init__eszKTestExclusiveLock.test_race_condition.<locals>.SynchronizedCounter.__init__cSs0|j�|jWd�S1s"0YdSrJ�r)rL�r!rrr�valuejszHTestExclusiveLock.test_race_condition.<locals>.SynchronizedCounter.valuecSs0|j�|jWd�S1s"0YdSrJ)r)rMrPrrr�maxvaluenszKTestExclusiveLock.test_race_condition.<locals>.SynchronizedCounter.maxvaluecSsR|j�8|jd7_|j|jkr*|j|_|jWd�S1sD0YdS�Nr)r)rLrMrPrrr�incrrs
zGTestExclusiveLock.test_race_condition.<locals>.SynchronizedCounter.incrcSs>|j�$|jd8_|jWd�S1s00YdSrSrOrPrrr�decryszGTestExclusiveLock.test_race_condition.<locals>.SynchronizedCounter.decrN)r)r&r'r(rNrQrRrTrUrrrr�SynchronizedCountercs

rVcs0��t|�Wd�n1s"0YdSrJ)�print)�msg)�
print_lockrr�print_locked~sz;TestExclusiveLock.test_race_condition.<locals>.print_lockedc	s$�d|||�f�t|d���}d}|��s�|d7}zvt�||ddd��N|��}	�d|||	f�t�d�|��}	�d	|||	f�Wd�n1s�0YWq&ty��d
||f�Yq&|��}
t	�}�d|||
|f�Yq&0q&�d||f�|du�r |�
�dS)
NzIThread %2d: Starting acquire_release_loop(id=%s, timeout=%d); lockpath=%s���rr�)r4r"r zbThread %2d: Acquired the lock. It's my %d. loop cycle. I am the %d. who has the lock concurrently.g{�G�zt?zjThread %2d: Releasing the lock, finishing my %d. loop cycle. Currently, %d colleagues still have the lock.z9Thread %2d: Got LockTimeout, finishing my %d. loop cycle.zdThread %2d: Exception thrown, finishing my %d. loop cycle. It's the %d. exception seen until now: %sz=Thread %2d: Loop timed out--terminating after %d loop cycles.)r	rZ	timed_outr
rTrr rUrrr,)r4r"�	thread_id�lock_owner_counter�exception_counterrYZlast_threadZtimer�cycleZlock_owner_countZexception_count�e)r.rZrr�acquire_release_loop�s*
4
zCTestExclusiveLock.test_race_condition.<locals>.acquire_release_loop�)Z
differenthosti�)�target�args)N)rWrK�range�RACE_TEST_NUM_THREADSr�RACE_TEST_DURATIONrr,)
r!r.rVrbr^r_�threadZhost_idZ
process_idr]r)r.rYrZr�test_race_conditionas$��
z%TestExclusiveLock.test_race_conditionN)	r&r'r(r1r9r$rErIrjrrrrr/4s
r/c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�TestLockcCs8t|dtd���}t|dtd���}|��|��dS)NF��	exclusiver4)rr5r6r8r@)r!r.Zlock1Zlock2rrr�test_shared�szTestLock.test_sharedcCs2t|dtd��}Wd�n1s$0YdS�NTrl)rr5r0rrr�test_exclusive�szTestLock.test_exclusivecCs@t|dd�� }|��|��Wd�n1s20YdS)NF�rm)rZupgrader0rrr�test_upgrade�szTestLock.test_upgradecCs@t|dd�� }|��|��Wd�n1s20YdS)NTrq)rZ	downgrader0rrr�test_downgrade�szTestLock.test_downgradecCs"t|dtd�}|��|��dSro)rr5r6r@r0rrr�test_got_exclusive_lock�sz TestLock.test_got_exclusive_lockcCsLt|dtd���}|��t|dtd��Wd�n1s>0YdSro)rr5r6r7r8r0rrr�
test_break�szTestLock.test_breakc	CsLt|dtd��Nt�t��$t|dtdd���Wd�n1sD0YWd�n1sb0Yt|dtd��Nt�t��$t|dtdd���Wd�n1s�0YWd�n1s�0Yt|dtd��Pt�t��$t|dtdd���Wd�n1�s0YWd�n1�s>0YdS)NFrlTr:)rmr4r")rr5r<r=rr8r6r>rrrr$�sPPzTestLock.test_timeoutc	Cst�\}}}}|||f}d}t||dd���}	|	j}
t||d��Wd�n1sX0Yt�t��|	��Wd�n1s�0Yt||dd��Lt�t��"t||dd���Wd�n1s�0YWd�n1s�0YdS)Nr?T�r4rmr3r:r;)	rrr6Z_rosterr<r=rr@r)r!r.rrrrrArBrCrD�rosterrrrrE�s
&zTestLock.test_kill_stalecCsZtt}}t||dd���}|�||�|��t||dd���}|�||�|��dS)NTrvF)r5r8rr6rFr@)r!r.rGrHr)rrrrI�s
zTestLock.test_migrate_lockN)r&r'r(rnrprrrsrtrur$rErIrrrrrk�s
rkcCst|�d��S)Nrwr*r-rrr�
rosterpathsrxc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestLockRostercCst|�}|��}|�|�dSrJ)r�loadZsave)r!rxrw�emptyrrr�
test_emptys
zTestLockRoster.test_emptycCsdt|td�}|�tt�t|td�}|�tt�t|td�}|�tt�t|td�}|�tt�dSr2)rr5�modifyrrr8r
)r!rx�roster1Zroster2rrr�test_modify_getszTestLockRoster.test_modify_getcCszt�\}}}}|||f}t||d�}d|_|�tt�d}	t||	d�}d|_|�tt�t|�}
|
�tt�t|�}dS)Nr3Fr?)rrZkill_stale_locksr}rr)r!rxrrrrrArBr~rCZ
killer_rosterZother_killer_rosterrrrrE's
zTestLockRoster.test_kill_stalecCs4tt}}t||d�}|�tt�|�t||�dSr2)r5r8rr}rrrF)r!rxrGrHrwrrrrIDs

z TestLockRoster.test_migrate_lockN)r&r'r(r|rrErIrrrrrysry)%rr�	threadingrrrK�	tracebackrr<Zhelpersr�platformrrZlockingr	r
rrr
rrrrrr5r8rgrhZfixturerrr.r/rkrxryrrrr�<module>s*4


y_