File tree Expand file tree Collapse file tree 4 files changed +51
-1
lines changed Expand file tree Collapse file tree 4 files changed +51
-1
lines changed Original file line number Diff line number Diff 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 ` - Amount of attempts to connect (defaults: 1, can be changed in runtime)
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
Original file line number Diff line number Diff line change @@ -257,6 +257,11 @@ static int __tarantool_connect(tarantool_object *t_obj) {
257257 double_to_ts (INI_FLT ("retry_sleep" ), & sleep_time );
258258 char * err = NULL ;
259259
260+ if (count < 1 ) {
261+ THROW_EXC ("tarantool.retry_count should be 1 or above" );
262+ return FAILURE ;
263+ }
264+
260265 if (t_obj -> is_persistent ) {
261266 if (!obj -> persistent_id )
262267 obj -> persistent_id = pid_pzsgen (obj -> host , obj -> port ,
Original file line number Diff line number Diff line change @@ -163,5 +163,33 @@ public static function provideGoodCredentials()
163163 ['guest ' , null ],
164164 ];
165165 }
166+
167+ public function test_10_zero_retry_exception () {
168+ /* A connection to call iproto_connect_count(). */
169+ $ tarantool = new Tarantool ('localhost ' , self ::$ port , 'test ' , 'test ' );
170+ $ iproto_connect_count_before =
171+ $ tarantool ->call ('iproto_connect_count ' )[0 ][0 ];
172+
173+ $ saved_retry_count = ini_get ('tarantool.retry_count ' );
174+ ini_set ('tarantool.retry_count ' , 0 );
175+
176+ $ exp_err = 'tarantool.retry_count should be 1 or above ' ;
177+ try {
178+ $ c = new Tarantool ('localhost ' , self ::$ port );
179+ $ c ->connect ();
180+ $ this ->assertFalse (true );
181+ } catch (Exception $ e ) {
182+ $ this ->assertInstanceOf (TarantoolException::class, $ e );
183+ $ this ->assertEquals ($ exp_err , $ e ->getMessage ());
184+ } finally {
185+ ini_set ('tarantool.retry_count ' , $ saved_retry_count );
186+ }
187+
188+ /* Verify that no connection attempts were performed. */
189+ $ iproto_connect_count_after =
190+ $ tarantool ->call ('iproto_connect_count ' )[0 ][0 ];
191+ $ this ->assertEquals ($ iproto_connect_count_before ,
192+ $ iproto_connect_count_after );
193+ }
166194}
167195
Original file line number Diff line number Diff line change @@ -180,5 +180,22 @@ function test_6(...)
180180 return ...
181181end
182182
183+ iproto_connect_counter = 0
184+ function iproto_connect_count ()
185+ return iproto_connect_counter
186+ end
187+
188+ box .session .on_connect (function ()
189+ -- box.session.type() was introduced in 1.7.4-370-g0bce2472b.
190+ --
191+ -- We're interested in iproto sessions, but it is okay for our
192+ -- usage scenario to count replication and console sessions
193+ -- too: we only see to a delta and AFAIK our testing harness
194+ -- does not perform any background reconnections.
195+ if box .session .type == nil or box .session .type () == ' binary' then
196+ iproto_connect_counter = iproto_connect_counter + 1
197+ end
198+ end )
199+
183200require (' console' ).listen (os.getenv (' ADMIN_PORT' ))
184201
You can’t perform that action at this time.
0 commit comments