Skip to content

Commit 7c0f97d

Browse files
author
Willem Stuursma
committed
#16 Add test if is resistant to minor cluster failures
1 parent 3cb8139 commit 7c0f97d

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

tests/mutex/MutexTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ function ($uri) {
110110
}];
111111

112112
$cases["PHPRedisMutex"] = [function () use ($uris) {
113+
/** @var Redis[] $apis */
113114
$apis = array_map(
114115
function ($uri) {
115116
$redis = new Redis();

tests/mutex/PHPRedisMutexTest.php

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,16 @@ private function closeMajorityConnections()
6464
}
6565
}
6666

67+
private function closeMinortyConnections()
68+
{
69+
$numberToClose = ceil(count($this->connections) / 2) - 1;
70+
71+
foreach ((array) array_rand($this->connections, $numberToClose) as $keyToClose) {
72+
$this->connections[$keyToClose]->close();
73+
}
74+
}
75+
6776
/**
68-
* Tests add() fails.
69-
*
70-
* @test
7177
* @expectedException \malkusch\lock\exception\LockAcquireException
7278
* @expectedExceptionCode \malkusch\lock\exception\MutexException::REDIS_NOT_ENOUGH_SERVERS
7379
*/
@@ -97,15 +103,32 @@ public function testEvalScriptFails()
97103
* @param $serialization
98104
* @dataProvider dpSerializationModes
99105
*/
100-
public function testSyncronizedWorks($serialization)
106+
public function testSynchronizedWorks($serialization)
101107
{
102108
foreach ($this->connections as $connection) {
103109
$connection->setOption(Redis::OPT_SERIALIZER, $serialization);
104110
}
105111

106-
$this->mutex->synchronized(function () {
107-
$this->assertTrue(true);
108-
});
112+
$this->assertNull($this->mutex->synchronized(function () {
113+
return null;
114+
}));
115+
}
116+
117+
public function testResistantToPartialClusterFailuresForAcquiringLock()
118+
{
119+
$this->closeMinortyConnections();
120+
121+
$this->assertNull($this->mutex->synchronized(function () {
122+
return null;
123+
}));
124+
}
125+
126+
public function testResistantToPartialClusterFailuresForReleasingLock()
127+
{
128+
$this->assertNull($this->mutex->synchronized(function () {
129+
$this->closeMinortyConnections();
130+
return null;
131+
}));
109132
}
110133

111134
public function dpSerializationModes()

0 commit comments

Comments
 (0)