[Mailer] Fix failover transport
This commit is contained in:
parent
28e072a8ec
commit
8b673f5a81
@ -46,9 +46,6 @@ class FailoverTransportTest extends TestCase
|
||||
$t2 = $this->createMock(TransportInterface::class);
|
||||
$t2->expects($this->never())->method('send');
|
||||
$t = new FailoverTransport([$t1, $t2]);
|
||||
$p = new \ReflectionProperty(RoundRobinTransport::class, 'cursor');
|
||||
$p->setAccessible(true);
|
||||
$p->setValue($t, 0);
|
||||
$t->send(new RawMessage(''));
|
||||
$this->assertTransports($t, 1, []);
|
||||
$t->send(new RawMessage(''));
|
||||
@ -77,9 +74,6 @@ class FailoverTransportTest extends TestCase
|
||||
$t2 = $this->createMock(TransportInterface::class);
|
||||
$t2->expects($this->exactly(3))->method('send');
|
||||
$t = new FailoverTransport([$t1, $t2]);
|
||||
$p = new \ReflectionProperty(RoundRobinTransport::class, 'cursor');
|
||||
$p->setAccessible(true);
|
||||
$p->setValue($t, 0);
|
||||
$t->send(new RawMessage(''));
|
||||
$this->assertTransports($t, 0, [$t1]);
|
||||
$t->send(new RawMessage(''));
|
||||
@ -99,9 +93,6 @@ class FailoverTransportTest extends TestCase
|
||||
$t2->expects($this->at(2))->method('send');
|
||||
$t2->expects($this->at(3))->method('send')->will($this->throwException(new TransportException()));
|
||||
$t = new FailoverTransport([$t1, $t2], 6);
|
||||
$p = new \ReflectionProperty(RoundRobinTransport::class, 'cursor');
|
||||
$p->setAccessible(true);
|
||||
$p->setValue($t, 0);
|
||||
$t->send(new RawMessage('')); // t1>fail - t2>sent
|
||||
$this->assertTransports($t, 0, [$t1]);
|
||||
sleep(4);
|
||||
@ -148,9 +139,6 @@ class FailoverTransportTest extends TestCase
|
||||
$t2->expects($this->at(1))->method('send');
|
||||
$t2->expects($this->at(2))->method('send')->will($this->throwException(new TransportException()));
|
||||
$t = new FailoverTransport([$t1, $t2], 1);
|
||||
$p = new \ReflectionProperty(RoundRobinTransport::class, 'cursor');
|
||||
$p->setAccessible(true);
|
||||
$p->setValue($t, 0);
|
||||
$t->send(new RawMessage(''));
|
||||
sleep(1);
|
||||
$t->send(new RawMessage(''));
|
||||
|
@ -29,6 +29,11 @@ class FailoverTransport extends RoundRobinTransport
|
||||
return $this->currentTransport;
|
||||
}
|
||||
|
||||
protected function getInitialCursor(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function getNameSymbol(): string
|
||||
{
|
||||
return 'failover';
|
||||
|
@ -67,9 +67,7 @@ class RoundRobinTransport implements TransportInterface
|
||||
protected function getNextTransport(): ?TransportInterface
|
||||
{
|
||||
if (-1 === $this->cursor) {
|
||||
// the cursor initial value is randomized so that
|
||||
// when are not in a daemon, we are still rotating the transports
|
||||
$this->cursor = mt_rand(0, \count($this->transports) - 1);
|
||||
$this->cursor = $this->getInitialCursor();
|
||||
}
|
||||
|
||||
$cursor = $this->cursor;
|
||||
@ -101,6 +99,13 @@ class RoundRobinTransport implements TransportInterface
|
||||
return $this->deadTransports->contains($transport);
|
||||
}
|
||||
|
||||
protected function getInitialCursor(): int
|
||||
{
|
||||
// the cursor initial value is randomized so that
|
||||
// when are not in a daemon, we are still rotating the transports
|
||||
return mt_rand(0, \count($this->transports) - 1);
|
||||
}
|
||||
|
||||
protected function getNameSymbol(): string
|
||||
{
|
||||
return 'roundrobin';
|
||||
|
Reference in New Issue
Block a user