| 1 |
<?php |
| 2 |
|
| 3 |
abstract class LockManagerIntegrationTestBase extends MediaWikiIntegrationTestCase { |
| 4 |
|
| 5 |
|
| 6 |
protected $class; |
| 7 |
|
| 8 |
protected $managerA; |
| 9 |
|
| 10 |
protected $managerB; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
abstract protected function getManager( $threadName ); |
| 17 |
|
| 18 |
protected function setUp(): void { |
| 19 |
$this->managerA = $this->getManager( 'A' ); |
| 20 |
$this->managerB = $this->getManager( 'B' ); |
| 21 |
$this->class = get_class( $this->managerA ); |
| 22 |
} |
| 23 |
|
| 24 |
public function testLockUnlockEx() { |
| 25 |
$managerA = $this->managerA; |
| 26 |
$managerB = $this->managerB; |
| 27 |
$rand = wfRandomString(); |
| 28 |
$path = "unit_testing://resource/$rand/photo.jpeg"; |
| 29 |
|
| 30 |
$status = $managerA->lock( [ $path ], LockManager::LOCK_EX ); |
| 31 |
$this->assertStatusGood( $status, "Lock (outer) succeeded ({$this->class})." ); |
| 32 |
|
| 33 |
$status = $managerA->lock( [ $path ], LockManager::LOCK_EX ); |
| 34 |
$this->assertStatusGood( $status, "Lock (inner) succeeded ({$this->class})." ); |
| 35 |
|
| 36 |
$status = $managerB->lock( [ $path ], LockManager::LOCK_EX ); |
| 37 |
$this->assertStatusNotGood( $status, "Lock (EX) conflicted ({$this->class})." ); |
| 38 |
|
| 39 |
$status = $managerB->lock( [ $path ], LockManager::LOCK_SH ); |
| 40 |
$this->assertStatusNotGood( $status, "Lock (SH) conflicted ({$this->class})." ); |
| 41 |
|
| 42 |
$status = $managerA->unlock( [ $path ], LockManager::LOCK_EX ); |
| 43 |
$this->assertStatusGood( $status, "Unlock (inner) succeeded ({$this->class})." ); |
| 44 |
|
| 45 |
$status = $managerB->lock( [ $path ], LockManager::LOCK_EX ); |
| 46 |
$this->assertStatusNotGood( $status, "Lock still conflicted ({$this->class})." ); |
| 47 |
|
| 48 |
$status = $managerB->lock( [ $path ], LockManager::LOCK_SH ); |
| 49 |
$this->assertStatusNotGood( $status, "Lock still conflicted ({$this->class})." ); |
| 50 |
|
| 51 |
$status = $managerA->unlock( [ $path ], LockManager::LOCK_EX ); |
| 52 |
$this->assertStatusGood( $status, "Unlock (outer) succeeded ({$this->class})." ); |
| 53 |
|
| 54 |
$status = $managerB->lock( [ $path ], LockManager::LOCK_EX ); |
| 55 |
$this->assertStatusGood( $status, "Lock now succeeded ({$this->class})." ); |
| 56 |
|
| 57 |
$status = $managerB->unlock( [ $path ], LockManager::LOCK_EX ); |
| 58 |
$this->assertStatusGood( $status, "Unlock succeeded ({$this->class})." ); |
| 59 |
} |
| 60 |
|
| 61 |
public function testLockUnlockSh() { |
| 62 |
$managerA = $this->managerA; |
| 63 |
$managerB = $this->managerB; |
| 64 |
$rand = wfRandomString(); |
| 65 |
$path = "unit_testing://resource/$rand/file.png"; |
| 66 |
|
| 67 |
$status = $managerA->lock( [ $path ], LockManager::LOCK_SH ); |
| 68 |
$this->assertStatusGood( $status, "Lock (outer) succeeded ({$this->class})." ); |
| 69 |
|
| 70 |
$status = $managerA->lock( [ $path ], LockManager::LOCK_SH ); |
| 71 |
$this->assertStatusGood( $status, "Lock (inner) succeeded ({$this->class})." ); |
| 72 |
|
| 73 |
$status = $managerB->lock( [ $path ], LockManager::LOCK_EX ); |
| 74 |
$this->assertStatusNotGood( $status, "Lock (EX) conflicted ({$this->class})." ); |
| 75 |
|
| 76 |
$status = $managerB->lock( [ $path ], LockManager::LOCK_SH ); |
| 77 |
$this->assertStatusGood( $status, "Lock (SH) obtained ({$this->class})." ); |
| 78 |
|
| 79 |
$status = $managerB->lock( [ $path ], LockManager::LOCK_EX ); |
| 80 |
$this->assertStatusNotGood( $status, "Lock upgrade (EX) conflicted ({$this->class})." ); |
| 81 |
|
| 82 |
$status = $managerA->unlock( [ $path ], LockManager::LOCK_SH ); |
| 83 |
$this->assertStatusGood( $status, "Unlock (inner) succeeded ({$this->class})." ); |
| 84 |
|
| 85 |
$status = $managerB->lock( [ $path ], LockManager::LOCK_EX ); |
| 86 |
$this->assertStatusNotGood( $status, "Lock (EX) still conflicted ({$this->class})." ); |
| 87 |
|
| 88 |
$status = $managerA->unlock( [ $path ], LockManager::LOCK_SH ); |
| 89 |
$this->assertStatusGood( $status, "Unlock (outer) succeeded ({$this->class})." ); |
| 90 |
|
| 91 |
$status = $managerB->lock( [ $path ], LockManager::LOCK_EX ); |
| 92 |
$this->assertStatusGood( $status, "Lock upgrade (EX) now obtained ({$this->class})." ); |
| 93 |
|
| 94 |
$status = $managerB->unlock( [ $path ], LockManager::LOCK_EX ); |
| 95 |
$this->assertStatusGood( $status, "Unlock (EX) succeeded ({$this->class})." ); |
| 96 |
|
| 97 |
$status = $managerB->unlock( [ $path ], LockManager::LOCK_SH ); |
| 98 |
$this->assertStatusGood( $status, "Unlock (SH) succeeded ({$this->class})." ); |
| 99 |
} |
| 100 |
} |