Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bf4b0cc

Browse filesBrowse files
committed
[Messenger] Fix stopwach usage if it has been reset
1 parent fc794e5 commit bf4b0cc
Copy full SHA for bf4b0cc

File tree

2 files changed

+34
-2
lines changed
Filter options

2 files changed

+34
-2
lines changed

‎src/Symfony/Component/Messenger/Middleware/TraceableMiddleware.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Middleware/TraceableMiddleware.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __construct(StackInterface $stack, Stopwatch $stopwatch, string
7171
*/
7272
public function next(): MiddlewareInterface
7373
{
74-
if (null !== $this->currentEvent) {
74+
if (null !== $this->currentEvent && $this->stopwatch->isStarted($this->currentEvent)) {
7575
$this->stopwatch->stop($this->currentEvent);
7676
}
7777

‎src/Symfony/Component/Messenger/Tests/Middleware/TraceableMiddlewareTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Middleware/TraceableMiddlewareTest.php
+33-1Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function handle(Envelope $envelope, StackInterface $stack): Envelope
4242
};
4343

4444
$stopwatch = $this->createMock(Stopwatch::class);
45-
$stopwatch->expects($this->once())->method('isStarted')->willReturn(true);
45+
$stopwatch->expects($this->exactly(2))->method('isStarted')->willReturn(true);
4646
$stopwatch->expects($this->exactly(2))
4747
->method('start')
4848
->withConsecutive(
@@ -91,4 +91,36 @@ public function testHandleWithException()
9191
$traced = new TraceableMiddleware($stopwatch, $busId);
9292
$traced->handle(new Envelope(new DummyMessage('Hello')), new StackMiddleware(new \ArrayIterator([null, $middleware])));
9393
}
94+
95+
public function testHandleWhenStopwatchHasBeenReset()
96+
{
97+
$busId = 'command_bus';
98+
$envelope = new Envelope(new DummyMessage('Hello'));
99+
100+
$stopwatch = new Stopwatch();
101+
102+
$middleware = new class($stopwatch) implements MiddlewareInterface {
103+
public $calls = 0;
104+
private $stopwatch;
105+
106+
public function __construct(Stopwatch $stopwatch)
107+
{
108+
$this->stopwatch = $stopwatch;
109+
}
110+
111+
public function handle(Envelope $envelope, StackInterface $stack): Envelope
112+
{
113+
$this->stopwatch->reset();
114+
115+
++$this->calls;
116+
117+
return $stack->next()->handle($envelope, $stack);
118+
}
119+
};
120+
121+
$traced = new TraceableMiddleware($stopwatch, $busId);
122+
123+
$traced->handle($envelope, new StackMiddleware(new \ArrayIterator([null, $middleware])));
124+
$this->assertSame(1, $middleware->calls);
125+
}
94126
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.