@@ -152,7 +152,7 @@ public function testGetStatus()
152
152
$ response = $ connection ->get ('/_admin/statistics ' );
153
153
static ::assertEquals (200 , $ response ->getHttpCode (), 'Did not return http code 200 ' );
154
154
}
155
-
155
+
156
156
/**
157
157
* Test get options
158
158
*/
@@ -208,6 +208,78 @@ public function testSetOptions()
208
208
$ value = $ connection ->getOption (ConnectionOptions::OPTION_RECONNECT );
209
209
static ::assertFalse ($ value );
210
210
}
211
+
212
+ /**
213
+ * Test timeout options handling
214
+ */
215
+ public function testTimeoutOptions ()
216
+ {
217
+ $ connection = getConnection ();
218
+
219
+ $ oldTimeout = $ connection ->getOption (ConnectionOptions::OPTION_TIMEOUT );
220
+ $ oldConnectTimeout = $ connection ->getOption (ConnectionOptions::OPTION_CONNECT_TIMEOUT );
221
+ $ oldRequestTimeout = $ connection ->getOption (ConnectionOptions::OPTION_REQUEST_TIMEOUT );
222
+
223
+ static ::assertEquals ($ oldTimeout , $ oldConnectTimeout );
224
+ static ::assertEquals ($ oldTimeout , $ oldRequestTimeout );
225
+
226
+ $ connection ->setOption (ConnectionOptions::OPTION_TIMEOUT , 12 );
227
+ $ newTimeout = $ connection ->getOption (ConnectionOptions::OPTION_TIMEOUT );
228
+ $ newConnectTimeout = $ connection ->getOption (ConnectionOptions::OPTION_CONNECT_TIMEOUT );
229
+ $ newRequestTimeout = $ connection ->getOption (ConnectionOptions::OPTION_REQUEST_TIMEOUT );
230
+
231
+ static ::assertEquals (12 , $ newTimeout );
232
+ static ::assertEquals (12 , $ newConnectTimeout );
233
+ static ::assertEquals (12 , $ newRequestTimeout );
234
+
235
+ $ connection ->setOption (ConnectionOptions::OPTION_TIMEOUT , 42 );
236
+ $ newTimeout = $ connection ->getOption (ConnectionOptions::OPTION_TIMEOUT );
237
+ $ newConnectTimeout = $ connection ->getOption (ConnectionOptions::OPTION_CONNECT_TIMEOUT );
238
+ $ newRequestTimeout = $ connection ->getOption (ConnectionOptions::OPTION_REQUEST_TIMEOUT );
239
+
240
+ static ::assertEquals (42 , $ newTimeout );
241
+ static ::assertEquals (42 , $ newConnectTimeout );
242
+ static ::assertEquals (42 , $ newRequestTimeout );
243
+
244
+ $ connection ->setOption (ConnectionOptions::OPTION_CONNECT_TIMEOUT , 1.5 );
245
+ try {
246
+ $ connection ->getOption (ConnectionOptions::OPTION_TIMEOUT );
247
+ static ::assertFalse (true );
248
+ } catch (\Exception $ e ) {
249
+ // OPTION_TIMEOUT is gone once OPTION_CONNECT_TIMEOUT is used
250
+ }
251
+
252
+ $ newConnectTimeout = $ connection ->getOption (ConnectionOptions::OPTION_CONNECT_TIMEOUT );
253
+ $ newRequestTimeout = $ connection ->getOption (ConnectionOptions::OPTION_REQUEST_TIMEOUT );
254
+
255
+ static ::assertEquals (1.5 , $ newConnectTimeout );
256
+ static ::assertEquals (42 , $ newRequestTimeout );
257
+
258
+ $ connection ->setOption (ConnectionOptions::OPTION_REQUEST_TIMEOUT , 24.5 );
259
+ $ newConnectTimeout = $ connection ->getOption (ConnectionOptions::OPTION_CONNECT_TIMEOUT );
260
+ $ newRequestTimeout = $ connection ->getOption (ConnectionOptions::OPTION_REQUEST_TIMEOUT );
261
+
262
+ try {
263
+ $ connection ->getOption (ConnectionOptions::OPTION_TIMEOUT );
264
+ static ::assertFalse (true );
265
+ } catch (\Exception $ e ) {
266
+ // OPTION_TIMEOUT is gone once OPTION_REQUEST_TIMEOUT is used
267
+ }
268
+
269
+ static ::assertEquals (1.5 , $ newConnectTimeout );
270
+ static ::assertEquals (24.5 , $ newRequestTimeout );
271
+
272
+
273
+ $ connection ->setOption (ConnectionOptions::OPTION_TIMEOUT , 8 );
274
+ $ newTimeout = $ connection ->getOption (ConnectionOptions::OPTION_TIMEOUT );
275
+ $ newConnectTimeout = $ connection ->getOption (ConnectionOptions::OPTION_CONNECT_TIMEOUT );
276
+ $ newRequestTimeout = $ connection ->getOption (ConnectionOptions::OPTION_REQUEST_TIMEOUT );
277
+
278
+ static ::assertEquals (8 , $ newTimeout );
279
+ static ::assertEquals (8 , $ newConnectTimeout );
280
+ static ::assertEquals (8 , $ newRequestTimeout );
281
+ }
282
+
211
283
212
284
/**
213
285
* Test set invalid options
@@ -340,7 +412,7 @@ public function testSetTimeoutException()
340
412
throw $ exception ;
341
413
}
342
414
}
343
-
415
+
344
416
/**
345
417
* Test timeout, no exception
346
418
*/
@@ -356,6 +428,62 @@ public function testSetTimeout()
356
428
$ cursor = $ statement ->execute ();
357
429
static ::assertCount (1 , $ cursor ->getAll ());
358
430
}
431
+
432
+ /**
433
+ * Test connect timeout, no exception
434
+ */
435
+ public function testSetConnectTimeout ()
436
+ {
437
+ $ connection = getConnection ();
438
+ $ connection ->setOption (ConnectionOptions::OPTION_CONNECT_TIMEOUT , 5 );
439
+ $ query = 'RETURN SLEEP(1) ' ;
440
+
441
+ $ statement = new Statement ($ connection , ['query ' => $ query ]);
442
+
443
+ // should work
444
+ $ cursor = $ statement ->execute ();
445
+ static ::assertCount (1 , $ cursor ->getAll ());
446
+ }
447
+
448
+ /**
449
+ * Test request timeout exception
450
+ *
451
+ * @expectedException \ArangoDBClient\ClientException
452
+ */
453
+ public function testSetRequestTimeoutException ()
454
+ {
455
+ $ connection = getConnection ();
456
+ $ connection ->setOption (ConnectionOptions::OPTION_CONNECT_TIMEOUT , 3 );
457
+ $ connection ->setOption (ConnectionOptions::OPTION_REQUEST_TIMEOUT , 2 );
458
+ $ query = 'RETURN SLEEP(3) ' ;
459
+
460
+ $ statement = new Statement ($ connection , ['query ' => $ query ]);
461
+
462
+ try {
463
+ // this is expected to fail
464
+ $ statement ->execute ();
465
+ } catch (ClientException $ exception ) {
466
+ static ::assertEquals (408 , $ exception ->getCode ());
467
+ throw $ exception ;
468
+ }
469
+ }
470
+
471
+ /**
472
+ * Test request timeout, no exception
473
+ */
474
+ public function testSetRequestTimeout ()
475
+ {
476
+ $ connection = getConnection ();
477
+ $ connection ->setOption (ConnectionOptions::OPTION_CONNECT_TIMEOUT , 5 );
478
+ $ connection ->setOption (ConnectionOptions::OPTION_REQUEST_TIMEOUT , 5 );
479
+ $ query = 'RETURN SLEEP(1) ' ;
480
+
481
+ $ statement = new Statement ($ connection , ['query ' => $ query ]);
482
+
483
+ // should work
484
+ $ cursor = $ statement ->execute ();
485
+ static ::assertCount (1 , $ cursor ->getAll ());
486
+ }
359
487
360
488
/**
361
489
* Test "connection: close"
0 commit comments