8000 [HttpClient] Move Http clients data collecting at a late level · symfony/symfony@ac4585e · GitHub
[go: up one dir, main page]

Skip to content

Commit ac4585e

Browse files
committed
[HttpClient] Move Http clients data collecting at a late level
This allows to collect http clients data when sending them in a StreamedResponse callback method
1 parent 2f62c4a commit ac4585e

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public function registerClient(string $name, TraceableHttpClient $client)
3737
* {@inheritdoc}
3838
*/
3939
public function collect(Request $request, Response $response, \Throwable $exception = null)
40+
{
41+
}
42+
43+
public function lateCollect()
4044
{
4145
$this->reset();
4246

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

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

56-
public function lateCollect()
57-
{
58-
foreach ($this->clients as $client) {
5958
$client->reset();
6059
}
6160
}

src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testItCollectsRequestCount()
5050
$sut->registerClient('http_client2', $httpClient2);
5151
$sut->registerClient('http_client3', $httpClient3);
5252
$this->assertEquals(0, $sut->getRequestCount());
53-
$sut->collect(new Request(), new Response());
53+
$sut->lateCollect();
5454
$this->assertEquals(3, $sut->getRequestCount());
5555
}
5656

@@ -79,7 +79,7 @@ public function testItCollectsErrorCount()
7979
$sut->registerClient('http_client2', $httpClient2);
8080
$sut->registerClient('http_client3', $httpClient3);
8181
$this->assertEquals(0, $sut->getErrorCount());
82-
$sut->collect(new Request(), new Response());
82+
$sut->lateCollect();
8383
$this->assertEquals(1, $sut->getErrorCount());
8484
}
8585

@@ -108,7 +108,7 @@ public function testItCollectsErrorCountByClient()
108108
$sut->registerClient('http_client2', $httpClient2);
109109
$sut->registerClient('http_client3', $httpClient3);
110110
$this->assertEquals([], $sut->getClients());
111-
$sut->collect(new Request(), new Response());
111+
$sut->lateCollect();
112112
$collectedData = $sut->getClients();
113113
$this->assertEquals(0, $collectedData['http_client1']['error_count']);
114114
$this->assertEquals(1, $collectedData['http_client2']['error_count']);
@@ -140,7 +140,7 @@ public function testItCollectsTracesByClient()
140140
$sut->registerClient('http_client2', $httpClient2);
141141
$sut->registerClient('http_client3', $httpClient3);
142142
$this->assertEquals([], $sut->getClients());
143-
$sut->collect(new Request(), new Response());
143+
$sut->lateCollect();
144144
$collectedData = $sut->getClients();
145145
$this->assertCount(2, $collectedData['http_client1']['traces']);
146146
$this->assertCount(1, $collectedData['http_client2']['traces']);
@@ -157,7 +157,7 @@ public function testItIsEmptyAfterReset()
157157
]);
158158
$sut = new HttpClientDataCollector();
159159
$sut->registerClient('http_client1', $httpClient1);
160-
$sut->collect(new Request(), new Response());
160+
$sut->lateCollect();
161161
$collectedData = $sut->getClients();
162162
$this->assertCount(1, $collectedData['http_client1']['traces']);
163163
$sut->reset();

0 commit comments

Comments
 (0)
0