Skip to content

Commit

Permalink
Fixed some integ tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremeamia committed Apr 23, 2015
1 parent faf763b commit ac71b1f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 50 deletions.
10 changes: 5 additions & 5 deletions src/AwsClient.php
Expand Up @@ -165,13 +165,13 @@ public function __call($name, array $args)
{
$params = isset($args[0]) ? $args[0] : [];

if (substr($name, -5) !== 'Async') {
return $this->execute($this->getCommand($name, $params));
if (substr($name, -5) === 'Async') {
return $this->executeAsync(
$this->getCommand(substr($name, 0, -5), $params)
);
}

return $this->executeAsync(
$this->getCommand(substr($name, 0, -5), $params)
);
return $this->execute($this->getCommand($name, $params));
}

public function getConfig($option = null)
Expand Down
19 changes: 10 additions & 9 deletions tests/Integ/ClientSmokeTest.php
Expand Up @@ -2,7 +2,8 @@
namespace Aws\Test\Integ;

use Aws\Exception\AwsException;
use GuzzleHttp\Event\BeforeEvent;
use Aws\Middleware;
use Psr\Http\Message\RequestInterface;

class ClientSmokeTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -20,12 +21,12 @@ public function testBasicOperationWorks($service, $class, $options,

// Setup event to get the request's host value.
$host = null;
$client->getHttpClient()->getEmitter()->on(
'before',
function (BeforeEvent $event) use (&$host) {
$host = $event->getRequest()->getHost();
$client->getHandlerList()->append(
'sign:integ',
Middleware::tap(function ($command, RequestInterface $request) use (&$host) {
$host = $request->getUri()->getHost();
}
);
));

// Execute the request and check if it behaved as intended.
try {
Expand Down Expand Up @@ -146,7 +147,7 @@ class (expected class name of instantiated client)
'Search',
['query' => 'foo'],
false,
'GuzzleHttp\Ring\Exception\ConnectException'
'GuzzleHttp\Exception\ConnectException'
],
[
'cloudtrail',
Expand Down Expand Up @@ -269,7 +270,7 @@ class (expected class name of instantiated client)
'ResourceNotFoundException'
],
[
'elb',
'elasticloadbalancing',
'Aws\\ElasticLoadBalancing\\ElasticLoadBalancingClient',
[],
'elasticloadbalancing.us-east-1.amazonaws.com',
Expand Down Expand Up @@ -389,7 +390,7 @@ class (expected class name of instantiated client)
'NoSuchBucket'
],
[
'sdb',
'simpledb',
'Aws\\SimpleDb\\SimpleDbClient',
[],
'sdb.amazonaws.com',
Expand Down
52 changes: 16 additions & 36 deletions tests/Integ/ConcurrencyTest.php
@@ -1,62 +1,42 @@
<?php
namespace Aws\Test\Integ;

use GuzzleHttp\Command\Event\ProcessEvent;
use Aws\CommandPool;
use GuzzleHttp\Promise;

class ConcurrencyTest extends \PHPUnit_Framework_TestCase
{
use IntegUtils;

public function testSendsRequestsConcurrently()
public function testSendsRequestsAsynchronously()
{
$s3 = $this->getSdk()->getS3();
/** @var \Aws\S3\S3Client $s3 */
$s3 = $this->getSdk()->createS3();

$commands = [
$s3->getCommand('ListBuckets'),
$s3->getCommand('ListBuckets'),
$s3->getCommand('ListBuckets')
];
$results = [];
$s3->executeAll($commands, [
'process' => function (ProcessEvent $e) use (&$results) {
$results[] = $e->getResult();
}
$promise = Promise\all([
$s3->listBucketsAsync(),
$s3->listBucketsAsync(),
$s3->listBucketsAsync()
]);
$results = $promise->wait();

$this->assertCount(3, $results);
$this->assertCount(1, array_unique(\JmesPath\search('[*].Owner.ID', $results)));
}

public function testSendsRequestsConcurrentlyWithPool()
{
$s3 = $this->getSdk()->getS3();
/** @var \Aws\S3\S3Client $s3 */
$s3 = $this->getSdk()->createS3();

$commands = [
$s3->getCommand('ListBuckets'),
$s3->getCommand('ListBuckets'),
$s3->getCommand('ListBuckets')
];
$results = CommandPool::batch($s3, $commands);

$resolved = false;
$processResults = $progress = [];
$pool = $s3->createPool($commands, [
'process' => function (ProcessEvent $e) use (&$processResults) {
$processResults[] = $e->getResult();
}
]);

$pool->then(
function ($result) use (&$resolved) {
$resolved = $result;
},
null,
function ($result) use (&$progress) {
$progress[] = $result;
}
);

$pool->wait();
$this->assertCount(3, $processResults);
$this->assertCount(3, $progress);
$this->assertSame(true, $resolved);
$this->assertCount(3, $results);
$this->assertCount(1, array_unique(\JmesPath\search('[*].Owner.ID', $results)));
}
}

0 comments on commit ac71b1f

Please sign in to comment.