Skip to content

Commit

Permalink
Added mutation testing and readme badge.
Browse files Browse the repository at this point in the history
Added public constants for constructor default thresholds.
  • Loading branch information
Bilge committed Oct 17, 2019
1 parent a5c8d7d commit c4201f3
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 8 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor/
/.*/
/composer.lock
/vendor/
/.*/
/composer.lock
/*.log
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ install:
- composer update --no-progress --no-suggest $DEPENDENCIES

script:
- composer test -- --coverage-clover=build/logs/clover.xml
- composer test -- --coverage-clover=build/logs/clover.xml --coverage-xml=build/coverage/coverage-xml
--log-junit=build/coverage/phpunit.junit.xml
- vendor/bin/infection --min-msi=95 --threads="$(($(nproc) * 2))" --coverage=build/coverage

after_success:
- composer require php-coveralls/php-coveralls:^2
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Async Throttle
[![Latest version][Version image]][Releases]
[![Total downloads][Downloads image]][Downloads]
[![Build status][Build image]][Build]
[![Mutation score][MSI image]][Build]
[![Test coverage][Coverage image]][Coverage]
[![Code style][Style image]][Style]

Expand All @@ -16,6 +17,7 @@ Throttles async object throughput.
[Downloads image]: https://poser.pugx.org/async/throttle/downloads "Total downloads"
[Build]: https://travis-ci.org/ScriptFUSION/Async-Throttle
[Build image]: https://travis-ci.org/ScriptFUSION/Async-Throttle.svg?branch=master "Build status"
[MSI image]: https://badge.stryker-mutator.io/github.com/ScriptFUSION/Async-Throttle/master
[Coverage]: https://coveralls.io/github/ScriptFUSION/Async-Throttle
[Coverage image]: https://coveralls.io/repos/ScriptFUSION/Async-Throttle/badge.svg "Test coverage"
[Style]: https://styleci.io/repos/131506544
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"require-dev": {
"amphp/phpunit-util": "^1.1",
"infection/infection": "*",
"infection/infection": "^0.14",
"phpunit/phpunit": "^7.5"
},
"autoload": {
Expand Down
5 changes: 4 additions & 1 deletion infection.json.dist → infection.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"configDir": "test"
},
"logs": {
"text": "infection.log"
"text": "infection.log",
"badge": {
"branch": "master"
}
},
"mutators": {
"@default": true
Expand Down
16 changes: 14 additions & 2 deletions src/Throttle.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
*/
class Throttle
{
/**
* Maximum number of promises per second.
*/
public const DEFAULT_PER_SECOND = 75;

/**
* Maximum number of concurrent promises.
*/
public const DEFAULT_CONCURRENCY = 30;

/**
* Milliseconds to wait before reevaluating thresholds when above chrono threshold.
*/
Expand Down Expand Up @@ -51,8 +61,10 @@ class Throttle
* @param int $maxPerSecond Optional. Maximum number of promises per second.
* @param int $maxConcurrency Optional. Maximum number of concurrent promises.
*/
public function __construct(int $maxPerSecond = 75, int $maxConcurrency = 30)
{
public function __construct(
int $maxPerSecond = self::DEFAULT_PER_SECOND,
int $maxConcurrency = self::DEFAULT_CONCURRENCY
) {
$this->maxPerSecond = $maxPerSecond;
$this->maxConcurrency = $maxConcurrency;
}
Expand Down
3 changes: 3 additions & 0 deletions test/ThrottleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public function testThroughput(): \Generator
self::assertLessThanOrEqual(.1, microtime(true) - $start);
}

/**
* Tests that 100 promises that resolve immediately are throttled only once the chrono threshold is hit.
*/
public function testThroughput2(): \Generator
{
$this->throttle->setMaxConcurrency(1);
Expand Down

0 comments on commit c4201f3

Please sign in to comment.