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 8b673f5

Browse filesBrowse files
committed
[Mailer] Fix failover transport
1 parent 28e072a commit 8b673f5
Copy full SHA for 8b673f5

File tree

3 files changed

+13
-15
lines changed
Filter options

3 files changed

+13
-15
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Tests/Transport/FailoverTransportTest.php
-12Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Transport/FailoverTransport.php
+5Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Transport/RoundRobinTransport.php
+8-3Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.