3 final class PhabricatorMailConfigTestCase
4 extends PhabricatorTestCase
{
6 public function testMailerPriorities() {
7 $mailers = $this->newMailersWithConfig(
21 mpull($mailers, 'getKey'));
23 $mailers = $this->newMailersWithConfig(
39 mpull($mailers, 'getKey'));
41 $mailers = $this->newMailersWithConfig(
68 // The "A" servers should be shuffled randomly, so either outcome is
70 $option_1 = array('C', 'A1', 'A2', 'B', 'D');
71 $option_2 = array('C', 'A2', 'A1', 'B', 'D');
72 $actual = mpull($mailers, 'getKey');
74 $this->assertTrue(($actual === $option_1) ||
($actual === $option_2));
76 // Make sure that when we're load balancing we actually send traffic to
77 // both servers reasonably often.
82 $mailers = $this->newMailersWithConfig(
96 $first_key = head($mailers)->getKey();
98 if ($first_key == 'A1') {
102 if ($first_key == 'A2') {
106 if ($saw_a1 && $saw_a2) {
110 if ($attempts++
> 1024) {
113 'Load balancing between two mail servers did not select both '.
114 'servers after an absurd number of attempts.'));
118 $this->assertTrue($saw_a1 && $saw_a2);
121 public function testMailerConstraints() {
145 $mailers = $this->newMailersWithConfig(
148 $this->assertEqual(4, count($mailers));
150 $mailers = $this->newMailersWithConfig(
155 $this->assertEqual(2, count($mailers));
157 $mailers = $this->newMailersWithConfig(
162 $this->assertEqual(2, count($mailers));
164 $mailers = $this->newMailersWithConfig(
170 $this->assertEqual(1, count($mailers));
172 $mailers = $this->newMailersWithConfig(
175 'types' => array('test'),
177 $this->assertEqual(4, count($mailers));
179 $mailers = $this->newMailersWithConfig(
182 'types' => array('duck'),
184 $this->assertEqual(0, count($mailers));
187 private function newMailersWithConfig(
189 array $constraints = array()) {
191 $env = PhabricatorEnv
::beginScopedEnv();
192 $env->overrideEnvConfig('cluster.mailers', $config);
194 $mailers = PhabricatorMetaMTAMail
::newMailers($constraints);