Skip to content

Commit

Permalink
Setting timeout config to Pusher instance (#382)
Browse files Browse the repository at this point in the history
* Move #381 to a new PR

* Bump to version 7.2.4

---------

Co-authored-by: Pusher CI <pusher-ci@pusher.com>
  • Loading branch information
fbenevides and pusher-ci committed Dec 15, 2023
1 parent 416e68d commit de2f722
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Tests
on:
pull_request:
push:
branches: [master, main]

branches: [ master, main ]
jobs:
test:
runs-on: ubuntu-20.04
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 7.2.4

* [Fixed] Timeout option is propagated to guzzle client

## 7.2.3

* [Fixed] Include socket_id in batch trigger if included.
Expand Down
24 changes: 14 additions & 10 deletions src/Pusher.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Pusher implements LoggerAwareInterface, PusherInterface
/**
* @var string Version
*/
public static $VERSION = '7.2.3';
public static $VERSION = '7.2.4';

/**
* @var null|PusherCrypto
Expand Down Expand Up @@ -64,12 +64,6 @@ public function __construct(string $auth_key, string $secret, string $app_id, ar
{
$this->check_compatibility();

if (!is_null($client)) {
$this->client = $client;
} else {
$this->client = new \GuzzleHttp\Client();
}

$useTLS = true;
if (isset($options['useTLS'])) {
$useTLS = $options['useTLS'] === true;
Expand Down Expand Up @@ -119,6 +113,13 @@ public function __construct(string $auth_key, string $secret, string $app_id, ar
);
$this->crypto = new PusherCrypto($parsedKey);
}


if (!is_null($client)) {
$this->client = $client;
} else {
$this->client = new \GuzzleHttp\Client(['timeout' => $this->settings['timeout'],]);
}
}

/**
Expand Down Expand Up @@ -724,7 +725,8 @@ public function get(string $path, array $params = [], $associative = false)
'query' => $signature,
'http_errors' => false,
'headers' => $headers,
'base_uri' => $this->channels_url_prefix()
'base_uri' => $this->channels_url_prefix(),
'timeout' => $this->settings['timeout']
]);

$status = $response->getStatusCode();
Expand Down Expand Up @@ -776,7 +778,8 @@ public function post(string $path, $body, array $params = [])
'body' => $body,
'http_errors' => false,
'headers' => $headers,
'base_uri' => $this->channels_url_prefix()
'base_uri' => $this->channels_url_prefix(),
'timeout' => $this->settings['timeout']
]);
} catch (ConnectException $e) {
throw new ApiErrorException($e->getMessage());
Expand Down Expand Up @@ -826,7 +829,8 @@ public function postAsync(string $path, $body, array $params = []): PromiseInter
'body' => $body,
'http_errors' => false,
'headers' => $headers,
'base_uri' => $this->channels_url_prefix()
'base_uri' => $this->channels_url_prefix(),
'timeout' => $this->settings['timeout'],
])->then(function ($response) {
$status = $response->getStatusCode();

Expand Down
17 changes: 14 additions & 3 deletions tests/unit/PusherConstructorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function testUseTLSOptionWillBeOverwrittenByHostAndPortOptionsSetHostAndP
{
$options = [
'useTLS' => true,
'host' => 'test.com',
'port' => '3000',
'host' => 'test.com',
'port' => '3000',
];
$pusher = new Pusher('app_key', 'app_secret', 'app_id', $options);

Expand Down Expand Up @@ -60,11 +60,22 @@ public function testClusterOptionIsOverriddenByHostIfItExists(): void
{
$options = [
'cluster' => 'eu',
'host' => 'api.staging.pusher.com',
'host' => 'api.staging.pusher.com',
];
$pusher = new Pusher('app_key', 'app_secret', 'app_id', $options);

$settings = $pusher->getSettings();
self::assertEquals('api.staging.pusher.com', $settings['host']);
}

public function testSetTimeoutOption(): void
{
$options = [
'timeout' => 10,
];
$pusher = new Pusher('app_key', 'app_secret', 'app_id', $options);

$settings = $pusher->getSettings();
self::assertEquals(10, $settings['timeout']);
}
}

0 comments on commit de2f722

Please sign in to comment.