Skip to content

Commit

Permalink
Merge pull request #30 from acelaya-forks/feature/geolite-timeout
Browse files Browse the repository at this point in the history
Feature/geolite timeout
  • Loading branch information
acelaya authored May 20, 2020
2 parents b313223 + d184483 commit 51213c4
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]
## 1.4.1 - 2020-05-20

#### Added

Expand All @@ -24,7 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this

#### Fixed

* *Nothing*
* [#29](https://github.com/shlinkio/shlink-ip-geolocation/issues/29) Fixed timeout connections when downloading GeoLite databases leaving connection stuck forever.


## 1.4.0 - 2020-03-13
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"require-dev": {
"infection/infection": "^0.16.1",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan": "^0.12.3",
"phpunit/phpunit": "^9.0.2",
"roave/security-advisories": "dev-master",
Expand Down
1 change: 1 addition & 0 deletions src/GeoLite2/DbUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private function downloadDbFile(string $dest, ?callable $handleProgress = null):
$this->httpClient->request(RequestMethod::METHOD_GET, $this->options->getDownloadFrom(), [
RequestOptions::SINK => $dest,
RequestOptions::PROGRESS => $handleProgress,
RequestOptions::CONNECT_TIMEOUT => $this->options->getConnectionTimeout(),
]);
} catch (Throwable | GuzzleException $e) {
throw DbUpdateException::forFailedDownload($e);
Expand Down
12 changes: 12 additions & 0 deletions src/GeoLite2/GeoLite2Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class GeoLite2Options extends AbstractOptions
private string $licenseKey = 'G4Lm0C60yJsnkdPi';
private string $downloadFrom = 'https://download.maxmind.com/app/geoip_download'
. '?edition_id=GeoLite2-City&license_key={license_key}&suffix=tar.gz';
private float $connectionTimeout = 15.0;

public function getDbLocation(): string
{
Expand Down Expand Up @@ -54,4 +55,15 @@ protected function setLicenseKey(string $licenseKey): self
$this->licenseKey = $licenseKey;
return $this;
}

protected function setConnectionTimeout(float $connectionTimeout): self
{
$this->connectionTimeout = $connectionTimeout;
return $this;
}

public function getConnectionTimeout(): float
{
return $this->connectionTimeout;
}
}
3 changes: 3 additions & 0 deletions test/GeoLite2/DbUpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use GuzzleHttp\Exception\ClientException;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\ResponseInterface;
use Shlinkio\Shlink\IpGeolocation\Exception\RuntimeException;
Expand All @@ -18,6 +19,8 @@

class DbUpdaterTest extends TestCase
{
use ProphecyTrait;

private DbUpdater $dbUpdater;
private ObjectProphecy $httpClient;
private ObjectProphecy $filesystem;
Expand Down
3 changes: 3 additions & 0 deletions test/Resolver/ChainIpLocationResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace ShlinkioTest\Shlink\IpGeolocation\Resolver;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
use Shlinkio\Shlink\IpGeolocation\Model\Location;
Expand All @@ -13,6 +14,8 @@

class ChainIpLocationResolverTest extends TestCase
{
use ProphecyTrait;

private ChainIpLocationResolver $resolver;
private ObjectProphecy $firstInnerResolver;
private ObjectProphecy $secondInnerResolver;
Expand Down
3 changes: 3 additions & 0 deletions test/Resolver/GeoLite2LocationResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
use GeoIp2\Model\City;
use MaxMind\Db\Reader\InvalidDatabaseException;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
use Shlinkio\Shlink\IpGeolocation\Model\Location;
use Shlinkio\Shlink\IpGeolocation\Resolver\GeoLite2LocationResolver;

class GeoLite2LocationResolverTest extends TestCase
{
use ProphecyTrait;

private GeoLite2LocationResolver $resolver;
private ObjectProphecy $reader;

Expand Down

0 comments on commit 51213c4

Please sign in to comment.