Browse Source

Fixed bug, when function Retry::backoffType always return SlowBackoff

Илья 1 year ago
parent
commit
d4ee6b94ac
3 changed files with 9 additions and 4 deletions
  1. 3 0
      CHANGELOG.md
  2. 2 2
      src/Retry/Retry.php
  3. 4 2
      tests/RetryOnExceptionTest.php

+ 3 - 0
CHANGELOG.md

@@ -1,4 +1,7 @@
+* fixed bug, when function Retry::backoffType always return SlowBackoff
+
 # 1.8.0
+
 * update destructor in MemorySessionPool
 * fixed exception on re-create server nodes
 * fixed key name in createTable function

+ 2 - 2
src/Retry/Retry.php

@@ -78,7 +78,7 @@ class Retry
         $retryCount = 0;
         $lastException = null;
         while (microtime(true) < $startTime + $this->timeoutMs / 1000) {
-            $this->logger->debug("YDB: Run user function. Retry count: $retryCount. Ms: ".(microtime(true) - $startTime));
+            $this->logger->debug("YDB: Run user function. Retry count: $retryCount. s: ".(microtime(true) - $startTime));
             try {
                 return $closure();
             } catch (Exception $e) {
@@ -89,7 +89,7 @@ class Retry
                 }
                 $retryCount++;
                 $lastException = $e;
-                $delay = $this->retryDelay($retryCount, $this->backoffType($e))*1000;
+                $delay = $this->retryDelay($retryCount, $this->backoffType(get_class($e)))*1000;
                 usleep($delay);
             }
         }

+ 4 - 2
tests/RetryOnExceptionTest.php

@@ -8,6 +8,7 @@ use YdbPlatform\Ydb\Retry\RetryParams;
 use YdbPlatform\Ydb\Session;
 use YdbPlatform\Ydb\Table;
 use YdbPlatform\Ydb\Ydb;
+use YdbPlatform\Ydb\Logger\SimpleFileLogger;
 
 class SessionManager extends \YdbPlatform\Ydb\Session{
     public static function setSessionId(\YdbPlatform\Ydb\Session $session, string $id){
@@ -46,7 +47,8 @@ class RetryOnExceptionTest extends TestCase
             'credentials' => new AnonymousAuthentication()
         ];
 
-        $ydb = new Ydb($config);
+        $ydb = new Ydb($config, new SimpleFileLogger(7, "l.log"));
+//        $ydb = new Ydb($config);
         $table = $ydb->table();
 
         $session = $table->createSession();
@@ -69,6 +71,6 @@ class RetryOnExceptionTest extends TestCase
                 1,
                 $tres
             );
-        }, true, new RetryParams(20000));
+        }, true, new RetryParams(2000));
     }
 }