[Messenger][Profiler] Collect the stamps at the end of dispatch

This commit is contained in:
Maxime Steinhausser 2019-07-23 15:40:37 +02:00 committed by Maxime Steinhausser
parent 9282f4fd93
commit ee68b1dfa7
7 changed files with 58 additions and 12 deletions

View File

@ -4,11 +4,12 @@ CHANGELOG
4.4.0
-----
* Added button to clear the ajax request tab
* Deprecated the `ExceptionController::templateExists()` method
* Deprecated the `TemplateManager::templateExists()` method
* Deprecated the `ExceptionController` in favor of `ExceptionPanelController`
* Marked all classes of the WebProfilerBundle as internal
* added button to clear the ajax request tab
* deprecated the `ExceptionController::templateExists()` method
* deprecated the `TemplateManager::templateExists()` method
* deprecated the `ExceptionController` in favor of `ExceptionPanelController`
* marked all classes of the WebProfilerBundle as internal
* added a section with the stamps of a message after it is dispatched in the Messenger panel
4.3.0
-----

View File

@ -45,7 +45,7 @@
{{ parent() }}
<style>
.message-item thead th { position: relative; cursor: pointer; user-select: none; padding-right: 35px; }
.message-item tbody tr td:first-child { width: 115px; }
.message-item tbody tr td:first-child { width: 170px; }
.message-item .label { float: right; padding: 1px 5px; opacity: .75; margin-left: 5px; }
.message-item .toggle-button { position: absolute; right: 6px; top: 6px; opacity: .5; pointer-events: none }
@ -166,7 +166,7 @@
<td>{{ profiler_dump(dispatchCall.message.value, maxDepth=2) }}</td>
</tr>
<tr>
<td class="text-bold">Envelope stamps</td>
<td class="text-bold">Envelope stamps <span class="text-muted">when dispatching</span></td>
<td>
{% for item in dispatchCall.stamps %}
{{ profiler_dump(item) }}
@ -175,6 +175,18 @@
{% endfor %}
</td>
</tr>
{% if dispatchCall.stamps_after_dispatch is defined %}
<tr>
<td class="text-bold">Envelope stamps <span class="text-muted">after dispatch</span></td>
<td>
{% for item in dispatchCall.stamps_after_dispatch %}
{{ profiler_dump(item) }}
{% else %}
<span class="text-muted">No items</span>
{% endfor %}
</td>
</tr>
{% endif %}
{% if dispatchCall.exception is defined %}
<tr>
<td class="text-bold">Exception</td>

View File

@ -99,6 +99,7 @@ class MessengerDataCollector extends DataCollector implements LateDataCollectorI
$debugRepresentation = [
'bus' => $busName,
'stamps' => $tracedMessage['stamps'] ?? null,
'stamps_after_dispatch' => $tracedMessage['stamps_after_dispatch'] ?? null,
'message' => [
'type' => new ClassStub(\get_class($message)),
'value' => $message,

View File

@ -55,9 +55,10 @@ class MessengerDataCollectorTest extends TestCase
$file = __FILE__;
$expected = <<<DUMP
array:4 [
array:5 [
"bus" => "default"
"stamps" => []
"stamps_after_dispatch" => []
"message" => array:2 [
"type" => "Symfony\Component\Messenger\Tests\Fixtures\DummyMessage"
"value" => Symfony\Component\Messenger\Tests\Fixtures\DummyMessage %A
@ -100,9 +101,10 @@ DUMP;
$file = __FILE__;
$this->assertStringMatchesFormat(<<<DUMP
array:5 [
array:6 [
"bus" => "default"
"stamps" => []
"stamps_after_dispatch" => []
"message" => array:2 [
"type" => "Symfony\Component\Messenger\Tests\Fixtures\DummyMessage"
"value" => Symfony\Component\Messenger\Tests\Fixtures\DummyMessage %A

View File

@ -27,7 +27,7 @@ class TraceableMessageBusTest extends TestCase
$stamp = new DelayStamp(5);
$bus = $this->getMockBuilder(MessageBusInterface::class)->getMock();
$bus->expects($this->once())->method('dispatch')->with($message, [$stamp])->willReturn(new Envelope($message));
$bus->expects($this->once())->method('dispatch')->with($message, [$stamp])->willReturn(new Envelope($message, [$stamp]));
$traceableBus = new TraceableMessageBus($bus);
$line = __LINE__ + 1;
@ -38,6 +38,7 @@ class TraceableMessageBusTest extends TestCase
$this->assertEquals([
'message' => $message,
'stamps' => [$stamp],
'stamps_after_dispatch' => [$stamp],
'caller' => [
'name' => 'TraceableMessageBusTest.php',
'file' => __FILE__,
@ -63,6 +64,33 @@ class TraceableMessageBusTest extends TestCase
$this->assertEquals([
'message' => $message,
'stamps' => [$stamp],
'stamps_after_dispatch' => [$stamp],
'caller' => [
'name' => 'TraceableMessageBusTest.php',
'file' => __FILE__,
'line' => $line,
],
], $actualTracedMessage);
}
public function testItCollectsStampsAddedDuringDispatch()
{
$message = new DummyMessage('Hello');
$envelope = (new Envelope($message))->with($stamp = new AnEnvelopeStamp());
$bus = $this->getMockBuilder(MessageBusInterface::class)->getMock();
$bus->expects($this->once())->method('dispatch')->with($envelope)->willReturn($envelope->with($anotherStamp = new AnEnvelopeStamp()));
$traceableBus = new TraceableMessageBus($bus);
$line = __LINE__ + 1;
$traceableBus->dispatch($envelope);
$this->assertCount(1, $tracedMessages = $traceableBus->getDispatchedMessages());
$actualTracedMessage = $tracedMessages[0];
unset($actualTracedMessage['callTime']); // don't check, too variable
$this->assertEquals([
'message' => $message,
'stamps' => [$stamp],
'stamps_after_dispatch' => [$stamp, $anotherStamp],
'caller' => [
'name' => 'TraceableMessageBusTest.php',
'file' => __FILE__,
@ -94,6 +122,7 @@ class TraceableMessageBusTest extends TestCase
'message' => $message,
'exception' => $exception,
'stamps' => [],
'stamps_after_dispatch' => [],
'caller' => [
'name' => 'TraceableMessageBusTest.php',
'file' => __FILE__,

View File

@ -38,13 +38,13 @@ class TraceableMessageBus implements MessageBusInterface
];
try {
return $this->decoratedBus->dispatch($message, $stamps);
return $envelope = $this->decoratedBus->dispatch($message, $stamps);
} catch (\Throwable $e) {
$context['exception'] = $e;
throw $e;
} finally {
$this->dispatchedMessages[] = $context;
$this->dispatchedMessages[] = $context + ['stamps_after_dispatch' => array_merge([], ...array_values($envelope->all()))];
}
}

View File

@ -6,6 +6,7 @@ CHANGELOG
* added `VarDumperTestTrait::setUpVarDumper()` and `VarDumperTestTrait::tearDownVarDumper()`
to configure casters & flags to use in tests
* added the stamps of a message after it is dispatched in `TraceableMessageBus` and `MessengerDataCollector` collected data
4.3.0
-----