From eab5eb35284f101ce243424ea9bb71965339677c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 25 Sep 2026 15:47:52 +0200 Subject: [PATCH] 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. --- tests/acceptance/bootstrap/CliContext.php | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/acceptance/bootstrap/CliContext.php b/tests/acceptance/bootstrap/CliContext.php index 2ec3c37694..2ac6e976ca 100644 --- a/tests/acceptance/bootstrap/CliContext.php +++ b/tests/acceptance/bootstrap/CliContext.php @@ -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); } /**