Skip to content

Commit 5990498

Browse files
committed
ACP2E-2345: MySQL has gone away error if consumer max_messages = 0
1 parent 572433b commit 5990498

File tree

1 file changed

+77
-0
lines changed
  • lib/internal/Magento/Framework/DB/Test/Unit/Adapter/Pdo

1 file changed

+77
-0
lines changed

lib/internal/Magento/Framework/DB/Test/Unit/Adapter/Pdo/MysqlTest.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,4 +866,81 @@ private function invokeModelMethod(MockObject $adapter, string $method, array $p
866866

867867
return $method->invokeArgs($adapter, $parameters);
868868
}
869+
870+
/**
871+
* @dataProvider retryExceptionDataProvider
872+
* @param \Exception $exception
873+
* @return void
874+
*/
875+
public function testBeginTransactionWithReconnect(\Exception $exception): void
876+
{
877+
$adapter = $this->getMysqlPdoAdapterMock(['_connect', '_beginTransaction', '_rollBack']);
878+
$adapter->expects(self::exactly(4))
879+
->method('_connect');
880+
$adapter->expects(self::once())
881+
->method('_rollBack');
882+
883+
$matcher = self::exactly(2);
884+
$adapter->expects($matcher)
885+
->method('_beginTransaction')
886+
->willReturnCallback(
887+
function () use ($matcher, $exception) {
888+
if ($matcher->getInvocationCount() === 1) {
889+
throw $exception;
890+
}
891+
}
892+
);
893+
$adapter->beginTransaction();
894+
$adapter->rollBack();
895+
}
896+
897+
/**
898+
* @return array[]
899+
*/
900+
public function retryExceptionDataProvider(): array
901+
{
902+
$serverHasGoneAwayException = new \PDOException();
903+
$serverHasGoneAwayException->errorInfo = [1 => 2006];
904+
$lostConnectionException = new \PDOException();
905+
$lostConnectionException->errorInfo = [1 => 2013];
906+
907+
return [
908+
[$serverHasGoneAwayException],
909+
[$lostConnectionException],
910+
[new \Zend_Db_Statement_Exception('', 0, $serverHasGoneAwayException)],
911+
[new \Zend_Db_Statement_Exception('', 0, $lostConnectionException)],
912+
];
913+
}
914+
915+
/**
916+
* @dataProvider exceptionDataProvider
917+
* @param \Exception $exception
918+
* @return void
919+
*/
920+
public function testBeginTransactionWithoutReconnect(\Exception $exception): void
921+
{
922+
$this->expectException(\Exception::class);
923+
$adapter = $this->getMysqlPdoAdapterMock(['_connect', '_beginTransaction', '_rollBack']);
924+
$adapter->expects(self::once())
925+
->method('_connect');
926+
$adapter->expects(self::once())
927+
->method('_beginTransaction')
928+
->willThrowException($exception);
929+
$adapter->beginTransaction();
930+
}
931+
932+
/**
933+
* @return array[]
934+
*/
935+
public function exceptionDataProvider(): array
936+
{
937+
$pdoException = new \PDOException();
938+
$pdoException->errorInfo = [1 => 1213];
939+
940+
return [
941+
[$pdoException],
942+
[new \Zend_Db_Statement_Exception('', 0, $pdoException)],
943+
[new \Exception()],
944+
];
945+
}
869946
}

0 commit comments

Comments
 (0)