@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 some test coverage for mailers configuration

Summary: Depends on D19005. Ref T12677. Ref T13053. Tests that turning `cluster.mailers` into an actual list of mailers more or less works as expected.

Test Plan: Ran unit tests.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13053, T12677

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

+136 -1
+2
src/__phutil_library_map__.php
··· 3178 3178 'PhabricatorMacroTransactionQuery' => 'applications/macro/query/PhabricatorMacroTransactionQuery.php', 3179 3179 'PhabricatorMacroTransactionType' => 'applications/macro/xaction/PhabricatorMacroTransactionType.php', 3180 3180 'PhabricatorMacroViewController' => 'applications/macro/controller/PhabricatorMacroViewController.php', 3181 + 'PhabricatorMailConfigTestCase' => 'applications/metamta/storage/__tests__/PhabricatorMailConfigTestCase.php', 3181 3182 'PhabricatorMailEmailHeraldField' => 'applications/metamta/herald/PhabricatorMailEmailHeraldField.php', 3182 3183 'PhabricatorMailEmailHeraldFieldGroup' => 'applications/metamta/herald/PhabricatorMailEmailHeraldFieldGroup.php', 3183 3184 'PhabricatorMailEmailSubjectHeraldField' => 'applications/metamta/herald/PhabricatorMailEmailSubjectHeraldField.php', ··· 8680 8681 'PhabricatorMacroTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 8681 8682 'PhabricatorMacroTransactionType' => 'PhabricatorModularTransactionType', 8682 8683 'PhabricatorMacroViewController' => 'PhabricatorMacroController', 8684 + 'PhabricatorMailConfigTestCase' => 'PhabricatorTestCase', 8683 8685 'PhabricatorMailEmailHeraldField' => 'HeraldField', 8684 8686 'PhabricatorMailEmailHeraldFieldGroup' => 'HeraldFieldGroup', 8685 8687 'PhabricatorMailEmailSubjectHeraldField' => 'PhabricatorMailEmailHeraldField',
+3 -1
src/applications/metamta/storage/PhabricatorMetaMTAMail.php
··· 513 513 $defaults = $mailer->newDefaultOptions(); 514 514 $options = idx($spec, 'options', array()) + $defaults; 515 515 $mailer->setOptions($options); 516 + 517 + $mailers[] = $mailer; 516 518 } 517 519 } 518 520 519 521 $sorted = array(); 520 522 $groups = mgroup($mailers, 'getPriority'); 521 - ksort($groups); 523 + krsort($groups); 522 524 foreach ($groups as $group) { 523 525 // Reorder services within the same priority group randomly. 524 526 shuffle($group);
+131
src/applications/metamta/storage/__tests__/PhabricatorMailConfigTestCase.php
··· 1 + <?php 2 + 3 + final class PhabricatorMailConfigTestCase 4 + extends PhabricatorTestCase { 5 + 6 + public function testMailerPriorities() { 7 + $mailers = $this->newMailersWithConfig( 8 + array( 9 + array( 10 + 'key' => 'A', 11 + 'type' => 'test', 12 + ), 13 + array( 14 + 'key' => 'B', 15 + 'type' => 'test', 16 + ), 17 + )); 18 + 19 + $this->assertEqual( 20 + array('A', 'B'), 21 + mpull($mailers, 'getKey')); 22 + 23 + $mailers = $this->newMailersWithConfig( 24 + array( 25 + array( 26 + 'key' => 'A', 27 + 'priority' => 1, 28 + 'type' => 'test', 29 + ), 30 + array( 31 + 'key' => 'B', 32 + 'priority' => 2, 33 + 'type' => 'test', 34 + ), 35 + )); 36 + 37 + $this->assertEqual( 38 + array('B', 'A'), 39 + mpull($mailers, 'getKey')); 40 + 41 + $mailers = $this->newMailersWithConfig( 42 + array( 43 + array( 44 + 'key' => 'A1', 45 + 'priority' => 300, 46 + 'type' => 'test', 47 + ), 48 + array( 49 + 'key' => 'A2', 50 + 'priority' => 300, 51 + 'type' => 'test', 52 + ), 53 + array( 54 + 'key' => 'B', 55 + 'type' => 'test', 56 + ), 57 + array( 58 + 'key' => 'C', 59 + 'priority' => 400, 60 + 'type' => 'test', 61 + ), 62 + array( 63 + 'key' => 'D', 64 + 'type' => 'test', 65 + ), 66 + )); 67 + 68 + // The "A" servers should be shuffled randomly, so either outcome is 69 + // acceptable. 70 + $option_1 = array('C', 'A1', 'A2', 'B', 'D'); 71 + $option_2 = array('C', 'A2', 'A1', 'B', 'D'); 72 + $actual = mpull($mailers, 'getKey'); 73 + 74 + $this->assertTrue(($actual === $option_1) || ($actual === $option_2)); 75 + 76 + // Make sure that when we're load balancing we actually send traffic to 77 + // both servers reasonably often. 78 + $saw_a1 = false; 79 + $saw_a2 = false; 80 + $attempts = 0; 81 + while (true) { 82 + $mailers = $this->newMailersWithConfig( 83 + array( 84 + array( 85 + 'key' => 'A1', 86 + 'priority' => 300, 87 + 'type' => 'test', 88 + ), 89 + array( 90 + 'key' => 'A2', 91 + 'priority' => 300, 92 + 'type' => 'test', 93 + ), 94 + )); 95 + 96 + $first_key = head($mailers)->getKey(); 97 + 98 + if ($first_key == 'A1') { 99 + $saw_a1 = true; 100 + } 101 + 102 + if ($first_key == 'A2') { 103 + $saw_a2 = true; 104 + } 105 + 106 + if ($saw_a1 && $saw_a2) { 107 + break; 108 + } 109 + 110 + if ($attempts++ > 1024) { 111 + throw new Exception( 112 + pht( 113 + 'Load balancing between two mail servers did not select both '. 114 + 'servers after an absurd number of attempts.')); 115 + } 116 + } 117 + 118 + $this->assertTrue($saw_a1 && $saw_a2); 119 + } 120 + 121 + private function newMailersWithConfig(array $config) { 122 + $env = PhabricatorEnv::beginScopedEnv(); 123 + $env->overrideEnvConfig('cluster.mailers', $config); 124 + 125 + $mailers = PhabricatorMetaMTAMail::newMailers(); 126 + 127 + unset($env); 128 + return $mailers; 129 + } 130 + 131 + }