Skip to content

Commit

Permalink
Merge a29e949 into e63894e
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Apr 23, 2021
2 parents e63894e + a29e949 commit 6ada566
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 21 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/main.yml
@@ -0,0 +1,73 @@
#
# JBZoo Toolbox - Retry
#
# This file is part of the JBZoo Toolbox project.
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
#
# @package Retry
# @license MIT
# @copyright Copyright (C) JBZoo.com, All rights reserved.
# @link https://github.com/JBZoo/Retry
#

name: Continuous Integration

on:
pull_request:
branches:
- "*"
push:
branches:
- 'master'
schedule:
- cron: '15 */8 * * *'

env:
COLUMNS: 120
TERM_PROGRAM: Hyper

jobs:
phpunit:
name: Tests
runs-on: ubuntu-latest
env:
JBZOO_COMPOSER_UPDATE_FLAGS: ${{ matrix.composer_flags }}
strategy:
matrix:
php-version: [ 7.2, 7.3, 7.4 ]
experimental: [ false ]
composer_flags: [ "--prefer-lowest", "" ]
include:
- php-version: "8.0"
experimental: true
- php-version: "8.1"
experimental: true
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup PHP and composer
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug
tools: composer

- name: Build the Project
continue-on-error: ${{ matrix.experimental }}
run: make update --no-print-directory

- name: 🧪 PHPUnit Tests
continue-on-error: ${{ matrix.experimental }}
run: make test --no-print-directory

- name: 👍 Code Quality
continue-on-error: ${{ matrix.experimental }}
run: make codestyle --no-print-directory

- name: 📝 Build All Reports at Once
continue-on-error: ${{ matrix.experimental }}
run: make report-all --no-print-directory
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -15,6 +15,9 @@ language: php
os: linux
dist: xenial

git:
depth: false

php:
- 7.2
- 7.3
Expand Down
32 changes: 17 additions & 15 deletions composer.json
@@ -1,14 +1,14 @@
{
"name" : "jbzoo/retry",
"type" : "library",
"description" : "Tiny PHP library providing retry functionality with multiple backoff strategies and jitter support",
"license" : "MIT",
"keywords" : [
"name" : "jbzoo/retry",
"type" : "library",
"description" : "Tiny PHP library providing retry functionality with multiple backoff strategies and jitter support",
"license" : "MIT",
"keywords" : [
"jbzoo", "jitter", "retry", "backoff", "middleware",
"back-off", "retry-after", "failure", "restart", "retryable"
],

"authors" : [
"authors" : [
{
"name" : "Joseph Szobody",
"email" : "joseph@stechstudio.com",
Expand All @@ -20,16 +20,20 @@
}
],

"require" : {
"require" : {
"php" : ">=7.2"
},

"require-dev" : {
"jbzoo/toolbox-dev" : "^2.10.0",
"require-dev" : {
"jbzoo/toolbox-dev" : "^2.11.0",
"jbzoo/jbdump" : ">=1.5.6"
},

"autoload" : {
"replace" : {
"stechstudio/backoff" : "*"
},

"autoload" : {
"psr-4" : {
"JBZoo\\Retry\\" : "src"
},
Expand All @@ -39,17 +43,15 @@
]
},

"autoload-dev" : {
"autoload-dev" : {
"classmap" : ["tests"]
},

"minimum-stability" : "dev",
"prefer-stable" : true,
"config" : {
"config" : {
"optimize-autoloader" : true
},

"extra" : {
"extra" : {
"branch-alias" : {
"dev-master" : "2.x-dev"
}
Expand Down
6 changes: 4 additions & 2 deletions src/Retry.php
Expand Up @@ -115,7 +115,7 @@ class Retry

/**
* This receive any exceptions we encounter.
* @var callable
* @var callable|null
*/
protected $errorHandler;

Expand Down Expand Up @@ -358,6 +358,7 @@ public function setErrorHandler(callable $callback): self
* Gets a default decider that simply check exceptions and maxattempts
* @return Closure
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @psalm-suppress MissingClosureParamType
*/
protected static function getDefaultDecider(): Closure
{
Expand Down Expand Up @@ -426,7 +427,8 @@ public function getWaitTime(int $attempt): int
*/
protected function cap(int $waitTime): int
{
return $this->getWaitCap() > 0 ? \min($this->getWaitCap(), $waitTime) : $waitTime;
$waitCap = (int)$this->getWaitCap();
return $waitCap > 0 ? \min($waitCap, $waitTime) : $waitTime;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/RetryTest.php
Expand Up @@ -192,8 +192,8 @@ public function testWaitLessOneSecond()

// We expect that this took just barely over the 100ms we asked for
isTrue(
$elapsedMS > 90 && $elapsedMS < 150,
"Expected elapsedMS between 90 & 150, got: {$elapsedMS}"
$elapsedMS > 90 && $elapsedMS < 175,
"Expected elapsedMS between 90 & 175, got: {$elapsedMS}"
);
}

Expand All @@ -211,8 +211,8 @@ public function testWaitMoreOneSecond()

// We expect that this took just barely over the 100ms we asked for
isTrue(
$elapsedMS > 1200 && $elapsedMS < 1300,
"Expected elapsedMS between 90 & 150, got: {$elapsedMS}"
$elapsedMS > 1200 && $elapsedMS < 1400,
"Expected elapsedMS between 1200 & 1400, got: {$elapsedMS}"
);
}

Expand Down

0 comments on commit 6ada566

Please sign in to comment.