1<?php
2
3final class PhutilProcessRefTestCase
4  extends PhutilTestCase {
5
6  public function testIdentifyOverseerProcess() {
7
8    // Test if various process argument vectors are correctly identified as
9    // daemon overseer processes or not. We're hoping to identify legitimate
10    // daemons and ignore false positives for processes with titles that look
11    // similar but are not really daemons, like "grep phd-daemon".
12
13    $tests = array(
14      array(
15        array('php', 'phd-daemon'),
16        true,
17      ),
18      array(
19        array('/path/to/php', '/path/to/phd-daemon'),
20        true,
21      ),
22      array(
23        array('/path/to/phd-daemon'),
24        true,
25      ),
26      array(
27        array('phd-daemon'),
28        true,
29      ),
30      array(
31        array('php', 'phd-daemon', '-l', 'instance-label'),
32        true,
33      ),
34      array(
35        array('grep phd-daemon'),
36        false,
37      ),
38      array(
39        array('this-is-a-phd-daemon'),
40        false,
41      ),
42    );
43
44    foreach ($tests as $case) {
45      list($argv, $expect) = $case;
46
47      $ref = id(new PhutilProcessRef())
48        ->setArgv($argv);
49
50      $actual = $ref->getIsOverseer();
51
52      $this->assertEqual(
53        $expect,
54        $actual,
55        pht('argv: %s', implode(' ', $argv)));
56    }
57  }
58
59}
60