Skip to content

Commit 33a8c09

Browse files
authored
Merge pull request #5293 from BacLuc/debug-print-performance-tests
EndpointPerformanceTest: add debug output if env variable is set
2 parents 89b8587 + 7f7f970 commit 33a8c09

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

.github/workflows/continuous-integration.yml

+2
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

+2
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

+23-4
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,10 +63,16 @@ 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);
68-
assertThat($endpointsWithTooLongExecutionTime, equalTo([]));
6971

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

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

8792
assertThat($statusCode, equalTo(200));
8893

94+
if (static::isPerformanceTestDebugOutput()) {
95+
echo "{$collectionEndpoint}: {$executionTimeSeconds}\n";
96+
}
97+
8998
$queryCountRanges = self::getContentNodeEndpointQueryCountRanges()[$collectionEndpoint];
9099
assertThat(
91100
$queryCount,
@@ -116,7 +125,9 @@ public function testNumberOfQueriesDidNotChangeForContentNodeItemEndpoints(strin
116125

117126
assertThat($statusCode, equalTo(200));
118127

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

121132
$queryCountRanges = self::getContentNodeEndpointQueryCountRanges()[$collectionEndpoint.'/item'];
122133
assertThat(
@@ -126,6 +137,10 @@ public function testNumberOfQueriesDidNotChangeForContentNodeItemEndpoints(strin
126137
lessThanOrEqual($queryCountRanges[1]),
127138
)
128139
);
140+
141+
if ($executionTimeSeconds > MAX_EXECUTION_TIME_SECONDS) {
142+
self::markTestSkipped("Endpoint {$collectionEndpoint} has too long execution time: {$executionTimeSeconds}");
143+
}
129144
}
130145

131146
/**
@@ -249,4 +264,8 @@ private function getFixtureFor(string $collectionEndpoint) {
249264
private function getEnvironment(): string {
250265
return static::$kernel->getContainer()->getParameter('kernel.environment');
251266
}
267+
268+
private static function isPerformanceTestDebugOutput(): bool {
269+
return 'true' === getenv('PERFORMANCE_TEST_DEBUG_OUTPUT');
270+
}
252271
}

docker-compose.yml

+1
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)