Skip to content

Commit d90a33a

Browse files
committed
fix: corrigir contagem de pools ativos para considerar apenas pools não vazios
1 parent b456e90 commit d90a33a

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"performance",
2525
"optimization"
2626
],
27-
"homepage": "https://github.com/CAFernandes/pivotphp-core",
27+
"homepage": "https://github.com/PivotPHP/pivotphp-core",
2828
"license": "MIT",
2929
"authors": [
3030
{
@@ -33,7 +33,7 @@
3333
},
3434
{
3535
"name": "PivotPHP Contributors",
36-
"homepage": "https://github.com/CAFernandes/pivotphp-core/contributors"
36+
"homepage": "https://github.com/PivotPHP/pivotphp-core/contributors"
3737
}
3838
],
3939
"require": {
@@ -159,10 +159,10 @@
159159
]
160160
},
161161
"support": {
162-
"issues": "https://github.com/CAFernandes/pivotphp-core/issues",
163-
"source": "https://github.com/CAFernandes/pivotphp-core",
164-
"docs": "https://github.com/CAFernandes/pivotphp-core/blob/main/README.md",
165-
"wiki": "https://github.com/CAFernandes/pivotphp-core/wiki"
162+
"issues": "https://github.com/PivotPHP/pivotphp-core/issues",
163+
"source": "https://github.com/PivotPHP/pivotphp-core",
164+
"docs": "https://github.com/PivotPHP/pivotphp-core/blob/main/README.md",
165+
"wiki": "https://github.com/PivotPHP/pivotphp-core/wiki"
166166
},
167167
"funding": [
168168
{

src/Json/Pool/JsonBufferPool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function ($a, $b) {
212212
'current_usage' => self::$stats['current_usage'],
213213
'peak_usage' => self::$stats['peak_usage'],
214214
'total_buffers_pooled' => $totalBuffersInPools,
215-
'active_pool_count' => count(self::$pools),
215+
'active_pool_count' => count(array_filter(self::$pools, fn($p) => count($p) > 0)),
216216
'pool_sizes' => $poolSizes, // Legacy format sorted by capacity
217217
'pools_by_capacity' => array_values($poolsByCapacity), // Enhanced format
218218
'detailed_stats' => self::$stats

tests/Json/Pool/JsonBufferPoolStatisticsTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,50 @@ public function testStatisticsConsistency(): void
283283
$this->assertEquals(count($stats['pool_sizes']), count($stats['pools_by_capacity']));
284284
$this->assertEquals($stats['active_pool_count'], count($stats['pools_by_capacity']));
285285
}
286+
287+
/**
288+
* Test that active_pool_count only counts non-empty pools
289+
*/
290+
public function testActivePoolCountOnlyCountsNonEmptyPools(): void
291+
{
292+
// Initial state - no pools
293+
$stats = JsonBufferPool::getStatistics();
294+
$this->assertEquals(0, $stats['active_pool_count']);
295+
296+
// Create buffers but don't return them (pools exist but are empty)
297+
$buffer1KB = JsonBufferPool::getBuffer(1024);
298+
$buffer4KB = JsonBufferPool::getBuffer(4096);
299+
$buffer8KB = JsonBufferPool::getBuffer(8192);
300+
301+
$stats = JsonBufferPool::getStatistics();
302+
$this->assertEquals(0, $stats['active_pool_count'], 'Empty pools should not be counted as active');
303+
304+
// Return only some buffers to pools
305+
JsonBufferPool::returnBuffer($buffer1KB);
306+
JsonBufferPool::returnBuffer($buffer4KB);
307+
308+
$stats = JsonBufferPool::getStatistics();
309+
$this->assertEquals(2, $stats['active_pool_count'], 'Only non-empty pools should be counted as active');
310+
$this->assertEquals(2, $stats['total_buffers_pooled'], 'Should have 2 buffers in pools');
311+
312+
// Return the remaining buffer
313+
JsonBufferPool::returnBuffer($buffer8KB);
314+
315+
$stats = JsonBufferPool::getStatistics();
316+
$this->assertEquals(3, $stats['active_pool_count'], 'All pools with buffers should be counted as active');
317+
$this->assertEquals(3, $stats['total_buffers_pooled'], 'Should have 3 buffers in pools');
318+
319+
// Get all buffers back (making pools empty again)
320+
$retrievedBuffer1 = JsonBufferPool::getBuffer(1024);
321+
$retrievedBuffer2 = JsonBufferPool::getBuffer(4096);
322+
$retrievedBuffer3 = JsonBufferPool::getBuffer(8192);
323+
324+
$stats = JsonBufferPool::getStatistics();
325+
$this->assertEquals(
326+
0,
327+
$stats['active_pool_count'],
328+
'Empty pools should not be counted as active after retrieval'
329+
);
330+
$this->assertEquals(0, $stats['total_buffers_pooled'], 'Should have 0 buffers in pools after retrieval');
331+
}
286332
}

0 commit comments

Comments
 (0)