You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
<?php |
|
/** |
|
* @link http://www.yiiframework.com/ |
|
* @copyright Copyright (c) 2008 Yii Software LLC |
|
* @license http://www.yiiframework.com/license/ |
|
*/ |
|
|
|
namespace yiiunit\framework\mutex; |
|
|
|
use Yii; |
|
use yii\base\InvalidConfigException; |
|
use yiiunit\framework\mutex\mocks\DumbMutex; |
|
use yiiunit\TestCase; |
|
|
|
/** |
|
* Class RetryAcquireTraitTest. |
|
* |
|
* @group mutex |
|
* |
|
* @author Robert Korulczyk <robert@korulczyk.pl> |
|
*/ |
|
class RetryAcquireTraitTest extends TestCase |
|
{ |
|
/** |
|
* @throws InvalidConfigException |
|
*/ |
|
public function testRetryAcquire() |
|
{ |
|
$mutexName = __FUNCTION__; |
|
$mutexOne = $this->createMutex(); |
|
$mutexTwo = $this->createMutex(); |
|
|
|
$this->assertTrue($mutexOne->acquire($mutexName)); |
|
$this->assertFalse($mutexTwo->acquire($mutexName, 1)); |
|
|
|
$this->assertSame(20, $mutexTwo->attemptsCounter); |
|
} |
|
|
|
/** |
|
* @return DumbMutex |
|
* @throws InvalidConfigException |
|
*/ |
|
private function createMutex() |
|
{ |
|
return Yii::createObject([ |
|
'class' => DumbMutex::className(), |
|
]); |
|
} |
|
}
|
|
|