|
| 1 | +--TEST-- |
| 2 | +FPM: LRU eviction works per-partition and never wipes the pool cache |
| 3 | +--SKIPIF-- |
| 4 | +<?php include __DIR__ . '/skipif.inc'; ?> |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | + |
| 8 | +require_once __DIR__ . '/tester.inc'; |
| 9 | + |
| 10 | +$cfg = <<<EOT |
| 11 | +[global] |
| 12 | +error_log = {{FILE:LOG}} |
| 13 | +[opcache] |
| 14 | +listen = {{ADDR}} |
| 15 | +pm = static |
| 16 | +pm.max_children = 1 |
| 17 | +pm.max_requests = 0 |
| 18 | +catch_workers_output = yes |
| 19 | +EOT; |
| 20 | + |
| 21 | +$code = <<<'PHP' |
| 22 | +<?php |
| 23 | +$cache = UserCache\Cache::getPool('p'); |
| 24 | +$blob = str_repeat('x', 8192); |
| 25 | +$action = $_GET['action'] ?? 'fill'; |
| 26 | +
|
| 27 | +if ($action === 'fill') { |
| 28 | + $stored = 0; |
| 29 | + for ($i = 0; $i < 476; $i++) { |
| 30 | + if (!$cache->store('k' . $i, $blob . $i)) { |
| 31 | + break; |
| 32 | + } |
| 33 | + $stored++; |
| 34 | + } |
| 35 | + var_dump($stored > 400); |
| 36 | + echo "fill\n"; |
| 37 | + return; |
| 38 | +} |
| 39 | +
|
| 40 | +if ($action === 'touch') { |
| 41 | + $alive = 0; |
| 42 | + for ($i = 0; $i < 10; $i++) { |
| 43 | + if ($cache->fetch('k' . $i) !== null) { |
| 44 | + $alive++; |
| 45 | + } |
| 46 | + } |
| 47 | + var_dump($alive === 10); |
| 48 | + echo "touch\n"; |
| 49 | + return; |
| 50 | +} |
| 51 | +
|
| 52 | +$ok = 0; |
| 53 | +for ($i = 0; $i < 30; $i++) { |
| 54 | + if ($cache->store('new' . $i, $blob . 'n' . $i)) { |
| 55 | + $ok++; |
| 56 | + } |
| 57 | +} |
| 58 | +$touched = 0; |
| 59 | +for ($i = 0; $i < 10; $i++) { |
| 60 | + if ($cache->fetch('k' . $i) !== null) { |
| 61 | + $touched++; |
| 62 | + } |
| 63 | +} |
| 64 | +$status = UserCache\Cache::getStatus(); |
| 65 | +var_dump($ok === 30); |
| 66 | +var_dump($touched === 10); |
| 67 | +var_dump($status->getEntryCount() > 400); |
| 68 | +var_dump($status->getEvictionCount() > 0); |
| 69 | +var_dump($status->getExpungeCount() === 0); |
| 70 | +echo "pressure\n"; |
| 71 | +PHP; |
| 72 | + |
| 73 | +$tester = new FPM\Tester($cfg, $code); |
| 74 | +$tester->start(iniEntries: [ |
| 75 | + 'opcache.enable' => '1', |
| 76 | + 'user_cache.shm_size' => '4M', |
| 77 | +]); |
| 78 | +$tester->expectLogStartNotices(); |
| 79 | + |
| 80 | +$tester->request(query: 'action=fill')->expectBody("bool(true)\nfill"); |
| 81 | + |
| 82 | +/* A later request re-stamps a slice of old keys with a fresh request clock. */ |
| 83 | +sleep(1); |
| 84 | +$tester->request(query: 'action=touch')->expectBody("bool(true)\ntouch"); |
| 85 | + |
| 86 | +sleep(1); |
| 87 | +$tester->request(query: 'action=pressure')->expectBody( |
| 88 | + "bool(true)\n" . |
| 89 | + "bool(true)\n" . |
| 90 | + "bool(true)\n" . |
| 91 | + "bool(true)\n" . |
| 92 | + "bool(true)\n" . |
| 93 | + "pressure" |
| 94 | +); |
| 95 | + |
| 96 | +$tester->terminate(); |
| 97 | +$tester->expectLogTerminatingNotices(); |
| 98 | +$tester->close(); |
| 99 | + |
| 100 | +?> |
| 101 | +--EXPECT-- |
0 commit comments