|
15 | 15 |
|
16 | 16 | use CodeIgniter\Session\Handlers\RedisHandler; |
17 | 17 | use CodeIgniter\Test\CIUnitTestCase; |
| 18 | +use CodeIgniter\Test\TestLogger; |
| 19 | +use Config\Logger as LoggerConfig; |
18 | 20 | use Config\Session as SessionConfig; |
19 | 21 | use PHPUnit\Framework\Attributes\DataProvider; |
20 | 22 | use PHPUnit\Framework\Attributes\Group; |
@@ -54,7 +56,10 @@ protected function getInstance($options = []): RedisHandler |
54 | 56 | $sessionConfig->{$key} = $value; |
55 | 57 | } |
56 | 58 |
|
57 | | - return new RedisHandler($sessionConfig, $this->userIpAddress); |
| 59 | + $handler = new RedisHandler($sessionConfig, $this->userIpAddress); |
| 60 | + $handler->setLogger(new TestLogger(new LoggerConfig())); |
| 61 | + |
| 62 | + return $handler; |
58 | 63 | } |
59 | 64 |
|
60 | 65 | protected function tearDown(): void |
@@ -359,4 +364,26 @@ public function testResetPersistentConnections(): void |
359 | 364 | $handler1->close(); |
360 | 365 | $handler2->close(); |
361 | 366 | } |
| 367 | + |
| 368 | + public function testLockMaxRetries(): void |
| 369 | + { |
| 370 | + $options = [ |
| 371 | + 'lockRetryInterval' => 10_000, // 10ms |
| 372 | + 'lockMaxRetries' => 3, |
| 373 | + ]; |
| 374 | + |
| 375 | + $handler1 = $this->getInstance($options); |
| 376 | + $handler1->open($this->sessionSavePath, $this->sessionName); |
| 377 | + $handler1->read('lock_test_session'); // Acquires lock |
| 378 | + |
| 379 | + $handler2 = $this->getInstance($options); |
| 380 | + $handler2->open($this->sessionSavePath, $this->sessionName); |
| 381 | + |
| 382 | + // Before the fix, this would incorrectly return true (since $attempt === 3 !== 300). |
| 383 | + // With the fix, it should return false after 3 attempts. |
| 384 | + $this->assertFalse($handler2->read('lock_test_session')); |
| 385 | + |
| 386 | + $handler1->close(); |
| 387 | + $handler2->close(); |
| 388 | + } |
362 | 389 | } |
0 commit comments