api-test: wait for upload session cleanup after scenario

The AfterScenario hook only asserted that the clean command returned
200, but cleaning sessions happens asynchronously in the daemon. Poll
the session list until it is empty (60s deadline) so leftover sessions
do not leak into the next scenario.
This commit is contained in:
Jörn Friedrich Dreyer committed 2026-09-25 17:34:50 +02:00
1 parent 04ad5b84bb
commit eab5eb3528
1 file changed
+32
+32
View File
@@ -655,6 +655,7 @@ class CliContext implements Context {
* @AfterScenario @cli-uploads-sessions
*
* @return void
* @throws JsonException
*/
public function cleanUploadsSessions(): void {
$command = "storage-users uploads sessions --clean";
@@ -663,6 +664,37 @@ class CliContext implements Context {
];
$response = CliHelper::runCommand($body);
Assert::assertEquals("200", $response->getStatusCode(), "Failed to clean upload sessions");
// Cleaning upload sessions happens asynchronously in the daemon, so wait
// until all sessions are actually gone. Otherwise leftover sessions would
// leak into the next scenario.
$deadline = \time() + 60;
$sessions = $this->listUploadSessions();
while (count($sessions) > 0 && \time() < $deadline) {
\sleep(1);
$sessions = $this->listUploadSessions();
}
$sessionNames = \array_map(
static fn ($session) => $session->filename ?? "?",
$sessions
);
Assert::assertCount(
0,
$sessions,
"Upload sessions were not cleaned up in time: " . \json_encode($sessionNames)
);
}
/**
* Lists all upload sessions via the CLI.
*
* @return array
* @throws JsonException
*/
private function listUploadSessions(): array {
$response = CliHelper::runCommand(["command" => "storage-users uploads sessions --json"]);
Assert::assertEquals("200", $response->getStatusCode(), "Failed to list upload sessions");
return $this->getJSONDecodedCliMessage($response);
}
/**