mirror of
https://github.com/predis/predis.git
synced 2026-09-04 23:08:00 +00:00
Test suite: add test for WATCH in Predis\MultiExecBlock.
This commit is contained in:
@@ -586,5 +586,25 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
|
||||
$this->assertEquals(0, count($replies));
|
||||
}
|
||||
|
||||
function testMultiExecBlock_Watch() {
|
||||
$client1 = RC::getConnection();
|
||||
$client2 = RC::getConnection(true);
|
||||
$client1->flushdb();
|
||||
|
||||
RC::testForAbortedMultiExecException($this, function()
|
||||
use($client1, $client2) {
|
||||
|
||||
$client1->multiExec(array('watch' => 'sentinel'), function($multi)
|
||||
use ($client2) {
|
||||
|
||||
$multi->set('sentinel', 'client1');
|
||||
$multi->get('sentinel');
|
||||
$client2->set('sentinel', 'client2');
|
||||
});
|
||||
});
|
||||
|
||||
$this->assertEquals('client2', $client1->get('sentinel'));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
+15
-1
@@ -44,7 +44,10 @@ class RC {
|
||||
return $connection;
|
||||
}
|
||||
|
||||
public static function getConnection() {
|
||||
public static function getConnection($new = false) {
|
||||
if ($new == true) {
|
||||
return self::createConnection();
|
||||
}
|
||||
if (self::$_connection === null || !self::$_connection->isConnected()) {
|
||||
self::$_connection = self::createConnection();
|
||||
}
|
||||
@@ -149,6 +152,17 @@ class RC {
|
||||
}
|
||||
}
|
||||
|
||||
public static function testForAbortedMultiExecException($testcaseInstance, $wrapFunction) {
|
||||
$thrownException = null;
|
||||
try {
|
||||
$wrapFunction($testcaseInstance);
|
||||
}
|
||||
catch (Predis\AbortedMultiExec $exception) {
|
||||
$thrownException = $exception;
|
||||
}
|
||||
$testcaseInstance->assertType('Predis\AbortedMultiExec', $thrownException);
|
||||
}
|
||||
|
||||
public static function pushTailAndReturn(Predis\Client $client, $keyName, Array $values, $wipeOut = 0) {
|
||||
if ($wipeOut == true) {
|
||||
$client->del($keyName);
|
||||
|
||||
Reference in New Issue
Block a user