Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor test #99

Merged
merged 6 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* added microseconds in Timestamp type

## 1.8.2

* fixed discovery on exception
* fixed logger in EnvironCredentials

Expand Down
16 changes: 9 additions & 7 deletions tests/RetryParams.php → tests/RetryParamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
use YdbPlatform\Ydb\Exceptions\Grpc\UnavailableException;
use YdbPlatform\Ydb\Exceptions\Grpc\UnimplementedException;
use YdbPlatform\Ydb\Exceptions\Grpc\UnknownException;
use YdbPlatform\Ydb\Exceptions\RetryableException;
use YdbPlatform\Ydb\Exceptions\Ydb\BadRequestException;
use YdbPlatform\Ydb\Exceptions\Ydb\InternalErrorException;
use YdbPlatform\Ydb\Exceptions\Ydb\StatusCodeUnspecified;
use YdbPlatform\Ydb\Exceptions\Ydb\UnauthorizedException;
use YdbPlatform\Ydb\Logger\SimpleStdLogger;
use YdbPlatform\Ydb\Retry\Backoff;
use YdbPlatform\Ydb\Retry\RetryParams;
use YdbPlatform\Ydb\Session;
use YdbPlatform\Ydb\Table;
use YdbPlatform\Ydb\Ydb;
use YdbPlatform\Ydb\Retry\Retry;
Expand All @@ -48,7 +47,7 @@ public function deleteSession(string $exception): bool
}
}

class RetryTest2 extends \PHPUnit\Framework\TestCase
class RetryParamsTest extends \PHPUnit\Framework\TestCase
{
protected const FAST = 5;
protected const SLOW = 20;
Expand Down Expand Up @@ -370,22 +369,25 @@ public function test(){
$retryParams = new RetryParams(1000, new Backoff(6,self::FAST),
new Backoff(6,self::SLOW));

$retry = (new RetrySubclass())->withParams($retryParams);
$table = new TableSubclass(new Ydb(["credentials"=>new AnonymousAuthentication()]), null, $retry);
$logger = new SimpleStdLogger(7);
$retry = (new RetrySubclass($logger))->withParams($retryParams);
$table = new TableSubclass(new Ydb(["credentials"=>new AnonymousAuthentication()]), $logger, $retry);

foreach ($this->errsToCheck as $error) {

$exception = new $error["class"]();

$resultDeleteSession = $table->deleteSession($error["class"]) ? "true" : "false";
$wantDeleteSession = $error["deleteSession"] ? "true" : "false";
self::assertEquals($wantDeleteSession, $resultDeleteSession,
"{$error["class"]}: unexpected delete session status: $resultDeleteSession, want: $wantDeleteSession");

$resultRetryIdempotent = $retry->canRetry(new $error["class"](), true) ? "true" : "false";
$resultRetryIdempotent = $retry->canRetry($exception, true) ? "true" : "false";
$wantRetryIdempotent = $error["retry"]["idempotent"] ? "true" : "false";
self::assertEquals($wantRetryIdempotent, $resultRetryIdempotent,
"{$error["class"]}: unexpected must retry idempotent operation status: $resultRetryIdempotent, want: $wantRetryIdempotent");

$resultRetryNonIdempotent = $retry->canRetry(new $error["class"](), false) ? "true" : "false";
$resultRetryNonIdempotent = $retry->canRetry($exception, false) ? "true" : "false";
$wantRetryNonIdempotent = $error["retry"]["nonIdempotent"] ? "true" : "false";
self::assertEquals($wantRetryNonIdempotent, $resultRetryNonIdempotent,
"{$error["class"]}: unexpected must retry non-idempotent operation status: $resultDeleteSession, want: $wantDeleteSession");
Expand Down
Loading