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