|
116 | 116 | ->and(count($logReader->reset()->get()))->toBe(2); |
117 | 117 | }); |
118 | 118 |
|
| 119 | +it('rebuilds the index when the current chunk is evicted but metadata survives', function () { |
| 120 | + File::append($this->file->path, PHP_EOL.makeLaravelLogEntry()); |
| 121 | + |
| 122 | + $path = $this->file->path; |
| 123 | + // Default chunk size, so both entries live in the single (current) chunk. |
| 124 | + $this->file->logs()->scan(); |
| 125 | + |
| 126 | + expect($this->file->logs()->total())->toBe(2); |
| 127 | + |
| 128 | + LogViewerCache::forget(GenerateCacheKey::for($this->file->index(), 'chunk:0')); |
| 129 | + |
| 130 | + // The request that discovers the eviction flags the index for a rebuild. |
| 131 | + IndexedLogReader::clearInstances(); |
| 132 | + $logReader = (new LogFile($path))->logs(); |
| 133 | + |
| 134 | + expect(count($logReader->get()))->toBe(0) |
| 135 | + ->and($logReader->requiresScan())->toBeTrue(); |
| 136 | + |
| 137 | + // The next request (e.g. a page reload) rebuilds the index from scratch. |
| 138 | + IndexedLogReader::clearInstances(); |
| 139 | + $logReader = (new LogFile($path))->logs(); |
| 140 | + |
| 141 | + expect($logReader->requiresScan())->toBeTrue(); |
| 142 | + |
| 143 | + $logReader->scan(); |
| 144 | + |
| 145 | + expect($logReader->requiresScan())->toBeFalse() |
| 146 | + ->and($logReader->total())->toBe(2) |
| 147 | + ->and(count($logReader->reset()->get()))->toBe(2); |
| 148 | +}); |
| 149 | + |
119 | 150 | it('does not flag a rebuild when reading a chunk the index does not know about', function () { |
120 | 151 | $this->file->logs()->scan(); |
121 | 152 |
|
|
0 commit comments