Skip to content

Commit

Permalink
Merge pull request #5293 from BacLuc/debug-print-performance-tests
Browse files Browse the repository at this point in the history
EndpointPerformanceTest: add debug output if env variable is set
  • Loading branch information
BacLuc committed Jun 4, 2024
2 parents 89b8587 + 7f7f970 commit 33a8c09
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ jobs:

- run: composer test
working-directory: api
env:
PERFORMANCE_TEST_DEBUG_OUTPUT: ${{ vars.PERFORMANCE_TEST_DEBUG_OUTPUT }}

- name: send coveralls report
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/reusable-api-performance-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ jobs:

- run: composer performance_test
working-directory: api
env:
PERFORMANCE_TEST_DEBUG_OUTPUT: ${{ vars.PERFORMANCE_TEST_DEBUG_OUTPUT }}
27 changes: 23 additions & 4 deletions api/tests/Api/SnapshotTests/EndpointPerformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use function PHPUnit\Framework\assertThat;
use function PHPUnit\Framework\equalTo;
use function PHPUnit\Framework\greaterThanOrEqual;
use function PHPUnit\Framework\lessThan;
use function PHPUnit\Framework\lessThanOrEqual;
use function PHPUnit\Framework\logicalAnd;

Expand Down Expand Up @@ -64,10 +63,16 @@ public function testPerformanceDidNotChangeForStableEndpoints() {
$not200Responses = array_filter($responseCodes, fn ($value) => 200 != $value);
assertThat($not200Responses, equalTo([]));

if (static::isPerformanceTestDebugOutput()) {
var_dump($queryExecutionTime);
}

$endpointsWithTooLongExecutionTime = array_filter($queryExecutionTime, fn ($value) => MAX_EXECUTION_TIME_SECONDS < $value);
assertThat($endpointsWithTooLongExecutionTime, equalTo([]));

$this->assertMatchesSnapshot($numberOfQueries, new ECampYamlSnapshotDriver());
if ([] !== $endpointsWithTooLongExecutionTime) {
self::markTestSkipped('Some endpoints have too long execution time, were: '.implode(',', array_keys($endpointsWithTooLongExecutionTime)));
}
}

/**
Expand All @@ -82,10 +87,14 @@ public function testNumberOfQueriesDidNotChangeForContentNodeCollectionEndpoints
if ('test' !== $this->getEnvironment()) {
self::markTestSkipped(__FUNCTION__.' is only run in test environment, not in '.$this->getEnvironment());
}
list($statusCode, $queryCount) = $this->measurePerformanceFor($collectionEndpoint);
list($statusCode, $queryCount, $executionTimeSeconds) = $this->measurePerformanceFor($collectionEndpoint);

assertThat($statusCode, equalTo(200));

if (static::isPerformanceTestDebugOutput()) {
echo "{$collectionEndpoint}: {$executionTimeSeconds}\n";
}

$queryCountRanges = self::getContentNodeEndpointQueryCountRanges()[$collectionEndpoint];
assertThat(
$queryCount,
Expand Down Expand Up @@ -116,7 +125,9 @@ public function testNumberOfQueriesDidNotChangeForContentNodeItemEndpoints(strin

assertThat($statusCode, equalTo(200));

assertThat($executionTimeSeconds, lessThan(MAX_EXECUTION_TIME_SECONDS));
if (static::isPerformanceTestDebugOutput()) {
echo "{$collectionEndpoint}: {$executionTimeSeconds}\n";
}

$queryCountRanges = self::getContentNodeEndpointQueryCountRanges()[$collectionEndpoint.'/item'];
assertThat(
Expand All @@ -126,6 +137,10 @@ public function testNumberOfQueriesDidNotChangeForContentNodeItemEndpoints(strin
lessThanOrEqual($queryCountRanges[1]),
)
);

if ($executionTimeSeconds > MAX_EXECUTION_TIME_SECONDS) {
self::markTestSkipped("Endpoint {$collectionEndpoint} has too long execution time: {$executionTimeSeconds}");
}
}

/**
Expand Down Expand Up @@ -249,4 +264,8 @@ private function getFixtureFor(string $collectionEndpoint) {
private function getEnvironment(): string {
return static::$kernel->getContainer()->getParameter('kernel.environment');
}

private static function isPerformanceTestDebugOutput(): bool {
return 'true' === getenv('PERFORMANCE_TEST_DEBUG_OUTPUT');
}
}
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ services:
# Then PHPStorm will use the corresponding path mappings
PHP_IDE_CONFIG: serverName=localhost
ADDITIONAL_TRUSTED_HOSTS: '.*'
PERFORMANCE_TEST_DEBUG_OUTPUT: ${PERFORMANCE_TEST_DEBUG_OUTPUT:-}
healthcheck:
interval: 10s
timeout: 3s
Expand Down

0 comments on commit 33a8c09

Please sign in to comment.