Skip to content

[HttpClient] Move Http clients data collecting at a late level #48898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public function registerClient(string $name, TraceableHttpClient $client)
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
}

public function lateCollect()
{
$this->reset();

Expand All @@ -50,12 +54,7 @@ public function collect(Request $request, Response $response, \Throwable $except

$this->data['request_count'] += \count($traces);
$this->data['error_count'] += $errorCount;
}
}

public function lateCollect()
{
foreach ($this->clients as $client) {
$client->reset();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use Symfony\Component\HttpClient\DataCollector\HttpClientDataCollector;
use Symfony\Component\HttpClient\NativeHttpClient;
use Symfony\Component\HttpClient\TraceableHttpClient;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\HttpClient\Test\TestHttpServer;

class HttpClientDataCollectorTest extends TestCase
Expand Down Expand Up @@ -50,7 +48,7 @@ public function testItCollectsRequestCount()
$sut->registerClient('http_client2', $httpClient2);
$sut->registerClient('http_client3', $httpClient3);
$this->assertEquals(0, $sut->getRequestCount());
$sut->collect(new Request(), new Response());
$sut->lateCollect();
$this->assertEquals(3, $sut->getRequestCount());
}

Expand Down Expand Up @@ -79,7 +77,7 @@ public function testItCollectsErrorCount()
$sut->registerClient('http_client2', $httpClient2);
$sut->registerClient('http_client3', $httpClient3);
$this->assertEquals(0, $sut->getErrorCount());
$sut->collect(new Request(), new Response());
$sut->lateCollect();
$this->assertEquals(1, $sut->getErrorCount());
}

Expand Down Expand Up @@ -108,7 +106,7 @@ public function testItCollectsErrorCountByClient()
$sut->registerClient('http_client2', $httpClient2);
$sut->registerClient('http_client3', $httpClient3);
$this->assertEquals([], $sut->getClients());
$sut->collect(new Request(), new Response());
$sut->lateCollect();
$collectedData = $sut->getClients();
$this->assertEquals(0, $collectedData['http_client1']['error_count']);
$this->assertEquals(1, $collectedData['http_client2']['error_count']);
Expand Down Expand Up @@ -140,7 +138,7 @@ public function testItCollectsTracesByClient()
$sut->registerClient('http_client2', $httpClient2);
$sut->registerClient('http_client3', $httpClient3);
$this->assertEquals([], $sut->getClients());
$sut->collect(new Request(), new Response());
$sut->lateCollect();
$collectedData = $sut->getClients();
$this->assertCount(2, $collectedData['http_client1']['traces']);
$this->assertCount(1, $collectedData['http_client2']['traces']);
Expand All @@ -157,7 +155,7 @@ public function testItIsEmptyAfterReset()
]);
$sut = new HttpClientDataCollector();
$sut->registerClient('http_client1', $httpClient1);
$sut->collect(new Request(), new Response());
$sut->lateCollect();
$collectedData = $sut->getClients();
$this->assertCount(1, $collectedData['http_client1']['traces']);
$sut->reset();
Expand Down