Skip to content

Commit 8d0916a

Browse files
committed
Added process isolition for tests
1 parent 7aac985 commit 8d0916a

File tree

4 files changed

+74
-7
lines changed

4 files changed

+74
-7
lines changed

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ matrix:
1515
services:
1616
- docker
1717

18+
install:
19+
- composer install
20+
1821
before_install:
1922
- docker pull cheprasov/redis-for-tests:latest;
2023
- docker pull cheprasov/redis-cluster-for-tests:latest;
@@ -46,5 +49,5 @@ before_install:
4649
- docker ps;
4750
- sleep 5;
4851

49-
install:
50-
- composer install
52+
before_script
53+
- if [[ $TRAVIS_PHP_VERSION = 'hhvm' ]] ; then rm ./tests/Unit/Client/AbstractRedisClientIsolatedTest.php; fi;

src/RedisClient/Client/AbstractRedisClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ protected function executeProtocolCommand(ProtocolInterface $Protocol, array $co
170170
return $this->executeProtocolCommand($Protocol, $command, $params);
171171
}
172172
if ($response instanceof AskResponseException) {
173-
$TempRedisProtocol = ProtocolFactory::createRedisProtocol($this, $this->getConfig());
173+
$config = $this->getConfig();
174+
$config['server'] = $response->getServer();
175+
$TempRedisProtocol = ProtocolFactory::createRedisProtocol($this, $config);
174176
$TempRedisProtocol->send(['ASKING']);
175177
return $this->executeProtocolCommand($TempRedisProtocol, $command, $params);
176178
}

tests/Unit/Client/AbstractRedisClientIsolatedTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,70 @@ public function test_ClusterFullMovedErrorResponse() {
158158
$this->assertSame(1, GlobalFunctionMock::getCountCalls('RedisClient\Connection::fgets'));
159159
$this->assertSame(1, GlobalFunctionMock::getCountCalls('RedisClient\Connection::fread'));
160160
}
161+
162+
public function test_ClusterFullAskErrorResponse() {
163+
GlobalFunctionMock::mockFunction('RedisClient\Connection::fwrite', function($h, $m, $c) {
164+
static $data = [
165+
[
166+
'tcp://127.0.0.1:7003',
167+
"*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n",
168+
],
169+
[
170+
'tcp://127.0.0.1:7002',
171+
"*1\r\n$6\r\nASKING\r\n",
172+
],
173+
[
174+
'tcp://127.0.0.1:7002',
175+
"*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n",
176+
],
177+
[
178+
'tcp://127.0.0.1:7003',
179+
"*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n",
180+
],
181+
];
182+
$datum = array_shift($data);
183+
$this->assertSame($datum[0], $h);
184+
$this->assertSame($datum[1], $m);
185+
return $c;
186+
});
187+
188+
GlobalFunctionMock::mockFunction('RedisClient\Connection::fgets', function() {
189+
static $data = [
190+
"-ASK 12182 127.0.0.1:7002\r\n",
191+
"+OK\r\n",
192+
"\$3\r\n",
193+
"\$7\r\n",
194+
];
195+
return array_shift($data);
196+
});
197+
198+
GlobalFunctionMock::mockFunction('RedisClient\Connection::fread', function() {
199+
static $data = [
200+
"bar\r\n",
201+
"bar-bar\r\n"
202+
];
203+
return array_shift($data);
204+
});
205+
206+
$Redis = new RedisClient([
207+
'server' => '127.0.0.1:7001',
208+
'cluster' => [
209+
'enabled' => true,
210+
'clusters' => [
211+
5460 => '127.0.0.1:7001',
212+
10922 => '127.0.0.1:7002',
213+
16383 => '127.0.0.1:7003',
214+
]
215+
]
216+
]);
217+
218+
$this->assertSame('bar', $Redis->get('foo'));
219+
$this->assertSame('bar-bar', $Redis->get('foo'));
220+
221+
$this->assertSame(2, GlobalFunctionMock::getCountCalls('RedisClient\Connection::stream_socket_client'));
222+
$this->assertSame(2, GlobalFunctionMock::getCountCalls('RedisClient\Connection::stream_set_timeout'));
223+
$this->assertSame(4, GlobalFunctionMock::getCountCalls('RedisClient\Connection::fwrite'));
224+
$this->assertSame(4, GlobalFunctionMock::getCountCalls('RedisClient\Connection::fgets'));
225+
$this->assertSame(2, GlobalFunctionMock::getCountCalls('RedisClient\Connection::fread'));
226+
}
161227
}

tests/Unit/GlobalFunctionMock.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ class GlobalFunctionMock {
1414

1515
protected static $mockedFunctions = [];
1616

17-
public static function resetMockFunctions() {
18-
static::$mockedFunctions = [];
19-
}
20-
2117
/**
2218
* @param string $fullname
2319
* @param callable $function

0 commit comments

Comments
 (0)