2022-08-26 09:21:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Appwrite\Tests;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-10 08:25:06 +00:00
|
|
|
* Marker trait for classes that support retry functionality.
|
2026-01-15 04:21:05 +00:00
|
|
|
* The actual retry logic is handled by the RetrySubscriber extension.
|
2026-01-10 08:25:06 +00:00
|
|
|
*
|
|
|
|
|
* Test methods can be annotated with #[Retry(count: N)] to enable retries.
|
2026-01-15 04:21:05 +00:00
|
|
|
* When a test with this attribute fails, the RetrySubscriber logs the failure
|
|
|
|
|
* and tracks retry attempts.
|
2022-08-26 09:21:08 +00:00
|
|
|
*/
|
|
|
|
|
trait Retryable
|
|
|
|
|
{
|
|
|
|
|
/**
|
2026-01-10 08:25:06 +00:00
|
|
|
* Get the number of retries configured for the current test method.
|
2022-08-26 09:21:08 +00:00
|
|
|
*
|
|
|
|
|
* @return int
|
|
|
|
|
* @throws \ReflectionException
|
|
|
|
|
*/
|
2026-01-10 08:25:06 +00:00
|
|
|
public function getNumberOfRetries(): int
|
2022-08-26 09:21:08 +00:00
|
|
|
{
|
|
|
|
|
$root = new \ReflectionClass($this);
|
2026-01-10 08:25:06 +00:00
|
|
|
$name = $this->name();
|
|
|
|
|
|
|
|
|
|
if (!$root->hasMethod($name)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 09:21:08 +00:00
|
|
|
$method = $root->getMethod($name);
|
2022-08-30 11:10:15 +00:00
|
|
|
$attributes = $method->getAttributes(Retry::class);
|
2022-08-26 09:21:08 +00:00
|
|
|
$attribute = $attributes[0] ?? null;
|
|
|
|
|
$args = $attribute?->getArguments();
|
2026-01-10 08:25:06 +00:00
|
|
|
$retries = $args['count'] ?? $args[0] ?? 0;
|
2022-08-26 09:21:08 +00:00
|
|
|
return \max(0, $retries);
|
|
|
|
|
}
|
|
|
|
|
}
|