Skip to content

Commit 08ff65f

Browse files
committed
bug #37611 [Mailer] Fix failover transport (fabpot)
This PR was merged into the 5.1 branch. Discussion ---------- [Mailer] Fix failover transport | Q | A | ------------- | --- | Branch? | 5.1 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #37593 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | n/a This fixes a regression in 5.1. Commits ------- 8b673f5 [Mailer] Fix failover transport
2 parents 28e072a + 8b673f5 commit 08ff65f

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

src/Symfony/Component/Mailer/Tests/Transport/FailoverTransportTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ public function testSendFirstWork()
4646
$t2 = $this->createMock(TransportInterface::class);
4747
$t2->expects($this->never())->method('send');
4848
$t = new FailoverTransport([$t1, $t2]);
49-
$p = new \ReflectionProperty(RoundRobinTransport::class, 'cursor');
50-
$p->setAccessible(true);
51-
$p->setValue($t, 0);
5249
$t->send(new RawMessage(''));
5350
$this->assertTransports($t, 1, []);
5451
$t->send(new RawMessage(''));
@@ -77,9 +74,6 @@ public function testSendOneDead()
7774
$t2 = $this->createMock(TransportInterface::class);
7875
$t2->expects($this->exactly(3))->method('send');
7976
$t = new FailoverTransport([$t1, $t2]);
80-
$p = new \ReflectionProperty(RoundRobinTransport::class, 'cursor');
81-
$p->setAccessible(true);
82-
$p->setValue($t, 0);
8377
$t->send(new RawMessage(''));
8478
$this->assertTransports($t, 0, [$t1]);
8579
$t->send(new RawMessage(''));
@@ -99,9 +93,6 @@ public function testSendOneDeadAndRecoveryWithinRetryPeriod()
9993
$t2->expects($this->at(2))->method('send');
10094
$t2->expects($this->at(3))->method('send')->will($this->throwException(new TransportException()));
10195
$t = new FailoverTransport([$t1, $t2], 6);
102-
$p = new \ReflectionProperty(RoundRobinTransport::class, 'cursor');
103-
$p->setAccessible(true);
104-
$p->setValue($t, 0);
10596
$t->send(new RawMessage('')); // t1>fail - t2>sent
10697
$this->assertTransports($t, 0, [$t1]);
10798
sleep(4);
@@ -148,9 +139,6 @@ public function testSendOneDeadButRecover()
148139
$t2->expects($this->at(1))->method('send');
149140
$t2->expects($this->at(2))->method('send')->will($this->throwException(new TransportException()));
150141
$t = new FailoverTransport([$t1, $t2], 1);
151-
$p = new \ReflectionProperty(RoundRobinTransport::class, 'cursor');
152-
$p->setAccessible(true);
153-
$p->setValue($t, 0);
154142
$t->send(new RawMessage(''));
155143
sleep(1);
156144
$t->send(new RawMessage(''));

src/Symfony/Component/Mailer/Transport/FailoverTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ protected function getNextTransport(): ?TransportInterface
2929
return $this->currentTransport;
3030
}
3131

32+
protected function getInitialCursor(): int
33+
{
34+
return 0;
35+
}
36+
3237
protected function getNameSymbol(): string
3338
{
3439
return 'failover';

src/Symfony/Component/Mailer/Transport/RoundRobinTransport.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ public function __toString(): string
6767
protected function getNextTransport(): ?TransportInterface
6868
{
6969
if (-1 === $this->cursor) {
70-
// the cursor initial value is randomized so that
71-
// when are not in a daemon, we are still rotating the transports
72-
$this->cursor = mt_rand(0, \count($this->transports) - 1);
70+
$this->cursor = $this->getInitialCursor();
7371
}
7472

7573
$cursor = $this->cursor;
@@ -101,6 +99,13 @@ protected function isTransportDead(TransportInterface $transport): bool
10199
return $this->deadTransports->contains($transport);
102100
}
103101

102+
protected function getInitialCursor(): int
103+
{
104+
// the cursor initial value is randomized so that
105+
// when are not in a daemon, we are still rotating the transports
106+
return mt_rand(0, \count($this->transports) - 1);
107+
}
108+
104109
protected function getNameSymbol(): string
105110
{
106111
return 'roundrobin';

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy