Skip to content

Commit 1917ae6

Browse files
committed
Fix for closing connection if Tarantool throws an error
closes gh-88
1 parent b155500 commit 1917ae6

File tree

2 files changed

+41
-34
lines changed

2 files changed

+41
-34
lines changed

src/tarantool.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,12 @@ static int64_t tarantool_step_recv(
316316
}
317317
THROW_EXC("Query error %d: %s", errcode, Z_STRVAL_P(errstr),
318318
Z_STRLEN_P(errstr));
319-
goto error;
319+
goto error_noclose;
320320
}
321321
THROW_EXC("Failed to retrieve answer code");
322322
error:
323323
obj->stream = NULL;
324+
error_noclose:
324325
if (header) zval_ptr_dtor(header);
325326
if (body) zval_ptr_dtor(body);
326327
SSTR_LEN(obj->value) = 0;

test/AssertTest.php

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,49 @@
11
<?php
22
class AssertTest extends PHPUnit_Framework_TestCase
33
{
4-
protected static $tarantool, $tm;
4+
protected static $tarantool, $tm;
55

6-
public static function setUpBeforeClass()
7-
{
8-
self::$tm = ini_get("tarantool.request_timeout");
9-
ini_set("tarantool.request_timeout", "0.1");
10-
self::$tarantool = new Tarantool('localhost', getenv('PRIMARY_PORT'));
11-
self::$tarantool->authenticate('test', 'test');
12-
}
6+
public static function setUpBeforeClass() {
7+
self::$tm = ini_get("tarantool.request_timeout");
8+
ini_set("tarantool.request_timeout", "0.1");
9+
self::$tarantool = new Tarantool('localhost', getenv('PRIMARY_PORT'));
10+
self::$tarantool->authenticate('test', 'test');
11+
}
1312

14-
public static function tearDownAfterClass() {
15-
ini_set("tarantool.request_timeout", self::$tm);
16-
}
13+
public static function tearDownAfterClass() {
14+
ini_set("tarantool.request_timeout", self::$tm);
15+
}
1716

18-
protected function tearDown()
19-
{
20-
$tuples = self::$tarantool->select("test");
21-
foreach($tuples as $value)
22-
self::$tarantool->delete("test", Array($value[0]));
23-
}
17+
protected function tearDown() {
18+
$tuples = self::$tarantool->select("test");
19+
foreach($tuples as $value)
20+
self::$tarantool->delete("test", Array($value[0]));
21+
}
2422

25-
public function test_00_timedout() {
23+
public function test_00_timedout() {
24+
self::$tarantool->eval("
25+
function assertf()
26+
require('fiber').sleep(1)
27+
return 0
28+
end");
29+
try {
30+
self::$tarantool->call("assertf");
31+
$this->assertFalse(True);
32+
} catch (Exception $e) {
33+
$this->assertTrue(strpos($e->getMessage(), "Can't read query") !== False);
34+
}
2635

27-
self::$tarantool->eval("
28-
function assertf()
29-
require('fiber').sleep(1)
30-
return 0
31-
end");
32-
try {
33-
self::$tarantool->call("assertf");
34-
$this->assertFalse(True);
35-
} catch (Exception $e) {
36-
$this->assertTrue(strpos($e->getMessage(),
37-
"Can't read query") !== False);
38-
}
36+
/* We can reconnect and everything will be ok */
37+
self::$tarantool->select("test");
38+
}
3939

40-
/* We can reconnect and everything will be ok */
41-
self::$tarantool->select("test");
42-
}
40+
public function test_01_closed_connection() {
41+
for ($i = 0; $i < 20000; $i++) {
42+
try {
43+
self::$tarantool->call("nonexistentfunction");
44+
} catch (Exception $e) {
45+
$this->assertTrue(strpos($e->getMessage(), "is not defined") !== False);
46+
}
47+
}
48+
}
4349
}

0 commit comments

Comments
 (0)