Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix failing tests
Browse files Browse the repository at this point in the history
bshaffer committed Sep 27, 2024
1 parent 7b6d80c commit 557e69c
Showing 2 changed files with 28 additions and 34 deletions.
48 changes: 19 additions & 29 deletions Redis/tests/System/V1/CloudRedisClientTest.php
Original file line number Diff line number Diff line change
@@ -18,7 +18,10 @@
namespace Google\Cloud\Redis\Tests\System\V1;

use Google\Auth\CredentialsLoader;
use Google\Cloud\Redis\V1\CloudRedisClient;
use Google\Cloud\Redis\V1\Client\CloudRedisClient;
use Google\Cloud\Redis\V1\CreateInstanceRequest;
use Google\Cloud\Redis\V1\DeleteInstanceRequest;
use Google\Cloud\Redis\V1\ListInstancesRequest;
use Google\Cloud\Redis\V1\Instance;
use Google\Cloud\Redis\V1\Instance\Tier;
use Google\Cloud\Redis\V1\OperationMetadata;
@@ -31,28 +34,11 @@
*/
class CloudRedisClientTest extends TestCase
{
protected static $grpcClient;
protected static $projectId;
private static $hasSetUp = false;
protected $grpcClient;
protected $projectId;

public function clientProvider()
public function setUp(): void
{
self::setUpTestFixtures();

return [
[self::$grpcClient]
];
}

/**
* @beforeClass
*/
public static function setUpTestFixtures(): void
{
if (self::$hasSetUp) {
return;
}

$keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH');
$keyFileData = json_decode(file_get_contents($keyFilePath), true);

@@ -62,13 +48,13 @@ public static function setUpTestFixtures(): void
]);

self::$projectId = $keyFileData['project_id'];

self::$hasSetUp = true;
}

private function deleteInstance(CloudRedisClient $client, $instanceToDelete)
{
$operationResponse = $client->deleteInstance($instanceToDelete);
$operationResponse = $client->deleteInstance(
DeleteInstanceRequest::build($instanceToDelete)
);
while (!$operationResponse->isDone()) {
// get the $any object to ensure this does not fail
$any = $operationResponse->getMetadata();
@@ -96,7 +82,9 @@ private function createRedisInstance(CloudRedisClient $client, $parent, $instanc
$instance = new Instance();
$instance->setTier($tier);
$instance->setMemorySizeGb($memorySizeGb);
$operationResponse = $client->createInstance($parent, $instanceId, $instance);
$operationResponse = $client->createInstance(
CreateInstanceRequest::build($parent, $instanceId, $instance)
);

while (!$operationResponse->isDone()) {
// get the $any object to ensure this does not fail
@@ -115,14 +103,16 @@ private function createRedisInstance(CloudRedisClient $client, $parent, $instanc
/**
* @dataProvider clientProvider
*/
public function testCreateListDeleteOperations(CloudRedisClient $client)
public function testCreateListDeleteOperations()
{
$client = self::$grpcClient;
$locationId = 'us-central1';
$instanceId = 'my-redis-test-instance';
$parent = $client::locationName(self::$projectId, $locationId);
$instanceName = $client::instanceName(self::$projectId, $locationId, $instanceId);
$request = ListInstancesRequest::build($parent);

$instances = $client->listInstances($parent);
$instances = $client->listInstances($request);
foreach ($instances->iterateAllElements() as $instance) {
if ($instance->getName() === $instanceName) {
// Instance exists - lets delete it
@@ -133,12 +123,12 @@ public function testCreateListDeleteOperations(CloudRedisClient $client)
$createdInstanceName = $this->createRedisInstance($client, $parent, $instanceId);
$this->assertSame($instanceName, $createdInstanceName);

$instances = iterator_to_array($client->listInstances($parent)->iterateAllElements());
$instances = iterator_to_array($client->listInstances($request)->iterateAllElements());
$this->assertSame(1, count($instances));

$this->deleteInstance($client, $createdInstanceName);

$instances = iterator_to_array($client->listInstances($parent)->iterateAllElements());
$instances = iterator_to_array($client->listInstances($request)->iterateAllElements());
$this->assertSame(0, count($instances));
}
}
14 changes: 9 additions & 5 deletions Storage/tests/System/SignedUrlTest.php
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
namespace Google\Cloud\Storage\Tests\System;

use Google\Cloud\Core\Exception\NotFoundException;
use Google\Cloud\Core\ExponentialBackoff;
use Google\Cloud\Core\Timestamp;
use GuzzleHttp\Client;

@@ -269,11 +270,14 @@ private function createFile($name)

private function getFile($url, array $options = [])
{
$res = $this->guzzle->request('GET', $url, $options + [
'http_errors' => false,
]);

return (string) $res->getBody();
$exponentialBackoff = new ExponentialBackoff();
return $exponentialBackoff->execute(function () use ($url, $options) {
$res = $this->guzzle->request('GET', $url, $options + [
'http_errors' => false,
]);

return (string) $res->getBody();
});
}

private function deleteFile($url, array $headers = [])

0 comments on commit 557e69c

Please sign in to comment.