function backendUnitCase::testBackendFork

8.0.x backendUnitTest.php backendUnitCase::testBackendFork()
6.x backendTest.php backendUnitCase::testBackendFork()
7.x backendUnitTest.php backendUnitCase::testBackendFork()
5.x backendTest.php backendUnitCase::testBackendFork()
master backendUnitTest.php backendUnitCase::testBackendFork()

Covers the following target responsibilities.

  • Insures that drush_invoke_process() called with fork backend set is able to invoke a non-blocking process.


tests/backendTest.php, line 267
We choose to test the backend system in two parts. - Origin. These tests assure that we are generate a proper ssh command when a backend invoke is needed. - Target. These tests assure that drush generates a delimited JSON array …




function testBackendFork() {
  // Ensure that file that will be created by forked process does not exist
  // before invocation.
  $test_file = UNISH_SANDBOX . '/fork_test.txt';
  if (file_exists($test_file)) {

  // Sleep for a millisecond, then create the file
  $ev_php = "usleep(1000);fopen('$test_file','a');";
  drush_invoke_process("@none", "ev", array($ev_php), array(), array("fork" => TRUE));

  // Test file does not exist immediate after process forked
  $this->assertEquals(file_exists($test_file), FALSE);
  // Check every 100th of a second for up to 4 seconds to see if the file appeared
  $repetitions = 400;
  while (!file_exists($test_file) && ($repetitions > 0)) {
  // Assert that the file did finally appear
  $this->assertEquals(file_exists($test_file), TRUE);