File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace ipl \Tests \Sql ;
4+
5+ use Exception ;
6+ use ipl \Sql \RetryConnection ;
7+
8+ class RetryConnectionTest extends \PHPUnit \Framework \TestCase
9+ {
10+ public function testIsRetryable ()
11+ {
12+ $ db = $ this ->getConnection ();
13+
14+ $ this ->assertTrue ($ db ::isRetryable (new Exception ('SQLState: Connection refused by the server ' )));
15+ $ this ->assertTrue ($ db ::isRetryable (new Exception ('SQLState: Error writing data to the connection ' )));
16+ $ this ->assertTrue ($ db ::isRetryable (new Exception ('SQLState: No such file or directory found ' )));
17+
18+ $ this ->assertFalse ($ db ::isRetryable (new Exception ('SQLState: Cannot start transaction ' )));
19+ $ this ->assertFalse ($ db ::isRetryable (new Exception ('Cannot establish the connection to SQL server ' )));
20+ $ this ->assertFalse ($ db ::isRetryable (new Exception ('Fatal error encountered during command execution ' )));
21+ }
22+
23+ public function testExecutionRetriesGivesUpAfterMaxRetries ()
24+ {
25+ $ this ->expectException (Exception::class);
26+ $ this ->expectExceptionMessage ('SQLSTATE[HY000] [2002] No such file or directory ' );
27+
28+ $ this ->getConnection (2 )->transaction (function () {
29+ });
30+ }
31+
32+ protected function getConnection (int $ retries = 1 ): RetryConnection
33+ {
34+ return new RetryConnection ([
35+ 'db ' => 'mysql ' ,
36+ 'dbname ' => 'foo ' ,
37+ ], $ retries );
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments