Changeset View
Changeset View
Standalone View
Standalone View
src/filesystem/__tests__/PhutilFileLockTestCase.php
| Show First 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | final class PhutilFileLockTestCase extends PhutilTestCase { | ||||
| } | } | ||||
| private function lockTest($file) { | private function lockTest($file) { | ||||
| list($err) = $this->buildLockFuture('--test', $file)->resolve(); | list($err) = $this->buildLockFuture('--test', $file)->resolve(); | ||||
| return ($err == 0); | return ($err == 0); | ||||
| } | } | ||||
| private function holdLock($file) { | private function holdLock($file) { | ||||
| if (phutil_is_windows()) { | |||||
| // Skip since stdout is not reliable on Windows + PHP. | |||||
| $this->assertSkipped(pht("This test doesn't work on Windows.")); | |||||
| return; | |||||
| } | |||||
| $future = $this->buildLockFuture('--hold', $file); | $future = $this->buildLockFuture('--hold', $file); | ||||
| // We can't return until we're sure the subprocess has had time to acquire | // We can't return until we're sure the subprocess has had time to acquire | ||||
| // the lock. Since actually testing for the lock would be kind of silly | // the lock. Since actually testing for the lock would be kind of silly | ||||
| // and guarantee that we loop forever if the locking primitive broke, | // and guarantee that we loop forever if the locking primitive broke, | ||||
| // watch stdout for a *claim* that it has acquired the lock instead. | // watch stdout for a *claim* that it has acquired the lock instead. | ||||
| // Make sure we don't loop forever, no matter how bad things get. | // Make sure we don't loop forever, no matter how bad things get. | ||||
| Show All 10 Lines | private function holdLock($file) { | ||||
| throw new Exception(pht('Unable to hold lock in external process!')); | throw new Exception(pht('Unable to hold lock in external process!')); | ||||
| } | } | ||||
| private function buildLockFuture($flags, $file) { | private function buildLockFuture($flags, $file) { | ||||
| $root = dirname(phutil_get_library_root('phutil')); | $root = dirname(phutil_get_library_root('phutil')); | ||||
| $bin = $root.'/scripts/utils/lock.php'; | $bin = $root.'/scripts/utils/lock.php'; | ||||
| // NOTE: Use `exec` so this passes on Ubuntu, where the default `dash` shell | if (phutil_is_windows()) { | ||||
| // will eat any kills we send during the tests. | $future = new ExecFuture('php %s %C %s', $bin, $flags, $file); | ||||
| } else { | |||||
| // NOTE: Use `exec` so this passes on Ubuntu, | |||||
| // where the default `dash` shell will eat any | |||||
| // kills we send during the tests. | |||||
| $future = new ExecFuture('exec php %s %C %s', $bin, $flags, $file); | $future = new ExecFuture('exec php %s %C %s', $bin, $flags, $file); | ||||
| } | |||||
| $future->start(); | $future->start(); | ||||
| return $future; | return $future; | ||||
| } | } | ||||
| } | } | ||||