Skip to content

Commit d151a54

Browse files
committed
feat: adicionar verificação de desempenho com limite baseado no ambiente
1 parent ce61606 commit d151a54

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

test_threshold.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
require_once "vendor/autoload.php";
3+
4+
function getPerformanceThreshold(): int
5+
{
6+
if (getenv("CI") \!== false || getenv("GITHUB_ACTIONS") \!== false) {
7+
return 25;
8+
}
9+
if (file_exists("/.dockerenv") || getenv("DOCKER") \!== false) {
10+
return 50;
11+
}
12+
return 100;
13+
}
14+
15+
echo "Threshold atual: " . getPerformanceThreshold() . " req/s
16+
";
17+
echo "CI: " . (getenv("CI") \!== false ? "true" : "false") . "
18+
";
19+
echo "GitHub Actions: " . (getenv("GITHUB_ACTIONS") \!== false ? "true" : "false") . "
20+
";
21+
echo "Docker: " . (file_exists("/.dockerenv") ? "true" : "false") . "
22+
";

tests/Integration/V11ComponentsTest.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,7 @@ public function testDistributedPoolManagerMock(): void
365365

366366
/**
367367
* Test end-to-end high-performance scenario
368-
*/
369-
/**
368+
*
370369
* @group performance
371370
*/
372371
public function testEndToEndHighPerformanceScenario(): void
@@ -421,8 +420,13 @@ function ($req, $res) {
421420
$duration = microtime(true) - $startTime;
422421
$throughput = count($results) / $duration;
423422

424-
// Verify performance (adjusted for CI environment)
425-
$this->assertGreaterThan(10, $throughput, 'Should handle >10 req/s');
423+
// Verify performance with environment-aware threshold
424+
$threshold = $this->getPerformanceThreshold();
425+
$this->assertGreaterThan(
426+
$threshold,
427+
$throughput,
428+
sprintf('Should handle >%d req/s (actual: %.2f req/s)', $threshold, $throughput)
429+
);
426430

427431
// Check monitoring data
428432
$monitor = HighPerformanceMode::getMonitor();
@@ -441,6 +445,33 @@ function ($req, $res) {
441445
$this->assertTrue(true, 'High-performance scenario completed successfully');
442446
}
443447

448+
/**
449+
* Get performance threshold based on environment
450+
*
451+
* This method provides environment-aware performance thresholds to avoid
452+
* masking performance regressions while accounting for CI constraints.
453+
*
454+
* @return int The minimum throughput threshold in requests/second
455+
*/
456+
private function getPerformanceThreshold(): int
457+
{
458+
// Check if running in CI environment
459+
if (getenv('CI') !== false || getenv('GITHUB_ACTIONS') !== false) {
460+
// CI environments are typically constrained
461+
// Use lower threshold but still meaningful for regression detection
462+
return 25; // CI threshold: 25 req/s
463+
}
464+
465+
// Check if running in Docker or containerized environment
466+
if (file_exists('/.dockerenv') || getenv('DOCKER') !== false) {
467+
// Docker environments may have resource constraints
468+
return 50; // Docker threshold: 50 req/s
469+
}
470+
471+
// Local development environment - expect full performance
472+
return 100; // Local threshold: 100 req/s
473+
}
474+
444475
protected function tearDown(): void
445476
{
446477
parent::tearDown();

0 commit comments

Comments
 (0)