Skip to content

Commit 0684555

Browse files
committed
out-of-sync packages will close connection now.
previously - asserting server. closes gh-57 + add test for request timeout
1 parent 845bcda commit 0684555

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-7
lines changed

src/tarantool.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,14 @@ static int64_t tarantool_step_recv(
364364
HashTable *hash = HASH_OF(*header);
365365
zval **val = NULL;
366366

367-
if (zend_hash_index_find(hash, TNT_SYNC, (void **)&val) == SUCCESS)
368-
assert(Z_LVAL_PP(val) == sync);
367+
if (zend_hash_index_find(hash, TNT_SYNC, (void **)&val) == SUCCESS) {
368+
if (Z_LVAL_PP(val) != sync) {
369+
THROW_EXC("request sync is not equal response sync. "
370+
"closing connection");
371+
tarantool_stream_close(obj TSRMLS_CC);
372+
goto error;
373+
}
374+
}
369375
val = NULL;
370376
if (zend_hash_index_find(hash, TNT_CODE, (void **)&val) == SUCCESS) {
371377
if (Z_LVAL_PP(val) == TNT_OK) {

test/AssertTest.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
class AssertTest extends PHPUnit_Framework_TestCase
3+
{
4+
protected static $tarantool;
5+
6+
public static function setUpBeforeClass()
7+
{
8+
self::$tarantool = new Tarantool('localhost', getenv('PRIMARY_PORT'));
9+
self::$tarantool->authenticate('test', 'test');
10+
}
11+
12+
protected function tearDown()
13+
{
14+
$tuples = self::$tarantool->select("test");
15+
foreach($tuples as $value)
16+
self::$tarantool->delete("test", Array($value[0]));
17+
}
18+
19+
public function test_00_timedout() {
20+
self::$tarantool->eval("
21+
function assertf()
22+
require('fiber').sleep(1)
23+
return 0
24+
end");
25+
try {
26+
self::$tarantool->call("assertf");
27+
$this->assertFalse(True);
28+
} catch (Exception $e) {
29+
$this->assertTrue(strpos($e->getMessage(),
30+
"Can't read query") !== False);
31+
}
32+
try {
33+
sleep(1);
34+
self::$tarantool->select("test");
35+
$this->assertFalse(True);
36+
} catch (Exception $e) {
37+
/* check that we are closing connection */
38+
$this->assertTrue(strpos($e->getMessage(),
39+
"request sync") !== False);
40+
}
41+
/* We can reconnect and everything will be ok */
42+
self::$tarantool->select("test");
43+
}
44+
}

test/shared/tarantool.ini

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
[PHP]
2-
extension = ./tarantool.so
3-
tarantool.timeout = 1.5
4-
tarantool.con_per_host = 5
5-
tarantool.persistent = 1
6-
tarantool.deauthorize = 1
2+
extension = ./tarantool.so
3+
tarantool.timeout = 1.5
4+
tarantool.request_timeout = 0.1
5+
tarantool.con_per_host = 5
6+
tarantool.persistent = 1
7+
tarantool.deauthorize = 1
78

89
[xdebug]
910
remote_autostart = 0

0 commit comments

Comments
 (0)