Skip to content

Commit 425ad79

Browse files
bigbesTotktonada
authored andcommitted
No more assertion on 0 retries options
This commit changes meanging of the `retry_count` option: now it means amount of attempts to connect after the first one, not overall attempts count. Closes tarantool#83
1 parent e67cb23 commit 425ad79

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Place it into project library path in your IDE.
6767

6868
* `tarantool.persistent` - Enable persistent connections (don't close connections between sessions) (defaults: True, **can't be changed in runtime**)
6969
* `tarantool.timeout` - Connection timeout (defaults: 10 seconds, can be changed in runtime)
70-
* `tarantool.retry_count` - Count of retries for connecting (defaults: 1, can be changed in runtime)
70+
* `tarantool.retry_count` - Count of retries for connecting (defaults: 0, can be changed in runtime). 0 means do not retry in case the connection was failed the first time.
7171
* `tarantool.retry_sleep` - Sleep between connecting retries (defaults: 0.1 second, can be changed in runtime)
7272
* `tarantool.request_timeout` - Read/write timeout for requests (defaults: 10 second, can be changed in runtime)
7373

src/tarantool.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ PHP_INI_BEGIN()
117117
STD_PHP_INI_ENTRY("tarantool.request_timeout", "3600.0", PHP_INI_ALL,
118118
OnUpdateReal, request_timeout, zend_tarantool_globals,
119119
tarantool_globals)
120-
STD_PHP_INI_ENTRY("tarantool.retry_count", "1", PHP_INI_ALL,
120+
STD_PHP_INI_ENTRY("tarantool.retry_count", "0", PHP_INI_ALL,
121121
OnUpdateLong, retry_count, zend_tarantool_globals,
122122
tarantool_globals)
123123
STD_PHP_INI_ENTRY("tarantool.retry_sleep", "10", PHP_INI_ALL,
@@ -252,7 +252,12 @@ static int __tarantool_connect(tarantool_object *t_obj) {
252252
TSRMLS_FETCH();
253253
tarantool_connection *obj = t_obj->obj;
254254
int status = SUCCESS;
255-
long count = TARANTOOL_G(retry_count);
255+
/*
256+
* Amount of connection attempts is always 1 more than
257+
* `retry_count` option value, since the option means
258+
* amount of attempts after the first one.
259+
*/
260+
long count = TARANTOOL_G(retry_count) + 1;
256261
struct timespec sleep_time = {0};
257262
double_to_ts(INI_FLT("retry_sleep"), &sleep_time);
258263
char *err = NULL;
@@ -962,7 +967,7 @@ PHP_RINIT_FUNCTION(tarantool) {
962967

963968
static void php_tarantool_init_globals(zend_tarantool_globals *tarantool_globals) {
964969
tarantool_globals->sync_counter = 0;
965-
tarantool_globals->retry_count = 1;
970+
tarantool_globals->retry_count = 0;
966971
tarantool_globals->retry_sleep = 10;
967972
tarantool_globals->timeout = 3600.0;
968973
tarantool_globals->request_timeout = 3600.0;

test/CreateTest.php

+23
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,28 @@ public static function provideGoodCredentials()
163163
['guest', null],
164164
];
165165
}
166+
167+
public function test_10_zero_retry_exception() {
168+
/*
169+
* gh-83: An attempt to connection with `retry_count = 0`
170+
* gives the following error:
171+
*
172+
* | Uncaught TarantoolIOException: (null)
173+
*
174+
* Now the option means amount of attempts to connect
175+
* after the first one, not an overall attempts to
176+
* connect. So zero becomes valid value.
177+
*/
178+
179+
$saved_retry_count = ini_get('tarantool.retry_count');
180+
ini_set('tarantool.retry_count', 0);
181+
182+
try {
183+
$c = new Tarantool('localhost', self::$port);
184+
$this->assertEquals($c->ping(), true);
185+
} finally {
186+
ini_set('tarantool.retry_count', $saved_retry_count);
187+
}
188+
}
166189
}
167190

0 commit comments

Comments
 (0)