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 d0e1de8

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

File tree

2 files changed

+37
-1
lines changed
Filter options

2 files changed

+37
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Middleware/TraceableMiddleware.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ public function __construct(StackInterface $stack, Stopwatch $stopwatch, string
7272
public function next(): MiddlewareInterface
7373
{
7474
if (null !== $this->currentEvent) {
75-
$this->stopwatch->stop($this->currentEvent);
75+
try {
76+
$this->stopwatch->stop($this->currentEvent);
77+
} catch (\LogicException $th) {
78+
// Maybe the stopwatch has been reset, noop
79+
}
7680
}
7781

7882
if ($this->stack === $nextMiddleware = $this->stack->next()) {

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Middleware/TraceableMiddlewareTest.php
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 $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.