|
13 | 13 | use Sloop\Database\Exception\InvalidConfigException; |
14 | 14 | use Sloop\Database\Factory\ConnectionFactory; |
15 | 15 | use Sloop\Database\Replica\InMemoryDeadReplicaCache; |
| 16 | +use Sloop\Tests\Support\MutableClock; |
16 | 17 | use Sloop\Tests\Unit\Database\Stub\AlwaysFailConnectionFactory; |
17 | 18 | use Sloop\Tests\Unit\Database\Stub\FixedReplicaSelector; |
18 | 19 | use Sloop\Tests\Unit\Database\Stub\ScriptedConnectionFactory; |
@@ -954,17 +955,14 @@ public function testProbeReplicasRefreshesDeadMarkTtlOnRepeatedFailure(): void |
954 | 955 | { |
955 | 956 | // Use a controllable clock so the assertion proves the dead mark was |
956 | 957 | // re-stamped by the probe rather than just lingering from the pre-mark. |
957 | | - $now = 1000; |
958 | | - $clock = function () use (&$now): int { |
959 | | - return $now; |
960 | | - }; |
961 | | - $deadCache = new InMemoryDeadReplicaCache($clock); |
| 958 | + $clock = new MutableClock(1000); |
| 959 | + $deadCache = new InMemoryDeadReplicaCache($clock(...)); |
962 | 960 |
|
963 | 961 | // Pre-mark with a short TTL that would naturally expire at 1010. |
964 | 962 | $deadCache->markServerDead('replica.internal', 0, 10); |
965 | 963 |
|
966 | 964 | // Advance past the original expiry; sanity-check the pre-mark is gone. |
967 | | - $now = 1100; |
| 965 | + $clock->now = 1100; |
968 | 966 | $this->assertFalse($deadCache->isDead('replica.internal', 0, 'master')); |
969 | 967 |
|
970 | 968 | $factory = new ScriptedConnectionFactory(); |
@@ -996,9 +994,9 @@ public function testProbeReplicasRefreshesDeadMarkTtlOnRepeatedFailure(): void |
996 | 994 | // Still dead between the original 1010 expiry and the new 1160 expiry, |
997 | 995 | // and gone again past 1160. This proves a fresh stamp, not a stale entry. |
998 | 996 | $this->assertTrue($deadCache->isDead('replica.internal', 0, 'master')); |
999 | | - $now = 1150; |
| 997 | + $clock->now = 1150; |
1000 | 998 | $this->assertTrue($deadCache->isDead('replica.internal', 0, 'master')); |
1001 | | - $now = 1170; |
| 999 | + $clock->now = 1170; |
1002 | 1000 | $this->assertFalse($deadCache->isDead('replica.internal', 0, 'master')); |
1003 | 1001 | } |
1004 | 1002 |
|
|
0 commit comments