Yaffs site version 1.1
[yaffs-website] / vendor / drush / drush / tests / backendUnitTest.php
1 <?php
2
3 namespace Unish;
4
5 class backendUnitCase extends UnitUnishTestCase {
6
7   /**
8    * Covers the following target responsibilities.
9    *   - Insures that drush_invoke_process() called with fork backend set is able
10    *     to invoke a non-blocking process.
11    */
12   function testBackendFork() {
13     if (self::is_windows()) {
14       $this->markTestSkipped('Fork tests not a priority on Windows.');
15     }
16
17     // Ensure that file that will be created by forked process does not exist
18     // before invocation.
19     $test_file = UNISH_SANDBOX . '/fork_test.txt';
20     if (file_exists($test_file)) {
21       unlink($test_file);
22     }
23
24     // Sleep for a millisecond, then create the file
25     $ev_php = "usleep(1000);fopen('$test_file','a');";
26     drush_invoke_process("@none", "ev", array($ev_php), array(), array("fork" => TRUE));
27
28     // Test file does not exist immediate after process forked
29     $this->assertEquals(file_exists($test_file), FALSE);
30     // Check every 100th of a second for up to 4 seconds to see if the file appeared
31     $repetitions = 400;
32     while (!file_exists($test_file) && ($repetitions > 0)) {
33       usleep(10000);
34     }
35     // Assert that the file did finally appear
36     $this->assertEquals(file_exists($test_file), TRUE);
37   }
38 }