Просмотр исходного кода

Test suite: add test for WATCH in Predis\MultiExecBlock.

Daniele Alessandri 14 лет назад
Родитель
Сommit
92d6ad62ce
2 измененных файлов с 35 добавлено и 1 удалено
  1. 20 0
      test/PredisClientFeatures.php
  2. 15 1
      test/PredisShared.php

+ 20 - 0
test/PredisClientFeatures.php

@@ -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
test/PredisShared.php

@@ -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);