mirror of
https://github.com/owncloud/ocis
synced 2026-04-25 17:25:21 +02:00
fix: flaky cli test (#12038)
This commit is contained in:
@@ -562,6 +562,51 @@ class CliContext implements Context {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given the administrator has waited until the file :filename has finished processing
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return void
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function theAdministratorHasWaitedUntilFileHasFinishedProcessing(string $filename): void {
|
||||
$timeout = 30; // seconds
|
||||
$interval = 1; // seconds
|
||||
$startTime = \time();
|
||||
|
||||
// Poll until file is no longer in --processing list (allows time for state transitions).
|
||||
// Replaces fixed wait that assumed deterministic timing.
|
||||
while (true) {
|
||||
$this->theAdministratorListsAllTheUploadSessions("processing");
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(200);
|
||||
$responseArray = $this->getJSONDecodedCliMessage($this->featureContext->getResponse());
|
||||
|
||||
$found = false;
|
||||
foreach ($responseArray as $item) {
|
||||
if (isset($item->filename) && $item->filename === $filename) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
// File is no longer in processing list - abort completed and state updated
|
||||
return;
|
||||
}
|
||||
|
||||
$elapsed = \time() - $startTime;
|
||||
if ($elapsed >= $timeout) {
|
||||
Assert::fail(
|
||||
"Timeout after {$timeout}s: file '{$filename}' is still in processing upload sessions list. " .
|
||||
"Virus scan + abort may not have completed within timeout period.",
|
||||
);
|
||||
}
|
||||
|
||||
\sleep($interval);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ResponseInterface $response
|
||||
*
|
||||
@@ -575,7 +620,7 @@ class CliContext implements Context {
|
||||
// Example Output: "INFO memory is not limited, skipping package=github.com/KimMachineGun/automemlimit/memlimit [{<output-json>}]"
|
||||
// So, only extracting the array of output json from the message
|
||||
\preg_match('/(\[.*\])/', $responseBody["message"], $matches);
|
||||
return \json_decode($matches[1], null, 512, JSON_THROW_ON_ERROR);
|
||||
return isset($matches[1]) ? \json_decode($matches[1], null, 512, JSON_THROW_ON_ERROR) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,7 +29,8 @@ Feature: List upload sessions via CLI command
|
||||
| antivirus | ANTIVIRUS_INFECTED_FILE_HANDLING | abort |
|
||||
And user "Alice" has uploaded file "filesForUpload/filesWithVirus/eicar.com" to "/virusFile.txt"
|
||||
And the config "POSTPROCESSING_DELAY" has been set to "10s" for "postprocessing" service
|
||||
And the administrator has waited for "2" seconds
|
||||
# Polls --processing list until virusFile.txt is absent (30s timeout). Replaces fixed 2s wait.
|
||||
And the administrator has waited until the file "virusFile.txt" has finished processing
|
||||
And user "Alice" has uploaded file with content "uploaded content" to "/file1.txt"
|
||||
And user "Alice" has uploaded file with content "uploaded content" to "/file2.txt"
|
||||
When the administrator lists all the upload sessions with flag "processing"
|
||||
|
||||
Reference in New Issue
Block a user