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.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|���}|��rJ�t�|d�|��s6J�dS)N��?g�?)r	�start�	timed_out�time�sleep)�self�timeout�trrr�test_timeouts
zTestTimeoutTimer.test_timeoutcCsfd\}}t||���}|��r"J�t��|jd|ks<J�|��rHJ�t��|jd|ksbJ�dS)N)Nrrr)r	rZtimed_out_or_sleepr Z
start_time)r"r#r!r$rrr�test_notimeout_sleep&sz%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)�TestExclusiveLockcCsDt|dd��$}|��r|��s"J�Wd�n1s60YdS)Nr)r#)r
Z	is_locked�by_me�r"r/r*rrr�test_checks5szTestExclusiveLock.test_checkscCsHt|td���}|��t|td��Wd�n1s:0YdS�N��id)r
�ID1�acquire�
break_lock�ID2r2rrr�test_acquire_break_reacquire9sz.TestExclusiveLock.test_acquire_break_reacquirec	Cslt|td��Lt�t��"t|tdd���Wd�n1s@0YWd�n1s^0YdS)Nr5皙�����?�r6r#)r
r7�pytest�raisesrr:r8�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.netrrr5r<r=)	rr
r8r>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_stalecCs�tt}}|d|dksJ�t||d���}|j|ks<J�|j}|��sNJ�|�||�|j|kshJ�|j}|��szJ�||ks�J�dS�Nrr5)r7r:r
r8r6Zunique_namer1�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|��|��d
ks�Jd��|��dks�Jd
|����|�	�d
ks�Jd|�	���dS)Nc@s6eZdZd
dd�Zdd�Zdd�Zdd	�Zd
d�ZdS)zBTestExclusiveLock.test_race_condition.<locals>.SynchronizedCounterrcSst�|_||_||_dS�N)�
ThreadingLockr*�count�maxcount)r"rOrrr�__init__eszKTestExclusiveLock.test_race_condition.<locals>.SynchronizedCounter.__init__cSs0|j�|jWd�S1s"0YdSrM�r*rO�r"rrr�valuejszHTestExclusiveLock.test_race_condition.<locals>.SynchronizedCounter.valuecSs0|j�|jWd�S1s"0YdSrM)r*rPrSrrr�maxvaluenszKTestExclusiveLock.test_race_condition.<locals>.SynchronizedCounter.maxvaluecSsR|j�8|jd7_|j|jkr*|j|_|jWd�S1sD0YdS�Nr)r*rOrPrSrrr�incrrs
zGTestExclusiveLock.test_race_condition.<locals>.SynchronizedCounter.incrcSs>|j�$|jd8_|jWd�S1s00YdSrVrRrSrrr�decryszGTestExclusiveLock.test_race_condition.<locals>.SynchronizedCounter.decrN)r)r'r(r)rQrTrUrWrXrrrr�SynchronizedCountercs

