File tree Expand file tree Collapse file tree
tests/system/Database/Live Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616use CodeIgniter \Config \BaseConfig ;
1717use CodeIgniter \Exceptions \InvalidArgumentException ;
1818use Config \Database as DbConfig ;
19+ use Throwable ;
1920
2021/**
2122 * @see \CodeIgniter\Database\ConfigTest
@@ -184,7 +185,12 @@ public static function cleanupForWorkerMode(): void
184185 log_message ('error ' , "Uncommitted transaction detected in database group ' {$ group }'. Transactions must be completed before request ends. " );
185186
186187 while ($ connection ->transDepth > 0 ) {
187- $ connection ->transRollback ();
188+ try {
189+ $ connection ->transRollback ();
190+ } catch (Throwable $ e ) {
191+ log_message ('critical ' , $ e ->getMessage ());
192+ break ;
193+ }
188194 }
189195 }
190196
Original file line number Diff line number Diff line change 1818use CodeIgniter \Test \CIUnitTestCase ;
1919use CodeIgniter \Test \DatabaseTestTrait ;
2020use PHPUnit \Framework \Attributes \Group ;
21+ use RuntimeException ;
2122
2223/**
2324 * @internal
@@ -48,6 +49,22 @@ public function testCleanupForWorkerMode(): void
4849 $ this ->assertNotFalse ($ this ->getPrivateProperty ($ conn , 'connID ' ));
4950 }
5051
52+ public function testCleanupForWorkerModeLogsRollbackCallbackException (): void
53+ {
54+ $ conn = Config::connect ();
55+ $ this ->assertInstanceOf (BaseConnection::class, $ conn );
56+
57+ $ conn ->transStart ();
58+ $ conn ->afterRollback (static function (): void {
59+ throw new RuntimeException ('Rollback callback failed. ' );
60+ });
61+
62+ Config::cleanupForWorkerMode ();
63+
64+ $ this ->assertSame (0 , $ conn ->transDepth );
65+ $ this ->assertLogged ('critical ' , 'Rollback callback failed. ' );
66+ }
67+
5168 public function testReconnectForWorkerMode (): void
5269 {
5370 $ conn = Config::connect ();
You can’t perform that action at this time.
0 commit comments