Skip to content

Commit 548a170

Browse files
committed
EndpointPerformanceTest: add debug print if env variable is set
Use env variable that we can turn off this feature quickly.
1 parent dece3fd commit 548a170

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ jobs:
233233

234234
- run: composer test
235235
working-directory: api
236+
env:
237+
PERFORMANCE_TEST_DEBUG_OUTPUT: ${{ vars.PERFORMANCE_TEST_DEBUG_OUTPUT }}
236238

237239
- name: send coveralls report
238240
run: |

.github/workflows/reusable-api-performance-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ jobs:
6868

6969
- run: composer performance_test
7070
working-directory: api
71+
env:
72+
PERFORMANCE_TEST_DEBUG_OUTPUT: ${{ vars.PERFORMANCE_TEST_DEBUG_OUTPUT }}

api/tests/Api/SnapshotTests/EndpointPerformanceTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use function PHPUnit\Framework\assertThat;
1616
use function PHPUnit\Framework\equalTo;
1717
use function PHPUnit\Framework\greaterThanOrEqual;
18-
use function PHPUnit\Framework\lessThan;
1918
use function PHPUnit\Framework\lessThanOrEqual;
2019
use function PHPUnit\Framework\logicalAnd;
2120

@@ -64,6 +63,10 @@ public function testPerformanceDidNotChangeForStableEndpoints() {
6463
$not200Responses = array_filter($responseCodes, fn ($value) => 200 != $value);
6564
assertThat($not200Responses, equalTo([]));
6665

66+
if (static::isPerformanceTestDebugOutput()) {
67+
var_dump($queryExecutionTime);
68+
}
69+
6770
$endpointsWithTooLongExecutionTime = array_filter($queryExecutionTime, fn ($value) => MAX_EXECUTION_TIME_SECONDS < $value);
6871
assertThat($endpointsWithTooLongExecutionTime, equalTo([]));
6972

@@ -82,10 +85,14 @@ public function testNumberOfQueriesDidNotChangeForContentNodeCollectionEndpoints
8285
if ('test' !== $this->getEnvironment()) {
8386
self::markTestSkipped(__FUNCTION__.' is only run in test environment, not in '.$this->getEnvironment());
8487
}
85-
list($statusCode, $queryCount) = $this->measurePerformanceFor($collectionEndpoint);
88+
list($statusCode, $queryCount, $executionTimeSeconds) = $this->measurePerformanceFor($collectionEndpoint);
8689

8790
assertThat($statusCode, equalTo(200));
8891

92+
if (static::isPerformanceTestDebugOutput()) {
93+
echo "{$collectionEndpoint}: {$executionTimeSeconds}\n";
94+
}
95+
8996
$queryCountRanges = self::getContentNodeEndpointQueryCountRanges()[$collectionEndpoint];
9097
assertThat(
9198
$queryCount,
@@ -116,6 +123,10 @@ public function testNumberOfQueriesDidNotChangeForContentNodeItemEndpoints(strin
116123

117124
assertThat($statusCode, equalTo(200));
118125

126+
if (static::isPerformanceTestDebugOutput()) {
127+
echo "{$collectionEndpoint}: {$executionTimeSeconds}\n";
128+
}
129+
119130
assertThat($executionTimeSeconds, lessThan(MAX_EXECUTION_TIME_SECONDS));
120131

121132
$queryCountRanges = self::getContentNodeEndpointQueryCountRanges()[$collectionEndpoint.'/item'];
@@ -249,4 +260,8 @@ private function getFixtureFor(string $collectionEndpoint) {
249260
private function getEnvironment(): string {
250261
return static::$kernel->getContainer()->getParameter('kernel.environment');
251262
}
263+
264+
private static function isPerformanceTestDebugOutput(): bool {
265+
return 'true' === getenv('PERFORMANCE_TEST_DEBUG_OUTPUT');
266+
}
252267
}

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ services:
6464
# Then PHPStorm will use the corresponding path mappings
6565
PHP_IDE_CONFIG: serverName=localhost
6666
ADDITIONAL_TRUSTED_HOSTS: '.*'
67+
PERFORMANCE_TEST_DEBUG_OUTPUT: ${PERFORMANCE_TEST_DEBUG_OUTPUT:-}
6768
healthcheck:
6869
interval: 10s
6970
timeout: 3s

0 commit comments

Comments
 (0)