rYcs0��t|�Wd�n1s"0YdSrM)�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�)r6r#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	rrr
rWr r!rXrrr-)r6r#�	thread_id�lock_owner_counter�exception_counterr\Zlast_threadZtimer�cycleZlock_owner_countZexception_count�e)r/r]rr�acquire_release_loop�s*
4
zCTestExclusiveLock.test_race_condition.<locals>.acquire_release_loop�)Z
differenthosti�)�target�argsrz3Never gained the lock? Something went wrong here...rzKMaximal number of concurrent lock holders was %d. So exclusivity is broken.zFExclusiveLock threw %d exceptions due to unclean concurrency handling.)N)
rZrN�range�RACE_TEST_NUM_THREADSr�RACE_TEST_DURATIONrr-rUrT)
r"r/rYrerarb�threadZhost_idZ
process_idr`r)r/r\r]r�test_race_conditionas(��
z%TestExclusiveLock.test_race_conditionN)	r'r(r)r3r;r%rGrLrmrrrrr04s
r0c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�TestLockcCs�t|dtd���}t|dtd���}t|j�t��dks<J�t|j�t��dksTJ�|j�	tt�rfJ�|j�	t�svJ�|�
�|�
�dS)NF��	exclusiver6rr)rr7r8r:�len�_roster�getrr�emptyrB)r"r/Zlock1Zlock2rrr�test_shared�szTestLock.test_sharedcCstt|dtd��R}t|j�t��dks(J�t|j�t��dks@J�|j�tt�rRJ�Wd�n1sf0YdS)NTrorr)rr7rqrrrsrrrtr2rrr�test_exclusive�szTestLock.test_exclusivecCs�t|dd��b}|��|��t|j�t��dks6J�t|j�t��dksNJ�|j�tt�r`J�Wd�n1st0YdS)NF�rprr)rZupgraderqrrrsrrrtr2rrr�test_upgrade�szTestLock.test_upgradecCspt|dd��P}|��|��t|j�t��dks6J�t|j�t��dksNJ�Wd�n1sb0YdS)NTrwrr)rZ	downgraderqrrrsrrr2rrr�test_downgrade�s
zTestLock.test_downgradecCsFt|dtd�}|��rJ�|��|��s.J�|��|��rBJ�dS)NTro)rr7Zgot_exclusive_lockr8rBr2rrr�test_got_exclusive_lock�sz TestLock.test_got_exclusive_lockcCs|t|dtd���}|��t|j�t��dks2J�t|j�t��dksJJ�t|dt	d��Wd�n1sn0YdS)NTror)
rr7r8r9rqrrrsrrr:r2rrr�
test_break�szTestLock.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)NFroTr<)rpr6r#)rr7r>r?rr:r8r@rrrr%�sPPzTestLock.test_timeoutc	CsVt�\}}}}|||f}d}t||dd���}	|	j}
t||d��8|
�t�t�ksXJ�|
�t�|hkslJ�Wd�n1s�0Y|
�t�t�ks�J�|
�t�t�ks�J�t�	t
��|	��Wd�n1s�0Yt||dd��Nt�	t��"t||dd���Wd�n1�s(0YWd�n1�sH0YdS)NrAT�r6rpr5r<r=)
rrr8rrrsr�setrr>r?rrBr)r"r/rrrrrCrDrErF�rosterrrrrG�s
2&zTestLock.test_kill_stalecCs�tt}}|d|dksJ�t||dd���}|j|ks>J�|�||�|j|ksXJ�|��t||dd���}|j|ks�J�|�||�|j|ks�J�|��dS)NrTr|F)r7r:rr8r6rIrB)r"r/rJrKr*rrrrL�s
zTestLock.test_migrate_lockN)r'r(r)rurvrxryrzr{r%rGrLrrrrrn�s
rncCst|�d��S)Nr~r+r.rrr�
rosterpathsrc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestLockRostercCs*t|�}|��}|�|�|iks&J�dSrM)r�loadZsave)r"rr~rtrrr�
test_emptys
zTestLockRoster.test_emptycCs�t|td�}|�t�t�ks J�|�tt�|�t�thks@J�t|td�}|�tt�|�t�tthksnJ�t|td�}|�tt�|�t�thks�J�t|td�}|�tt�|�t�t�ks�J�dSr4)	rr7rsrr}�modifyrr:r
)r"r�roster1Zroster2rrr�test_modify_getszTestLockRoster.test_modify_getcCst�\}}}}|||f}t||d�}d|_|�t�t�ks@J�|�tt�|�t�|hks`J�d}	t||	d�}d|_|�t�|hks�J�|�tt�|�t�||	hks�J�t|�}
|
�t�|	hks�J�|
�tt�|
�t�||	hks�J�t|�}|�t�||	hk�s
J�dS)Nr5FrA)rrZkill_stale_locksrsrr}r�r)r"rrrrrrCrDr�rEZ
killer_rosterZother_killer_rosterrrrrG's&
zTestLockRoster.test_kill_stalecCs�tt}}|d|dksJ�t||d�}|j|ks8J�|�tt�|�t�|hksXJ�|�t||�|j|kstJ�|�t�|hks�J�dSrH)	r7r:rr6r�rrrsrI)r"rrJrKr~rrrrLDs
z TestLockRoster.test_migrate_lockN)r'r(r)r�r�rGrLrrrrr�sr�)%rr �	threadingrrrN�	tracebackrr>Zhelpersr�platformrrZlockingr	r
rrr
rrrrrr7r:rjrkZfixturerrr/r0rnrr�rrrr�<module>s*4


y_