@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add unit tests for mail failover behaviors when multiple mailers are configured

Summary: Depends on D19006. Ref T13053. Ref T12677. When multiple mailers are configured but one or more fail, test that we recover (or don't) appropriately.

Test Plan: Ran unit tests.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13053, T12677

Differential Revision: https://secure.phabricator.com/D19007

+88 -6
+10 -6
src/applications/metamta/storage/PhabricatorMetaMTAMail.php
··· 315 315 return $this->getParam('stampMetadata', array()); 316 316 } 317 317 318 + public function getMailerKey() { 319 + return $this->getParam('mailer.key'); 320 + } 321 + 318 322 public function setHTMLBody($html) { 319 323 $this->setParam('html-body', $html); 320 324 return $this; ··· 586 590 } catch (Exception $ex) { 587 591 $exceptions[] = $ex; 588 592 continue; 593 + } 594 + 595 + // Keep track of which mailer actually ended up accepting the message. 596 + $mailer_key = $mailer->getKey(); 597 + if ($mailer_key !== null) { 598 + $this->setParam('mailer.key', $mailer_key); 589 599 } 590 600 591 601 return $this ··· 917 927 $mailer->addTos($add_to); 918 928 if ($add_cc) { 919 929 $mailer->addCCs($add_cc); 920 - } 921 - 922 - // Keep track of which mailer actually ended up accepting the message. 923 - $mailer_key = $mailer->getKey(); 924 - if ($mailer_key !== null) { 925 - $this->setParam('mailer.key', $mailer_key); 926 930 } 927 931 928 932 return $mailer;
+78
src/applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php
··· 253 253 ->executeOne(); 254 254 } 255 255 256 + public function testMailerFailover() { 257 + $user = $this->generateNewTestUser(); 258 + $phid = $user->getPHID(); 259 + 260 + $status_sent = PhabricatorMailOutboundStatus::STATUS_SENT; 261 + $status_queue = PhabricatorMailOutboundStatus::STATUS_QUEUE; 262 + $status_fail = PhabricatorMailOutboundStatus::STATUS_FAIL; 263 + 264 + $mailer1 = id(new PhabricatorMailImplementationTestAdapter()) 265 + ->setKey('mailer1'); 266 + 267 + $mailer2 = id(new PhabricatorMailImplementationTestAdapter()) 268 + ->setKey('mailer2'); 269 + 270 + $mailers = array( 271 + $mailer1, 272 + $mailer2, 273 + ); 274 + 275 + // Send mail with both mailers active. The first mailer should be used. 276 + $mail = id(new PhabricatorMetaMTAMail()) 277 + ->addTos(array($phid)) 278 + ->sendWithMailers($mailers); 279 + $this->assertEqual($status_sent, $mail->getStatus()); 280 + $this->assertEqual('mailer1', $mail->getMailerKey()); 281 + 282 + 283 + // If the first mailer fails, the mail should be sent with the second 284 + // mailer. Since we transmitted the mail, this doesn't raise an exception. 285 + $mailer1->setFailTemporarily(true); 286 + 287 + $mail = id(new PhabricatorMetaMTAMail()) 288 + ->addTos(array($phid)) 289 + ->sendWithMailers($mailers); 290 + $this->assertEqual($status_sent, $mail->getStatus()); 291 + $this->assertEqual('mailer2', $mail->getMailerKey()); 292 + 293 + 294 + // If both mailers fail, the mail should remain in queue. 295 + $mailer2->setFailTemporarily(true); 296 + 297 + $mail = id(new PhabricatorMetaMTAMail()) 298 + ->addTos(array($phid)); 299 + 300 + $caught = null; 301 + try { 302 + $mail->sendWithMailers($mailers); 303 + } catch (Exception $ex) { 304 + $caught = $ex; 305 + } 306 + 307 + $this->assertTrue($caught instanceof Exception); 308 + $this->assertEqual($status_queue, $mail->getStatus()); 309 + $this->assertEqual(null, $mail->getMailerKey()); 310 + 311 + $mailer1->setFailTemporarily(false); 312 + $mailer2->setFailTemporarily(false); 313 + 314 + 315 + // If the first mailer fails permanently, the mail should fail even though 316 + // the second mailer isn't configured to fail. 317 + $mailer1->setFailPermanently(true); 318 + 319 + $mail = id(new PhabricatorMetaMTAMail()) 320 + ->addTos(array($phid)); 321 + 322 + $caught = null; 323 + try { 324 + $mail->sendWithMailers($mailers); 325 + } catch (Exception $ex) { 326 + $caught = $ex; 327 + } 328 + 329 + $this->assertTrue($caught instanceof Exception); 330 + $this->assertEqual($status_fail, $mail->getStatus()); 331 + $this->assertEqual(null, $mail->getMailerKey()); 332 + } 333 + 256 334 }